-3
使用enum爲以下值創建一個程序。 3個對象 名稱: 年齡: 狀態: *如果你是單身,你的程序應該打印隨機的理由是單: 1.白白 2.採取了等待授予 3.挑剔有人可以指導我製作我的手錶。它關於枚舉。
使用enum爲以下值創建一個程序。 3個對象 名稱: 年齡: 狀態: *如果你是單身,你的程序應該打印隨機的理由是單: 1.白白 2.採取了等待授予 3.挑剔有人可以指導我製作我的手錶。它關於枚舉。
as far as I understand, the only candidate for enum is the status.
public enum Status{
SINGLE,MARRIED,WIDOW ...
}
public class Person{
String[] reasons = {"Waiting in vain","Taken for granted","Choosy"};
Status status;
int age;
String name;
Random random = new Random();
public Person(Status status, int age, String name) {
this.status = status;
this.age = age;
this.name = name;
}
public printRandomValue() {
if (status == Status.SINGLE) {
int index = random.nextInt(reasons.length);
System.out.println(reasons[index]);
}
}
}
在這裏做其他人的作業不是一個好主意。 (不,我沒有投票,只是一個提示) –
到目前爲止您嘗試了什麼? – cello