我在文本中找不到与设置字符相关的任何内容。我认为它应该是一个空白' '
有人可以给我一些建议吗?我在这里搜索过,谷歌。我的文字等等。我只是想在今晚 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/