public class Player
{
private String firstName;
private String lastName;
private int heightInInches;
private double weightInPounds;
private boolean goalScorer;
private boolean drinksBeer;
public Player(){
}
public Player(String firstName, String lastName, int heightInInches, double weightInPounds, boolean goalScorer, boolean drinksBeer){
if(lastName != null && lastName.trim().length() > 0){
if(lastName != null && lastName.trim().length() > 0){
if(heightInInches >= 0){
if(weightInPounds >= 0){
this.firstName = firstName;
this.lastName = lastName;
this.heightInInches = heightInInches;
this.weightInPounds = weightInPounds;
this.goalScorer = goalScorer;
this.drinksBeer = drinksBeer;
}
}
}
}
}
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public int getHeightInInches(){
return heightInInches;
}
public double getWeightInPounds(){
return weightInPounds;
}
public boolean getGoalScorer(){
return goalScorer;
}
public boolean getDrinksBeer(){
return drinksBeer;
}
public void setFirstName(String firstName){
if(firstName != null && firstName.trim().length() > 0){
this.firstName = firstName;
}else{
System.out.println("Error. Invalid First Name.");
}
}
public void setLastName(String lastName){
if(lastName != null && lastName.trim().length() > 0){
this.lastName = lastName;
}else{
System.out.println("Error. Invalid Last Name.");
}
}
在重载的构造函数中,如何不使用赋值语句为每个字段调用 mutator 方法?并且如果我调用 mutator 方法,我应该删除构造函数中的 if 语句吗?(我使用的是blueJ)我是初学者,所以请说明我的代码中是否还有其他问题。提前致谢。
吃鸡游戏
函数式编程
随时随地看视频慕课网APP
相关分类