How would I make it so these are dialog boxes instead of just like a regular question?
Here are the instructions.
"Ask the user to input a number. You must use an input dialog box for this input. Be sure to convert the String from the dialog box into an integer (int). The program needs to keep track of the smallest number the user entered as well as the largest number entered. Use a Confirm dialog box to ask the user if they want to enter another number. If yes, repeat the process. If no, output the smallest and largest number that the user entered.
This program only outputs the largest and smallest number once AT THE END of the program when the user wants to quit.
Also, your program should account for the case when the user only enters one number. In that case, the smallest and largest number will be the same."
Here is the code I have
import java.util.Scanner;
public class MinMax {
public static void
main(String[] args) {
Scanner scanner =
new Scanner(System.in);
// delcare two variable
min and max
int
minNumber = 0, maxNumber = 0;
boolean
firstTime = true;
String choice =
"";
// keep asking for a
number until user enter N and wants to quit
while
(true) {
System.out.print("Enter your number:
");
int
userNumber = scanner.nextInt();
scanner.nextLine(); // for consuming the new line charaacter
// when the firstTime is true we
assign the first number
// to both min and max and set the firstime vlaue to False
if
(firstTime) minNumber = maxNumber = userNumber;
// we check if the number entered is less than min, if true we set
the
// new min value to the current value
if
(userNumber < minNumber) minNumber = userNumber;
// we check if the number entered is greater than min, if true we
set the
// new max value to the current value
if
(userNumber > maxNumber) maxNumber = userNumber;
firstTime = false; // once we set the first value
to both min and max we set this value to false
// enter a loop until user enters either Y or N only
while
(true) {
System.out.print("Do you want to enter
again (Y for yes N for No): ");
choice = scanner.nextLine().toUpperCase();
if
(choice.equals("Y")) break;
else
if (choice.equals("N"))
break;
else
System.out.println("Please enter either Y
or N only. Try again.");
}
if
(choice.equals("N")) break;
}
// print both min and
max values at the end
System.out.println("Min:
"+minNumber);
System.out.println("Max:
"+maxNumber);
}
}
import java.util.SortedSet;
import java.util.TreeSet;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
class MinMax {
public static void main(String [] args) {
String choice="Y",test1;
int int1,min=99999,max=0,turn=1;
while(choice.equals("Y")){
//displaying a dialog box for input
test1= JOptionPane.showInputDialog("Please Enter the Number:
");
//converting input into integer
int1 = Integer.parseInt(test1);
//finding min value
if(int1<min)
min=int1;
//finding max value
if(int1>max)
max=int1;
if(turn==1){
min=int1;
max=int1;
turn=2;
}
//asking the user to continue or not
choice= JOptionPane.showInputDialog("Do you want to
Continue(Y/N):");
choice=choice.toUpperCase();
}
JFrame frame = new JFrame();
//printing min value
JOptionPane.showInternalMessageDialog(frame.getContentPane(),
String.format("Min %d", (min)));
//printing max value
JOptionPane.showInternalMessageDialog(frame.getContentPane(),
String.format("Max %d", (max)));
}
}









Output:


Please Like it.
How would I make it so these are dialog boxes instead of just like a regular...
I need help asking the user to half the value of the displayed random number as well as storing each number generated by the program into another array list and displayed after the game is over at the end java.util.*; public class TestCode { public static void main(String[] args) { String choice = "Yes"; Random random = new Random(); Scanner scanner = new Scanner(System.in); ArrayList<Integer> data = new ArrayList<Integer>(); int count = 0; while (!choice.equals("No")) { int randomInt =...
I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...
public static void main(String[] args) { System.out.println("Welcome to the Future Value Calculator\n"); Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // get the input from the user System.out.println("DATA ENTRY"); double monthlyInvestment = getDoubleWithinRange(sc, "Enter monthly investment: ", 0, 1000); double interestRate = getDoubleWithinRange(sc, "Enter yearly interest rate: ", 0, 30); int years = getIntWithinRange(sc, "Enter number of years: ", 0, 100); System.out.println(); ...
Step 4: Add code that discards any extra entries at the propmt that asks if you want to enter another score. Notes from professor: For Step 4, add a loop that will validate the response for the prompt question: "Enter another test score? (y/n): " This loop must only accept the single letters of ‘y’ or ‘n’ (upper case is okay). I suggest that you put this loop inside the loop that already determines if the program should collect...
How would I edit this Java program to end if the user inputs 0 or less? public static void main(String[] args) { Scanner sc = new Scanner(System.in); // to read input String Message; int m=0; int i=1; System.out.print("Please enter the message you would like displayed: "); Message=sc.nextLine(); while(true) { System.out.print("How many times would you like your message displayed?"); m = sc.nextInt(); break; } do { System.out.println(Message); //When I enter 0 or a negative number it still runs at least once,...
Can someone explain me parts of this code I do not fully understand what its doing or what its purpose is. I have highlighted the parts I'm confused over. Please explain thoroughly. import java.util.Scanner; class A1Stats { public static void main(String args[]) { double min, max, sum, mean; int n; Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); String[] numbers = input.split(" "); double value[] = new double[numbers.length]; if(numbers.length > 0){ for (int i = 0; i < numbers.length;...
**how can I make my program break if 0 is entered by user as last number not always 10 numbers output should be enter 10 numbers:1 2 0 numbers entered by user are: 1 2 Largest number: 2 **arrays can ONLY be used in the main function, other than the main function pointers should be used #include #define N 10 void max(int a[], int n, int *max); int main (void) { int a [N], i , big; printf("enter %d numbers:",N);...
I am given an input file, P1input.txt and I have to write code to find the min and max, as well as prime and perfect numbers from the input file. P1input.txt contains a hundred integers. Why doesn't my code compile properly to show me all the numbers? It just stops and displays usage: C:\> java Project1 P1input.txt 1 30 import java.io.*; // BufferedReader import java.util.*; // Scanner to read from a text file public class Project1 { public static...
Can you help me rearrange my code to make it look cleaner but still give the same output? Also kindly add an in-line comment on what changes and rearrangement you've done so I can understand what's going on. import java.util.ArrayList; import java.util.Scanner; public class Bank { /** * Add and read bank information to the user. * @param arg A string, double and int array containing * the command line arguments. * @exception Any exception * @return an arraylsit of...
(How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...