op -java的居民
我在2天前就发现了Java的OOP,现在我有一个我无法独自重新熟食的问题。 我有4个公司为一家公司,在第一类中,我们在第二堂3级是:
“
public class Profession {
public enum Position {
Developer, Mechanic, Director
}
}"
那么我如何在第一堂课中使用这些枚举来设置工资? 我的意思是类似的东西
"if (position is Developer{
salary = 5000
}else if (position is Mechanic){
salary = 3000
}"
,当我回到主要的时候写下类似的东西: 囊泡。 (通过使用枚举来捷径进行捷径。
I found out the OOP in JAVA just 2 days ago, and now I have a problem that I can not reslove alone.
I have 4 classes for a company, in the 1st class we have the characteristics of an employee(name, salary, exepirience) in the 2nd I made a list and a method to add them in the class with the main using the method, the 3rd class is :
"
public class Profession {
public enum Position {
Developer, Mechanic, Director
}
}"
So how can I use those Enums in the first class to set the salary?
I mean something like
"if (position is Developer{
salary = 5000
}else if (position is Mechanic){
salary = 3000
}"
and when I go back in the main and write something like:
veselin. (to have the shortcut to setProfession by using the ENUMS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须有一个枚举实例,目前,您只有它的“蓝图”。创建您的位置字段(我将其重命名为位置类型)并使用它。另外,作为个人喜好,我不喜欢将我的枚举嵌入课堂上,因为您每次使用时都必须在类名称上前缀。
一个示例:
此输出:
You have to have an instance of your enum, currently you only have the "blueprint" of it. Create a field of your Position (I've renamed it PositionTypes) and use that. Also, as a personal preference, I don't like having my enums embedded in classes, since you'd have to prefix the class name every time you use it.
An example:
This outputs: