用Jav实现一个包含各个邻域职业及其编号属性(从1开始)的枚举类型(不少于50种职业),并提供静态方法供其他类调用
时间: 2023-05-22 21:03:50 浏览: 140
好的,我来回答你的问题。以下是 Jav 实现一个包含各个邻域职业及其编号属性的枚举类型的代码:
```
public enum NeighborhoodJob {
DOCTOR(1),
NURSE(2),
TEACHER(3),
LAWYER(4),
ENGINEER(5),
CHEF(6),
WAITER(7),
ACCOUNTANT(8),
ARCHITECT(9),
ARTIST(10),
ATHLETE(11),
BANKER(12),
BARBER(13),
BARTENDER(14),
BUILDER(15),
BUS_DRIVER(16),
CARPENTER(17),
CASHIER(18),
COMPUTER_TECHNICIAN(19),
CONSTRUCTION_WORKER(20),
DANCER(21),
DENTIST(22),
DESIGNER(23),
DEVELOPER(24),
DIRECTOR(25),
DRIVER(26),
ELECTRICIAN(27),
FIRE_FIGHTER(28),
FITNESS_COACH(29),
FLIGHT_ATTENDANT(30),
HAIRDRESSER(31),
HOUSEKEEPER(32),
INSTRUCTOR(33),
JOURNALIST(34),
JUDGE(35),
LANDLORD(36),
LIBRARIAN(37),
MANAGER(38),
MUSICIAN(39),
NANNY(40),
OPTOMETRIST(41),
PAINTER(42),
PHARMACIST(43),
PHOTOGRAPHER(44),
PILOT(45),
PLUMBER(46),
POLICE_OFFICER(47),
PSYCHOLOGIST(48),
REAL_ESTATE_AGENT(49),
RECEPTIONIST(50);
private final int id;
NeighborhoodJob(int id) {
this.id = id;
}
public int getId() {
return id;
}
public static NeighborhoodJob getJobById(int id) {
for (NeighborhoodJob job : values()) {
if (job.id == id) {
return job;
}
}
return null;
}
}
```
其中枚举类型 NeighborhoodJob 包含了50种职业,每个职业都有一个唯一的 id。我们提供了一个静态方法 getJobById,可以根据职业的 id 获取对应的职业实例。
希望对你有所帮助!
阅读全文