Question
JAVA Add a new program to your Menu program, by writing in a new class a program that takes a sequence of numbers from the
JAVA
Add a new program to your Menu program, by writing in a new class a program that takes a sequence of numbers from the user and stores them as a String, then rolls a single Die until the pattern is found. The user will input a 6 digit number without spaces. You must check to see if the user used die face values as input (1-6), and if they did not ask the user for new input. You must use String methods to evaluate the values of the String of numbers. (Remember to include your name, Algorithm and module comments.)
Your program will mimic the rolling of a die to find how many rolls it takes to roll that particular sequence of numbers.
The user must be allowed to repeat the game from within the game itself. (Do not return to the Main control menu to repeat the game.)
The running of the game itself should look something like the following:
(Main Control Menu)
Please select one of the following Choices A)first Program B)second Program
C) Third Program
D)Sequence of Die Rolls Q)Quit Please enter a sequence of 6 die face values. 123459 9 is not a proper die face value. Please enter a sequence of 6 die face values. 123456 It took 945,353 rolls of the die to roll the sequence. 123456 Would you like to try again? Please enter yes or no. maybe Please enter yes or no. yes Please enter a sequence of 6 die face values. 654321 It took 95,252 rolls of the die to roll the sequence. 654321 Would you like to try again? Please enter yes or no. no (Back to Main Control Menu) Use at least three separate modules in the game. Module 1, setup game Module 2, run game Module 3, find Random number
Program hint: Use String comparison to identify the match. Use a String to store your new Die rolls. Limit the Die roll String to the same size as the user input String. Concatenate the new Die roll to the end of the String, remove the leading number from the String, then compare Strings.
MENU CODE ;
public class MenuChoices
{
private static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args)
{
String menuChoice = "";
do
{
System.out.println("A) choice 1: Progam count from a starting number, by an interval, up to some maximum value");
System.out.println("B) choice 2: Progam count from a starting number by an interval some number of times");
System.out.println("C) choice 3 : Roman Conversion Program");
System.out.println("Q) Quit");
System.out.println("Please select a menu item.");
do
{
System.out.println("Enter \"A\", \"B\", \"C\" or \"Q\" ");
menuChoice = keyboard.next().toLowerCase().trim();
} while (!menuChoice.equals("a") && !menuChoice.equals("b") && !menuChoice.equals("c") && !menuChoice.equals("q"));
switch (menuChoice)
{
case "a":
moduleOne();
break;
case "b":
moduleTwo();
break;
case "c":
moduleThree();
break;
default:
System.out.println("Good-bye!!!");
break;
}
System.out.println("An excellent choice!");
} while (!menuChoice.equals("q"));
}
private static void moduleThree()
{
RomanConversionMS.conversion();
}
private static void moduleTwo()
{
int start, interval, times;
System.out.print("Enter the starting number: ");
start = keyboard.nextInt();
System.out.print("Enter the interval (e.g. 2 or 7): ");
interval = keyboard.nextInt();
System.out.print("How many times do you want to count? ");
times = keyboard.nextInt();
if(times < 2)
System.out.println("The ending number needs to be at least one counting interval lager than the starting number!");
else
{
int num = start;
for(int i = 1; i <= times; i++)
{
System.out.print(num + " ");
num = num + interval;
}
System.out.println();
}
}
private static void moduleOne()
{
int start, interval, maximum;
System.out.print("Enter the starting number: ");
start = keyboard.nextInt();
System.out.print("Enter the interval (e.g. 2 or 7): ");
interval = keyboard.nextInt();
System.out.print("What is the maximum value you want to go to? ");
maximum = keyboard.nextInt();
if(start+interval > maximum)
System.out.println("The ending number needs to be at least one counting interval lager than the starting number!");
else
{
for(int i = start; i <= maximum; i = i + interval)
{
System.out.print(i + " ");
}
System.out.println();
}
}
Step 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