Question: i did a java lab for random compliments and the feedback i got was in the main method i called two input methods when i
i did a java lab for random compliments and the feedback i got was in the main method i called two input methods when i was only allowed to call one, and then it was cited again later in the code that i could only write one input method and wrote two. i have included my code below. could someone explain how to only have one input method? the methods in question are getSeed and getQuantityOfCompliments
import java.util.Random;
import java.util.Scanner;
public class RandomComplimentPart
public static void mainString args
Displays welcome message
System.out.printlnWelcome to the Random Complimenter program.
;
Instantiate the scanner
Scanner scanner new ScannerSystemin;
Getting the seed for the random number generator
int seed getSeedscanner;
Instantiate the random object
Random random new Randomseed;
Consume newline
scanner.nextLine;
Variable to store the quantity of compliments
int quantityOfCompliments;
Loop to continuously ask for compliments until the user enters
do
Prompting the user for the quantity of compliments
quantityOfCompliments getQuantityOfComplimentsscanner;
If the user input is not generate and output compliments
if quantityOfCompliments
outputComplimentsquantityOfCompliments random;
while quantityOfCompliments ;
Close the scanner
scanner.close;
Displays farewell message
System.out.println
Have a great day!
;
Method to prompt the user for a seed
public static int getSeedScanner scanner
Asking the user to enter a seed for the random number generator
System.out.printlnEnter a seed for the random number generator.";
Returning the seed entered by the user
return scanner.nextInt;
Method to prompt the user for the quantity of compliments
public static int getQuantityOfComplimentsScanner scanner
Asking the user how many compliments they would like
System.out.println
How many compliments would you like? to quit;
Returning the quantity of compliments entered by the user
return scanner.nextInt;
Method to generate a random compliment
public static String generateComplimentRandom random
Generating a random integer between and to select a compliment
int complimentIndex random.nextInt;
Switching between different compliments based on the random
integer generated
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, Random random
Loop to generate and output the specified quantity of compliments
for int i ; i quantity; i
Generating a random compliment
String compliment generateComplimentrandom;
Printing the compliment
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
