Java帮助: Using Classes

标签 java

现在我已经阅读了此内容,但我只是卡住了。任何帮助表示赞赏。我正在寻找提示。代码编译并运行良好,但我认为变量没有存储在员工类中,并且我不确定我是否正确理解了构造函数的使用。

要求: 我已完成:

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 ObjectsThe Java Tutorials可能有用,因为它提供了一些关于面向对象编程概念的很好的示例和解释。

关于Java帮助: Using Classes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1250324/

相关文章:

java - 有没有办法用 netbeans 中的记录器替换所有 system.out/err 和 e.printstacktraces?

Java Servlet header 隐式对象

java - 同步方法

java - 如何以编程方式限制 Eclipse (Message)Console 的缓冲区大小?

java - 为什么编译器更喜欢 char 的 int 重载而不是 varargs char 重载?

JavaFX - 如何将 ChangeListener 添加到与其他类中的 StringProperty 绑定(bind)的 TextArea

java - 计算句子数

java - 如何查看点击了哪个通知ID?

java - 为ELKI中的关系添加索引

java - 如何使用 Java 从 URL 链接获取 xsp 值