I\'m looking for help wil modifying the following code to appear with instruncti
ID: 3777103 • Letter: I
Question
I'm looking for help wil modifying the following code to appear with instrunctions and input options in one pop-up pane, and then the input options and random output to be in a new pane. The code as is works how I want to, outside of being able to appear in pop-up panes. This program is a decision maker program, I want the user to choose how many options to input, input each option, and then the program and randomly output one of the inputs. Needs to be in Java
//**************************************************************
//Title: Decision Maker Program
//FILENAME: Term Project
//Prepared for: Java
//Programer: Â Amanda Kopp
//Developement date: 11/21/2016
//Compiler: netbeans
//****************************************************************
import java.util.Scanner; // for typing input not dialogue box
public class decisionMaker {
public static void main(String[] args) {
System.out.println("Welcome to the Decision Maker");
System.out.println("Please enter how many you want to options to choose from ");
System.out.println("Input your options ");
System.out.println("This program will in return one of those options");
System.out.println(" ");
System.out.println("************************************************************");
try ( // output
Scanner scanner = new Scanner(System.in)) {
int size = getInt(scanner);
String option[] = new String[size];
for (int index = 0; index < size; index++) {
System.out.println("Enter the next option: ");
option[index] = scanner.next();
} int index = (int) (Math.random() * size);
System.out.println("************************************************************");
System.out.println(" ");
System.out.println("Choosen for you: ");
System.out.println(option[index]);
System.out.println(" ");
System.out.println("************************************************************");
// output
System.out.println("************************************************************");
System.out.println(" ");
System.out.println("Thank you for using Decision Maker ");
System.out.println("GoodBye ");
System.out.println(" ");
System.out.println("************************************************************");
}
}
public static int getInt(Scanner scanner) {
Scanner input=new Scanner(System.in);
System.out.println("************************************************************");
System.out.println(" ");
System.out.print("Enter number of options you would like to choose from: ");
int size = input.nextInt();
System.out.println(" ");
System.out.println("************************************************************");
while (size <= 0) {
if (scanner.hasNext()) {
if (scanner.hasNextInt()) {
size = scanner.nextInt();
}
}
if (size <= 0) {
System.out.println("The input: " + scanner.next() + " is not a valid value.");
}
}
return size;
}
}//end of main
Explanation / Answer
import java.util.Scanner; // for typing input not dialogue box
import javax.swing.*; //This for dialog pane
public class decisionMaker {
public static void main(String[] args) {
System.out.println("Welcome to the Decision Maker");
System.out.println("Please enter how many you want to options to choose from ");
System.out.println("Input your options ");
System.out.println("This program will in return one of those options");
System.out.println(" ");
System.out.println("************************************************************");
JFrame frame = new JFrame("Decision Maker");
String name = JOptionPane.showInputDialog(frame, "What's your name?");
int size = getInt(scanner);
String option[] = new String[size];
for (int index = 0; index < size; index++) {
option[index] = JOptionPane.showInputDialog(frame, "Enter the next option: ");
} int index = (int) (Math.random() * size);
JOptionPane.showMessageDialog(frame, "************************************************************ Choosen for you: "+option[index]+" ************************************************************ ************************************************************ Thank you for using Decision Maker GoodBye ************************************************************");
}
public static int getInt(Scanner scanner) {
JFrame frame = new JFrame("Decision Maker");
System.out.println("************************************************************");
System.out.println(" ");
int size = parseInt(JOptionPane.showInputDialog(frame, "Enter number of options you would like to choose from: "));
System.out.println(" ");
System.out.println("************************************************************");
while (size <= 0) {
size = parseInt(JOptionPane.showInputDialog(frame, "Enter number of options you would like to choose from: "));
if (size <= 0) {
System.out.println("The input: " + scanner.next() + " is not a valid value.");
}
}
return size;
}
}//end of main
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.