Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java programming exercise needs to have two classes, the first one's name is Numbers and needs to have the following methods as writing in the
Java programming exercise needs to have two classes, the first one's name is Numbers and needs to have the following methods as writing in the first photo, and is shown in the last photo, the main class will have the menu and will need to call these methods as needed to depend on the options in the menu, the sample input is showing in the sample output photos.
Download this Lab 1 Processing Arrays starter file. It contains two classes Numbers and Lab1. You should load these classes into a project, and write the Java code as indicated in the classes according to the following specifications. NOTE: Your code must never, never, ever \"crap out". (You must handle every possible condition) and you should never leave compile warnings without fixing them nor should you suppress them. Use the provided test plan template to implement exception handling and to thoroughly test your code. Your code must have clear, comprehensive programmer comments, Javadoc comments, for all methods. Test your code through the Lab 1 sample output below and also test using your own test cases. Class Numbers . Data members: 0 a reference to a dynamically allocated array of Float references: Do NOT use arraylist. You are to use an array in this lab. 0 an int to hold the size of the array 0 an int to hold the number of values currently in the array - Methods default constructor initial constructor using an int parameter to set size of the array addValue which will prompt the user to enter one float value cachverage will return a float which is a average of the values in the array. Set number of decimal places to 2 max. findMinMax - will return the minimum and maximum values in the array, and result of MaxValue modulo MinValue getfactorialMax will return the factorial of MaxValue after first dropping the decimal part. toString will return a String of the values in the array ooooooo - NOTE: Your output will be a little different as it is to include output of 'MaxValue modulo MinValue' and of getfactorialMax . Make meaningful changes to the menu options to take care of this. Modulo operator denoted by % is an arithmetic operator. Your program will use this operator to compute the value of max mod min that is displayed by menu option 5. Class Lab1 - Methods 0 main - Its purpose is to test the code you wrote in the Numbers class. It uses the helper method to display the menu and should loop until the user wishes to quit. Add code to process all items in the menu as per the output below. Use a switch statement for menu options. 0 displayMainMenu - Outputs the main menu to the console (standard output) . o The main menu should look like this: Please select one of the following: 1: Initialize a default array : To specify the max size of the array Add value to the array Display values in the array : Display average of the values, minimum value, maximum value, max mod min 6: To Exit Sample Output: (green is user input) Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, max mod min 6: To Exit >4 Numbers are: Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, max mod min 6: To Exit >5 Average is: 0.0, Minimum value is 0.0, Maximum value is 0.0 , max mod min is fachnialofth Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, max mod min, uorkhax 6: To Exit > 3 Enter value: 22.2 Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, max mod min, unorhbax 6: To Exit >3 Enter value: 1.0 Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, max mod min, factorhhdax 6: To Exit >3 Enter value: 2 Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, 6: To Exit > 4 Numbers are: 22.2 1.0 2.0 Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, 6: To Exit > 2 Enter new size of array: 4 Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, 6: To Exit > 4 Numbers are: Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, 6: To Exit > 3 Enter value: 2.2 Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, 6: To Exit > 3 Enter value: 1.1 maximum value, max mod min, factorialMax maximum value, max mod min, factorialMax maximum value, max mod min, factorialMax maximum value, max mod min, factorialMax maximum value, max mod min, factorialMax Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, 6: To Exit > 3 Enter value: 3.3 Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, 6: To Exit > 3 Enter value: 4 Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, 6: To Exit > 3 Array full Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, 6: To Exit > 4 Numbers are: 2.2 p w H . o w H Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, 6: To Exit > 5 Average is: 2.65, Minimum value is 1.1, Maximum value is 4.0, max mod min is max mod min, max mod min, max mod min, max mod min, max mod min, factorialMax factorialMax factorialMax factorialMax factorialMax .1 . . Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, max mod min, 6: To Exit > 1 Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, max mod min, 6: To Exit > 3 Enter value: 1 Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, max mod min, 6: To Exit > 4 Numbers are: 1.0 Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, max mod min, 6: To Exit > 5 Average is: 1.0, Minimum value is 1.0, Maximum value is 1.0, Please select one of the following: 1: Initialize a default array 2: To specify the max size of the array 3: Add value to the array 4: Display values in the array 5: Display average of the values, minimum value, maximum value, max mod min, 6: To Exit > 6 Exiting... factorialMax factorialMax factorialMax factorialMax factorialMax */ public class Numbers { lb) /** * Stores Float values. */ private Float numbers; ;() / *ak ) * Store the number of items currently in the array. ) * / private int numItems; l() / *1: * Default Constructor */ .H public Numbers() { ' // TODO Write code here to initialize a \"default" array since this is the default constructor } u) / *1: * Constructor that initializes the numbers array. * @param size Max size of the numbers array . */ be; public Numbers(int size) { // TODO Write code here to initialize the numbers array of max 'size' } ;E) /** l * Adds a value in the array ) * @param keyboard Scanner object to use for input . *l H public void addValue(Scanner keyboard) { . // TODO Write code here to add the values in the array } 4) / *1: ' * Calculates the average of all the values in the numbers array. ; * @return float value that represents the average ) */ )P) public float cachverage() { // TODO Write code to return the average of the values in the array return (float) 0.0; } b) @Override public String toString() { // TODO Write code for an appropriate toString method return \""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