Question
import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); Random
import java.util.Random; import java.util.Scanner;
public class Main {
public static void main(String[] args) { // TODO Auto-generated method stub
Scanner sc = new Scanner(System.in); Random random = new Random(); // declaring all the variables in all the cases, collectively. int change, dollars, quarters, dimes, nickels, pennies, num1, num2, num3, r1, r2, r3; int points = 0; char option, lastInitial, firstInitial; String firstName, lastName; // printing the first initial statements. System.out.println("a) Exact Change"); System.out.println("b) Format Name"); System.out.println("c) Lucky Numbers"); System.out.println(" "); // option to select the favourable option. System.out.print("Select one of the above option: "); option = sc.next().charAt(0); // creating the switch. switch(option ) {
// ........................................................................................................................................................................................................... // case 1 with case-sensitive. case 'a': System.out.print(" Total change: "); change = sc.nextInt(); // initiallizing the value of dollars dollars = change / 100; change %= 100;
// initiallizing the value of quarters quarters = change / 25; change %= 25; // initiallizing the value of dimes dimes = change / 10; change %= 10; // initiallizing the value of nickels nickels = change / 5; change %= 5; // initiallizing the value of pennies (remaining all the values) pennies = change;
System.out.print(" "); // print statement of first case. if (dollars != 0) { System.out.printf("%-10s %-10d ", "Dollars:", dollars); } if (quarters != 0) { System.out.printf("%-10s %-10d ", "Quarters:", quarters); } if (dimes != 0) { System.out.printf("%-10s %-10d ", "Dimes:", dimes); } if ( nickels != 0) { System.out.printf("%-10s %-10d ", "Nickels:", nickels); } if ( pennies != 0) { System.out.printf("%-10s %-10d ", "Pennies:", pennies); } break; // ............................................................................................................................................................................................. case 'b': System.out.print(" First Name: "); firstName = sc.next(); System.out.print("Last Name: "); lastName = sc.next(); // // initiallizing the initials of first name and last name. lastInitial = lastName.charAt(0); firstInitial = firstName.charAt(0); // print statements as related to the question if the values are in the range. if ((lastInitial >= 'A' && lastInitial = 'T' && lastInitial
// ............................................................................................................................................................................................. // default statement, if any of the above case have not been followed. default: System.out.println(">>>>>>>"); break; // ............................................................................................................................................................................................. }
}
}
Can you please check this code for errors, also grammar errors.Please don't send a new high-level code this is for beginners class.
Heres what the question is and what the output should be.
PURPOSE This assignment will enhance your ability to utilize branches in a computer program. By the end of this assignment, you should feel comfortable working with if statements, switch statements, and random number generators. PROBLEM Write a program that allows the user to select an option from a menu. Depending on the option they select, a certain block of code should be executed. Use a switch statement to structure this menu. The menu options are listed below: a) Exact Change Prompt the user to enter an integer that represents the total amount of change. Then, find out the smallest combination of coins that will make up the total change. Coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. b) Format Name Prompt the user to enter their first and last name. If their last initial is in the range (a-g) or ( tz) inclusively, display their first name followed by their last initial. If their last initial is not in the range, display their last name followed by their first initial. c) Lucky Numbers Prompt the user to guess three integers. Then, generate three lucky numbers that are random integers in the range 0-5. For each lucky number that the user guesses correctly, they get a point. If no numbers are guessed correctly, they lose. If the user guesses the same number more than once, print an error message. ** If the user selects an invalid option, you should print an appropriate error message to the console. Sample Input/Output for option a a) Exact Change b) Format Name c) Lucky Numbers Select one of the above options: a Total change: 19 Dimes: 1 Nickels: 1 Pennies: 4 a) Exact Change b) Format Name c) Lucky Numbers Select one of the above options: a Total change: 120 Dollars: 1 Dimes: 2 a) Exact Change b) Format Name c) Lucky Numbers Select one of the above options: a Total change: 287 Dollars: 2 Quarters: 3 Dimes: 1 Pennies: 2 Sample Input/Output for option b a) Exact Change b) Format Name c) Lucky Numbers Select one of the above options: b First name: John Last name: Doe John D. a) Exact Change b) Format Name c) Lucky Numbers Select one of the above options: b First name: Jane Last name: Johnson Johnson J. Sample Input/Output for option c a) Exact Change b) Format Name c) Lucky Numbers Select one of the above options: c Guess three numbers (05) Num1: 0 Num2: 2 Num3: 5 The lucky numbers are 2,1,0 Congratulations! Total points: 2 a) Exact Change b) Format Name c) Lucky Numbers Select one of the above options: c Guess three numbers (05) Num1: 1 Num2: 2 Num3: 3 The lucky numbers are 1,4,1 Congratulations! Total points: 2 a) Exact Change b) Format Name c) Lucky Numbers Select one of the above options: c Guess three numbers (05) Num1: 1 Num2: 3 Num3: 4 The lucky numbers are 5,0,2 0oof. better luck next time. a) Exact Change b) Format Name c) Lucky Numbers Select one of the above options: c Guess three numbers (05) Num1: 1 Num2: 1 Num3: 2 ERR0R: You cannot enter duplicate numbersStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started