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 and ask for compliments. instead of randomizing the compliments, it's giving me the same one 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.
How many compliments would you like? to quit
You are soooooo good looking.
You are soooooo good looking.
You're pretty awesome.
You're pretty awesome.
You are #
You are #
How many compliments would you like? to quit
You are #
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? to quit
You are #
You are #
You are #
You are soooooo good looking.
You are soooooo good looking.
You're pretty awesome.
How many compliments would you like? to quit
Have a great day!
MY CODE
import java.util.Random;
import java.util.Scanner;
public class RandomComplimentPart
public static void mainString args
System.out.printlnWelcome to the Random Complimenter program.
;
Scanner scanner new ScannerSystemin;
int seed getSeedscanner;
scanner.nextLine;
int quantityOfCompliments;
do
quantityOfCompliments getQuantityOfComplimentsscanner;
if quantityOfCompliments
outputComplimentsquantityOfCompliments seed;
while quantityOfCompliments ;
scanner.close;
System.out.println
Have a great day!";
Method to prompt the user for a seed
public static int getSeedScanner scanner
System.out.printlnEnter a seed for the random number generator.";
return scanner.nextInt;
Method to prompt the user for the quantity of compliments
public static int getQuantityOfComplimentsScanner scanner
System.out.printlnHow many compliments would you like? to quit;
return scanner.nextInt;
Method to generate a random compliment
public static String generateComplimentint seed
Random random new Randomseed;
int complimentIndex random.nextInt;
switch complimentIndex
case :
return "You are soooooo good looking.";
case :
return "You are #;
case :
return "You're pretty awesome.";
default:
return ; This case should never happen
Method to output compliments
public static void outputComplimentsint quantity, int seed
for int i ; i quantity; i
String compliment generateComplimentseed;
System.out.printlncompliment;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
