Question: i've written a java program that doles out a certain number of random compliments. for the most part, the code works as it should, except

i've written a java program that doles out a certain number of random compliments. for the most part, the code works as it should, except it doesn't entirely match the expected output. for example, when running the program, i enter the seed as '33' and ask for 6 compliments. instead of randomizing the compliments, it's giving me the same one 6 times in a row. i've included what the sample output should be and also my code.
SAMPLE OUTPUT
Welcome to the Random Complimenter program.
Enter a seed for the random number generator.
33
How many compliments would you like? ('0' to quit)
6
You are soooooo good looking.
You are soooooo good looking.
You're pretty awesome.
You're pretty awesome.
You ... are ... #1.
You ... are ... #1.
How many compliments would you like? ('0' to quit)
6
You ... are ... #1.
You're pretty awesome.
You're pretty awesome.
You're pretty awesome.
You're pretty awesome.
You are soooooo good looking.
How many compliments would you like? ('0' to quit)
6
You ... are ... #1.
You ... are ... #1.
You ... are ... #1.
You are soooooo good looking.
You are soooooo good looking.
You're pretty awesome.
How many compliments would you like? ('0' to quit)
0
Have a great day!
MY CODE
import java.util.Random;
import java.util.Scanner;
public class RandomCompliment_Part1{
public static void main(String[] args){
System.out.println("Welcome to the Random Complimenter program.
");
Scanner scanner = new Scanner(System.in);
int seed = getSeed(scanner);
scanner.nextLine();
int quantityOfCompliments;
do {
quantityOfCompliments = getQuantityOfCompliments(scanner);
if (quantityOfCompliments !=0){
outputCompliments(quantityOfCompliments, seed);
}
} while (quantityOfCompliments !=0);
scanner.close();
System.out.println("
Have a great day!");
}
// Method to prompt the user for a seed
public static int getSeed(Scanner scanner){
System.out.println("Enter a seed for the random number generator.");
return scanner.nextInt();
}
// Method to prompt the user for the quantity of compliments
public static int getQuantityOfCompliments(Scanner scanner){
System.out.println("How many compliments would you like? ('0' to quit)");
return scanner.nextInt();
}
// Method to generate a random compliment
public static String generateCompliment(int seed){
Random random = new Random(seed);
int complimentIndex = random.nextInt(3);
switch (complimentIndex){
case 0:
return "You are soooooo good looking.";
case 1:
return "You ... are ... #1.";
case 2:
return "You're pretty awesome.";
default:
return ""; // This case should never happen
}
}
// Method to output compliments
public static void outputCompliments(int quantity, int seed){
for (int i =0; i < quantity; i++){
String compliment = generateCompliment(seed);
System.out.println(compliment);
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!