如何使用输入更改setter的值?Java

huangapple go评论58阅读模式
英文:

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;
}

huangapple
  • 本文由 发表于 2020年9月1日 22:32:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/63689778.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定