Question: In this Java example code, how do I get this menu to display and function based on user commands? The screenshot shows how the menu

In this Java example code, how do I get this menu to display and function based on user commands?
The screenshot shows how the menu should be formatted, and the goal is so that the program can accept and respond accordingly to each command. This is the example code I have so far:
package com.app;
import java.util.Random;
import org.json.simple.JSONArray;
public class CavazosExample {
public static void main(String[] args){
String fileName =
"/Users/envyi/Documents/GitHub/General_Cavazos_App/cavazosapp/src/main/java/com/app/commands.json";
// read commands
JSONArray commandJSONArray = JSONFile.readArray(fileName);
String[] commandArray = getCommandArray(commandJSONArray);
System.out.println(commandArray);
// print list of all commands
System.out.println("----- List of all commands -----");
print(commandArray);
System.out.println(
"----- Issuing 5 random commands from General Cavazos -----"
);
randomCommand(commandArray,5);
}
// randomly issue commands from General Cavazos
public static void randomCommand(String[] commandArray, int numCommand){
Random rand = new Random();
System.out.printf("Number\tCommand
");
System.out.printf("------\t---------------
");
for (int i =0; i numCommand; i++){
int randIndex = rand.nextInt(commandArray.length);
System.out.printf("%04d\t%s
", i, commandArray[randIndex]);
}
}
// print command array
public static void print(String[] commandArray){
System.out.printf("Number\tCommand
");
System.out.printf("------\t---------------
");
for (int i =0; i commandArray.length; i++){
System.out.printf("%04d\t%s
", i, commandArray[i]);
}
}
// get array of commands
public static String[] getCommandArray(JSONArray commandArray){
String[] arr = new String[commandArray.size()];
// get names from json object
for (int i =0; i commandArray.size(); i++){
String command = commandArray.get(i).toString();
arr[i]= command;
}
return arr;
}
}
General Cavazos Commander App
Issue a command
List all of the commands
Undo the last command that was issued
Redo the last command that was issued
Quit
Enter a command:
In this Java example code, how do I get this menu

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!