Question: Java please help DESIRED PROGRAM BEHAVIOR In this assignment, you are to write a program that behaves as described below. First, you will prompt the

Java please help

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:

5) Display a bar chart of values Using a bar chart class I provide, display a GUI visualization showing the values in the array.

This bar chart is interactive. If you click a bar a window will pop up showing details, including whether the value is higher or lower than the average of values in the array.

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. 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 12 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. 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. 3) static double average(double[] nbrs) This method takes a double array as a parameter and returns the average of its values.

  4. 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. 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. You can see an example in chapter 7 of the textbook.

  6. 6) static void displayBarChart(double[] values)

    This uses a barchart package that I provide for you (see below). Note that in addition to preparing data arrays for the bar chart, you will need to call the average function to determine whether a value is higher or lower than the user-entered arrays average. Also note that the bar chart expects integer values so you will need to convert doubles from the original array to integers.

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. DONT REINVENT THE WHEEL BY CODING SOMETHING YOU ALREADY CODED.

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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!