Question: Java Assignment: Ignore the bar charts, but follow instructions and methods fully. DESIRED PROGRAM BEHAVIOR In this assignment, you are to write a program that
Java Assignment: Ignore the bar charts, but follow instructions and methods fully.
DESIRED PROGRAM BEHAVIOR
In this assignment, you are to write a program that behaves as described below. First, you will prompt the user to enter a size for a numeric array, which you instantiate accordingly. Then you will ask the user to enter that many numbers and fill the array with these values. This array will be a local variable of your main method and will be passed as an argument to some of the methods you create.

After, this, your program should loop repeatedly, presenting a menu for the user to select from, like this:

The user will enter a choice, and the program should perform the appropriate operation. The following are done:
1) Determining if a number is prime
User enters a number. A statement appears indicating whether or not the number is a prime number. Here are a couple examples:

2) List all prime numbers below a given value
User enters the number. Response is a list all primes up to that number as shown below (each line displays a maximum of ten values):

3) Compute statistics from an array:
Your program will calculate and display the average and the standard deviation for the values in the array. Output for above numbers in array will look like this:
4) Perform linear search for number in the array
User enters the number to search for. If number is found in the array, the position is displayed, otherwise a not found message appears: For the above array values, here are a couple outputs:

0) Quit the program Program says goodbye and terminates:
ERROR HANDLING
Your program must handle any errors that the user has. If the user enters an invalid number, or if the user enters a non-numeric value, you must present an error message and allow the user to try again. For example, if the user enters an invalid menu choice, the message could look say something like Invalid choice, please try again.
If an exception occurs (for example if a user enters a string when a number is expected), you should catch this exception and print the exception content, then loop to present the menu again. Something like this:

Hint: the Exception class has a toString() method that you can call in the catch section.
PROGRAMMING TASKS
For this assignment, you will write a program that includes methods for various tasks. The signatures for these methods and descriptions of the tasks they perform are listed below:
1) static boolean isPrime(int number)
This method returns True if the parameter is a prime number. A prime number is a number that has no factors other than itself and 1. For example, 2, 3, 5, and 7 are prime numbers, but 4, 6, 8, and 9 are not.
The trick to test if a number is prime is to make sure it is not divisible by any number (other than 1) lower than itself. So, if you had a loop that went from 2 to the value of the number you are testing, and checked whether the number you are testing was divisible by the loop counter number, and if NONE of these came out true, then you would know it is a prime number.
2) static String listPrimes(int number)
This method returns a string that contains all of the prime numbers that are less than or equal to the passed in parameter. For example, if the value of the parameter is 10, then the string should have 1, 2, 3, 5, 7.
This method involves a loop in which all the primes are concatenated to the string. When completed, the string is returned. This method should call the isPrime method in order to determine, for each value in the loop, whether it is prime. Try to avoid long lists appearing on a single line. Something like 10 numbers per line of output.
3) static double average(double[] nbrs)
This method takes a double array as a parameter and returns the average of its values.
4) static double standardDeviation (double[] nbrs)
This method takes a double array as a parameter and returns the standard deviation of its values. This method should call average for the array, then use this value to calculate the standard deviation.
5) public static int linearSearch(double[] list, double value)
This performs a linear search of an array of doubles. It returns the position of a value if found in the array, or -1 if not found.
NOTE: NONE OF THESE METHODS SHOULD INPUT VALUES FROM THE USER OR DISPLAY DATA TO THE USER. THEY ARE ALL TO RECEIVE THEIR VALUES AS FORMAL PARAMETERS, AND THEY ARE ALL TO RETURN VALUES TO THE CALLER OF THE METHOD. ALL USER-INPUT AND USER DISPLAY SHOULD BE DONE IN THE MAIN METHOD. NOTE ALSO: NONE OF THESE ARE BIG METHODS. NO METHOD WILL REQUIRE MORE THAN 15-20 LINES OF CODE, AND SOME REQUIRE MUCH LESS. ALSO, NO METHOD REQUIRES A NESTED LOOP, ALTHOUGH SOME MAY INVOLVE AN IF STATEMENT INSIDE A LOOP. IF YOU FIND THAT THE METHODS ARE GETTING TOO LARGE, THEN YOURE PROBABLY ON THE WRONG TRACK. NOTE ALSO: SOME METHODS MAKE USE OF OTHERS. IF THE FUNCTIONALITY IS ALREADY THERE, USE IT.
THE main METHOD
Your main method should begin by asking the user how to size the array, then create the array and input values into each element of the array.
Next, you should have a loop that presents a menu of options to the user, and then performs the desired option. For some options, your main method will need to ask the user to input the values that will be sent as arguments to the methods, call the appropriate method, and then will need to display the results that were returned from the method. The overall structure of the menu-processing in the main method will be a loop with a nested decision structure (either an IF statement or a SWITCH).
Again, as stated above, the above-listed methods DO NOT involve any user interaction. They merely take in parameters, perform the appropriate computations, and return results. All data shared between methods is done via parameter passing. There should be no class-wide variables in this assignment.
Also, make sure to do any necessary exception and error handling in the main method.
How many numbers in the array? 6 Please enter 6 numbers. 20.5 33 15.2 35 22 19.3 Enter : to determine if a number is prime 2 to list prime numbers below a given value 3 to compute the statistics from an array of numbers 4 to perform linear search finding a number in the array to display a bar chart of values 0 to quit Enter a number: 99 99 is NOT a prime number Enter a number: 101 101 Is a prime number Enter a number: 200 The prime numbers up to 200 are: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 The average of: 20.5 33.0 15.2 35.0 22.0 19.3 is 24.166666666666668 The standard deviation of: 20.5 33.0 15.2 35.0 22.0 19.3 is 7.970110831517129 Enter a double value: 22 The value 22.0 is found in position 4 Enter a double value: 100 The value 100.0 is not in the array Enter a number: x Error. Please try again: java.util.InputMismatchException Enter : 1 to determine if a number is prime 2 to list prime numbers below a given value 3 to compute the statistics from an array of numbers 4 to perform linear search finding a number in the array 5 to display a bar chart of values 0 to quit O in W
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
