现在我已经阅读了此内容,但我只是卡住了。任何帮助表示赞赏。我正在寻找提示。代码编译并运行良好,但我认为变量没有存储在员工类中,并且我不确定我是否正确理解了构造函数的使用。
要求: 我已完成:
Values are checked to ensure they are positive numbers.
Entering stop as the employee name end program.
遇到问题
Uses a class to store
- name
- hourly rate
- hours worked
Use a constructor to initialize the employee information and a method within that class to calculate the weekly pay.
最佳答案
这里有一些提示:
Use a constructor to initialize the employee information
查看提供的代码,有一个构造函数不带参数,并将对象的字段初始化为零。
也许“初始化员工信息的构造函数”意味着构造函数应该能够接受Employee
对象将其字段初始化为的值。
The Java Tutorials有一个页面 Providing Constructors for Your Classes示例应该有助于创建这样的构造函数。
... and a method within that class to calculate the weekly pay
这似乎是说,应该有一个仅对其自身可见且其他人无法使用的方法来计算 weeklyPay
字段的值。
再次,来自 The Java Tutorials , Controlling Access to Members of a Class讨论显示更改方法的可见性。
看作业内容,好像是在看Lesson: Classes and Objects的The Java Tutorials可能有用,因为它提供了一些关于面向对象编程概念的很好的示例和解释。
关于Java帮助: Using Classes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1250324/