java题目:关于setter和getter,帮忙做一下
发布网友
发布时间:2022-05-27 17:08
我来回答
共1个回答
热心网友
时间:2023-11-06 11:45
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;
}
}