java - JAVA 中的 this.set(charHere)

标签 java constructor char set

我在文本中找不到与设置字符相关的任何内容。我认为它应该是一个空白' '

有人可以给我一些建议吗?我在这里搜索过,谷歌。我的文字等等。我只是想在今晚 sleep 之前再多了解一下这个实验室。我知道这是一个非常初学者的问题,但我所有的在线研究都只是带回数组字符问题。

public class RateEstimator
{
    // instance variables
    private boolean smoker;
    private char gender;
    private int age;
    private boolean highRisk;
    private int numTickets;
    private String health;

    // constants

    /**
     * base rate for a 100K face value policy.
     */
    public static final double BASE_RATE = 45.0;

    /**
     *?????????????????ASK HOW TO CONSTRUCT BOOLEAN AND CHAR???????
     *First constructor for objects of class RateEstimator.
     */

    public RateEstimator()
    {
        // REPLACE these comments and return statement
        // with your coding of this constructor
        this.setSmoker(false);
        this.setGender(' ');
        this.setAge(0);
        this.setHighRisk(false);
        this.setNumTickets(0);
        this.setHealth("Good");

    }

最佳答案

据我所知,您遇到困难的编码作业部分是 RateEstimator 类的构造函数的实现。以下代码是我为该类编写的普通构造函数。

public RateEstimator(boolean smoker, char gender, int age, boolean highRisk,
    int numTickets, String health) {
    this.smoker = smoker;
    this.gender = gender;
    this.age = age;
    this.highRisk = highRisk;
    this.numTickets = numTickets;
    this.health = health;
}

进一步说明:

this 运算符引用正在构造的 RateEstimator 对象的实例。因此,this.age = Age 意味着将构造函数参数 age 分配给 RateEstimator 类实例中包含的变量。

关于java - JAVA 中的 this.set(charHere),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33515450/

相关文章:

java:创建目录

java - 基础 Controller SpringMVC

javascript - someFunction.Prototype.constructor 与 someFunction.constructor

c++ - 即使存在转换,也无法将子类模板转换为基类的另一个模板

c++ - 如何在 C++ 中将类的实例与 char * 变量进行比较?

java - 如何计算物体自由落体 10 秒后的位置

java - RxJava2 中可观察量和观察者的行为

c++ - 调用函数时首选错误的参数转换

c++ - 如何将整数字面显示为字符

c++ - 如何正确使用 intptr 将 char* 值从 C++ DLL 返回到 Vb.net