Question: in java programuse topdown design to design and implement a...
in JAVA program.Use top-down design to design and implement a program to ask the user to enter a list of integers, and then display to the user the mean and median of this list. You should first prompt the user to specify the length of the list of integers. For this assignment, your code should create an array of size 10, and then allow the user to specify the number of integers in their list, up to a maximum of 10. Also, error handling is not the purpose of this assignment, so you can assume that the user will enter an allowable number. Of course, this will result in wasted space being allocated for the array if the user only wants to store 3 integers. Further, we will be unable to handle lists larger than the pre-determined maximum of 10.
Hello! This program will produce descriptive statistics for a list of integers.
How many integers are in the list? (max: 10)
What are the integers?
4 6 8 3 10 4 9 3 4 3
the Mean is: 5.4
the Median is: 4 Bye!
Note: the Mean is the average value of the list (the sum of the values, divided by the number of values). The Median is the “middle” value of the list, after the list is sorted (if the list has an odd number of elements, then the median is the middle value. If the list has an even number of elements, the median is the average of the two middle numbers).
This application is just big enough that planning will help you get it done in a reasonable amount of time. If you simply start writing Java code, you may spend too much time thinking at the wrong level of abstraction. So don’t!
1. The top level description is given in the question description. Use top-down design (as in Q1) to list the tasks that you need to accomplish. Refine them as necessary, stepwise, until you reach a sensible topping point, where your design can be translated fairly literally to Java.
2. Before you implement, convert all your levels to pseudo-code algorithms. Add pre-conditions, post-conditions, return criteria to everything in your design. Think about how your steps work together. Consider correctness, efficiency, robustness, adaptability, and reusability (CERAR).
3. When you are happy with your design, implement your design by converting to Java. If your design work was good, you should not need a lot of time here.
4. Document your java code by adding in comments.
5. Test your program, by trying a few examples.
Note: Don't re-invent the wheel to sort, use one of the algorithms from the COMP1230. For example, one algorithm for sorting is as follows (recall: what sorting algorithm is this?). You can choose any sorting algorithm you have learnt to do this question.
Problem: sort the elements in an array in ascending order.
Pre-condition: an array arr with n distinct elements
Post-condition: the elements in arr are sorted in ascending order
Return: The sorted array, arr
for k ← 0 to n-1
position ← k
for i ← k+1 to n-1 by 1
if (arr(i) < arr(position)) position ← i
if (position != k)
temp ← arr(k) //The next three lines swaps
arr(k) ← arr(k) //arr(k) with arr(k)
arr(k) ← temp