2015-08-09 14 views

回答

-1
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]); 
     } 
    } 
} 
+1

在這裏做其他人的作業不是一個好主意。 (不,我沒有投票,只是一個提示) –

相關問題