Question
1. Write a Java program MinMax.java that reads in 3 floating point numbers between 1 and 10 (inclusive) as command line arguments. First parse the
1. Write a Java program MinMax.java that reads in 3 floating point numbers between 1 and 10 (inclusive) as command line arguments. First parse the 3 inputs into doubles and check to make sure each number is between 1 and 10 if any number is outside that range, exit the program. If the numbers are all in the correct range, print out them out, and also print out which one is the largest and which one is the smallest.
2. Modify the MinMax.java program into a program called SortNumbers.java that sorts 3 numbers from smallest to largest, and prints them out first (on one line) in the original order and then (on the next line) in the sorted order. Use if or if/else statements to sort the 3 numbers.
3. Write a Java class TestProgram.java with a main method to test each of these programs. An example TestDemo.java program is given in the exercises directory, along with a Demo.java program to test. Note that Demo.java has no inputs in this case, you can see that you just give it one command-line argument with a blank String value. Use the following values to test your programs:
Both MinMax and SortNumbers: Test1: 3.4 3.2 1.1; Test2: 3 4.3 -46; Test3: 6 100 3; Test4: 1.03 10 1.030
Of course, the program should compute correct results for any valid test inputs.
4. Write a Java program MinMaxArray.java that scans floating point numbers into a double array numbers until the user types in quit, and then computes and prints the min and max values in the numbers array. Feel free to use the java.Math.min and java.Math.max methods.
5. Modify the MinMaxArray.java program into a program called SortNumbersArray.java that sorts the numbers array in ascending (smallest-to-largest) order, and then prints both the unsorted and sorted arrays. Feel free to use one of the sort() methods of the java.util.Arrays class. Note that since these methods are static (more later), you access them via the command Arrays.sort(arrayName, possibly other parameters);
In both programs, check to make sure that the user inputs valid floating-point numbers. If an valid floating number is not input at any step, prompt the user to re-input the number.
PLEASE POST CODE ONLY FOR #'s 4 AND 5
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