是关于setter和getter的作业,麻烦大佬帮忙看一下!

/**
* A Human demonstrates some attributes and methods of Humans.
*/
public class Human
{
// instance variables
private String name;
private int age;
private String phone;
private String gender;
private boolean sleep;

/**
* Constructors for objects of class Human
*/
public Human()
{
}

public Human(String genderIn)
{
gender = genderIn;
}

public Human(String genderIn, String nameIn)
{
public

gender = genderIn;
name = nameIn;
}

/**
* Methods for objects of class Human
*/
public void setAge(int ageIn){
age = ageIn;
}

public int getAge(){
return age;
}

public void birthday(){
age++;
}

public String getName() {
return name;
}

/**
* goToSleep()
*/
public void goToSleep()
{
sleep = true;
}

/**
* wakeUp()
*/
public void wakeUp()
{
sleep = false;
}

/**
* getSleepStatus()
* @return true if asleep else false
*/
public boolean getSleepStatus(){
return sleep;
}
}

给GPA加一些attribute, 一个为numberOfClassesMissed, 另一个自定,Add setters and getters for those attributes,可能不可以再麻烦加一下注释?谢谢!

慕侠2389804
浏览 284回答 1
1回答

慕的地8271018

public class Human{// instance variablesprivate String name;private int age;private String phone;private String gender;private boolean sleep;//////////////////////////////////////////////////////////////private int ppppp;private String numberOfClassesMissed;public String getNumberOfClassesMissed(){return numberOfClassesMissed;}public void setNumberOfClassesMissed(String numberOfClassesMissed){this.numberOfClassesMissed=numberOfClassesMissed;}public int getPpppp(){return ppppp;}public void setPpppp(int ppppp){this.ppppp=ppppp;}/////////////////////////////////////////////////////////////*** Constructors for objects of class Human*/public Human(){}public Human(String genderIn){gender = genderIn;}public Human(String genderIn, String nameIn){publicgender = genderIn;name = nameIn;}/*** Methods for objects of class Human*/public void setAge(int ageIn){age = ageIn;}public int getAge(){return age;}public void birthday(){age++;}public String getName() {return name;}/*** goToSleep()*/public void goToSleep(){sleep = true;}/*** wakeUp()*/public void wakeUp(){sleep = false;}/*** getSleepStatus()* @return true if asleep else false*/public boolean getSleepStatus(){return sleep;}}
打开App,查看更多内容
随时随地看视频慕课网APP