我收到的问题是:
定义具有下列规格的一流酒店:
私人成员:
Roomno
Name
Charges_day
No_of_days 公众成员:
Getit() -to enter the data members
Showit() to show the data member
Compute() -To calculate and return the total charges as charges_day * No_of_days以及初始化数据成员的构造函数。
我写的代码:
public class hotel{
private int Roomno;
private String Name;
private int Charges_day;
private int No_of_days;
public hotel(){
Roomno = 0;
Name = "";
Charges_day = 0;
No_of_days = 0;
}
public void Getit(int r, String n, int c, int no){
Roomno = r;
Name = n;
Charges_day = c;
No_of_days = no;
}
public String Showname(){
return Name;
}
public int Showit(){
return Roomno;
return Charges_day;
return No_of_days;
}
public int Compute(){
return (Charges_day*No_of_days);
}
}我知道在一个方法函数中不能有超过一个返回,但是我无法找到解决这个问题的方法。
发布于 2020-04-07 14:54:08
关于需求,我建议你直接打印这些值
public void Showit(){
System.out.println(Name+" "+Roomno+" "+Charges_day+" "+No_of_days);
}如果需要返回对象的String表示的方法,请重写toString()
public String toString(){
return Name + " " + Roomno + " " + Charges_day + " " + No_of_days;
}另外,Java命名约定是
用于方法和属性的
https://stackoverflow.com/questions/61082796
复制相似问题