I want to produce a string that is a single letter (A, B or C), followed by two random numbers. I have written the following code:
enum typeOfPerson {CHILD, ELDER, BOOMER};
public String setNumber(Report.ReportType type) {
Random rand = new Random();
String number = String.valueOf(rand.nextInt(10)) + String.valueOf((rand.nextInt(10)));
switch (type) {
case CHILD:
String prefix = "A";
break;
case ELDER:
prefix = "B";
break;
case BOOMER:
prefix = "C";
break;
accountNumber = prefix + number;
}
return accountNumber;
}
When I run the code I just get the two random numbers, without the prefix. I am unclear where the error is, but I am guessing I did something wrong with the switch statement.
Aucun commentaire:
Enregistrer un commentaire