英文:
How can I change the value of a setter with input? JAVA
问题
你好,我遇到的问题是,我无法使用整数(从扫描仪输入)更改此设置器的值,原因我不明白。我也在使用一个数组和一个主类。
当我以字符串作为输入时,这个确切的代码起作用。但是当我尝试使用整数(在这种情况下我必须这样做,因为我正在处理小时)时,它不起作用……有解决方法吗?或者有另一种编码方式吗?
英文:
Hi so the problem I have is I cant change the value of this setter using an integer (input from scanner) for some reason I dont understand. Im using an array aswell and a mainclass.
This exact coding worked when I used a string as the input. But when I try to do it with an int (which i have to in this case cause Im working with hours) it wont work... Is there a solution to this? or another way to code it.
答案1
得分: 0
你的员工类(employee class)用于设置员工工作小时数的 Getter 和 Setter 方法应该如下所示:
public void setEmployeeHours(int hour){
this.hours = hour;
}
public int getEmployeeHours(){
return hours;
}
英文:
Your Getter and Setter method of employee class for setting employee hours should look like this.
public void setEmployeeHours(int hour){
this.hours=hour;
}
public int getEmployeeHours(){
return hours;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论