Instructions
Requirements and Specifications
Source Code
/*
ALGORITHM:
Begin
Declare finalist1, finalist2, finalist3 as Integer
finalist1 = Random number between 1 and 10
finalist2 = Random number between 1 and 10
While finalist2 Is finalist1
finalist2 = Random number between 1 and 10
End While
finalist3 = Random number between 1 and 10
While finalist3 Is finalist1 Or finalist3 Is finalist2
finalist3 = Random number between 1 and 10
End While
Write finalist1
Write finalist2
Write finalist3
End
*/
import java.util.Random;
public class Ch4PP8Prizes_YourName {
// Entry point of the program
public static void main(String[] args) {
Random random = new Random();
// Choose the first finalist
int finalist1 = random.nextInt(11) + 1;
// Choose the second finalist
int finalist2 = random.nextInt(11) + 1;
while (finalist2 == finalist1) {
finalist2 = random.nextInt(11) + 1;
}
// Choose the third finalist
int finalist3 = random.nextInt(11) + 1;
while(finalist3 == finalist1 || finalist3 == finalist2) {
finalist3 = random.nextInt(11) + 1;
}
System.out.println("Finalist 1: " + finalist1);
System.out.println("Finalist 2: " + finalist2);
System.out.println("Finalist 3: " + finalist3);
}
}