类和对象的基础知识:Java

时间:2020-04-07 14:48:26

标签: java class object public

我收到的问题:

定义具有以下规格的一流酒店:

私人成员:

for( i in 1:nrow(data1)){
  result <- ""
  for(j in 1: nrow(data2)){
     present <- grepl(eval(parse(text = paste0('\\<',data2$names_search[j],'\\>'))), data1$names[i], fixed = T)
     # I check if the whole word data[j] is present in data1[i]

     if(present ==T){
       result <- paste(result, data2$names_search[j], sep= "|")

     }


  }
  data1$names_search[i] <- result

}

公众成员:

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

我知道在一个方法函数中返回不能超过1,但是我无法找到解决此问题的方法。

1 个答案:

答案 0 :(得分:0)

关于要求,我建议您只打印值

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的命名约定也是

  • lowerCamelCase方法和属性
相关问题