为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕侠2389804 2021-10-27 23:19:16
/*** A Human demonstrates some attributes and methods of Humans.*/public class Human{// instance variablesprivate 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){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;}}给GPA加一些attribute, 一个为numberOfClassesMissed, 另一个自定,Add setters and getters for those attributes,可能不可以再麻烦加一下注释?谢谢!
查看完整描述

1 回答

?
慕的地8271018

TA贡献1796条经验 获得超4个赞

public class Human
{
// instance variables
private 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)
{
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;
}
}



查看完整回答
反对 回复 2021-10-31
  • 1 回答
  • 0 关注
  • 282 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信