用Jav实现一个包含各个邻域职业的枚举类型
时间: 2023-05-22 14:03:47 浏览: 112
当然可以。以下是一个简单的实现示例:
```
public enum NeighborhoodJob {
ARCHITECT,
ENGINEER,
TEACHER,
DOCTOR,
LAWYER,
ARTIST
}
```
以上是一个包含邻域职业的枚举类型,其中包括建筑师、工程师、教师、医生、律师和艺术家。
相关问题
用Jav实现一个包含各个邻域职业及其编号属性(从1开始)的枚举类型(不少于50种职业),并提供静态方法供其他类调用
好的,我来回答你的问题。以下是 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 获取对应的职业实例。
希望对你有所帮助!
用Jav实现一个包含各个邻域职业及其编号属性(从1开始)和中文名属性(字符串类型)的枚举类型(不少于50种职业),并提供静态方法供其他类调用
当然可以!以下是实现该要求的代码:
```java
public enum Career {
PROGRAMMER(1, "程序员"),
DESIGNER(2, "设计师"),
PRODUCT_MANAGER(3, "产品经理"),
TEACHER(4, "教师"),
ENGINEER(5, "工程师"),
SALESPERSON(6, "销售人员"),
MARKETER(7, "市场人员"),
ACCOUNTANT(8, "会计"),
DOCTOR(9, "医生"),
NURSE(10, "护士"),
LAWYER(11, "律师"),
JOURNALIST(12, "记者"),
WRITER(13, "作家"),
ARCHITECT(14, "建筑师"),
MUSICIAN(15, "音乐家"),
ARTIST(16, "艺术家"),
ATHLETE(17, "运动员"),
ACTOR(18, "演员"),
CHEF(19, "厨师"),
BARISTA(20, "咖啡师"),
BANKER(21, "银行家"),
CONSULTANT(22, "顾问"),
INVESTOR(23, "投资人"),
PHARMACIST(24, "药剂师"),
PSYCHOLOGIST(25, "心理学家"),
SCIENTIST(26, "科学家"),
RESEARCHER(27, "研究员"),
POLITICIAN(28, "政治家"),
CIVIL_SERVANT(29, "公务员"),
MILITARY(30, "军人"),
POLICE(31, "警察"),
FIREFIGHTER(32, "消防员"),
PILOT(33, "飞行员"),
ENGINE_DRIVER(34, "司机"),
TRUCK_DRIVER(35, "卡车司机"),
TAXI_DRIVER(36, "出租车司机"),
DELIVERY(37, "快递员"),
COURIER(38, "邮递员"),
CLEANER(39, "清洁工"),
GARDENER(40, "园丁"),
JANITOR(41, "看门人"),
SALESMAN(42, "售货员"),
CASHIER(43, "收银员"),
WAREHOUSE(44, "仓库管理员"),
CONSTRUCTION_WORKER(45, "建筑工人"),
ELECTRICIAN(46, "电工"),
PLUMBER(47, "水暖工"),
MECHANIC(48, "机修工"),
HAIRDRESSER(49, "理发师"),
AUCTIONEER(50, "拍卖师");
private int id;
private String name;
Career(int id, String name) {
this.id = id;
this.name = name;
}
public static String getCareerNameById(int id) {
for (Career career : Career.values()) {
if (career.id == id) {
return career.name;
}
}
return null;
}
}
```
这个枚举类型中包含50种不同的职业,并且提供了一个静态方法,可以根据职业的编号获取其中文名。每个职业都有一个唯一的ID和一个中文名属性。
阅读全文