Write a Java class DemoList, the class has: a private attribute list1 as an ArrayList of Integer. Zero argument constructor that create and initilaise list1 to an empty list. A method fill(), which take no argument and return no values. The method should allow the user to read the list of integers: user should be prompted, to enter a series of integers one at a time, until the user enters 0. Those values are used to fill list1. A method sortList() that return the sorted list1. A method brint(): that print contents of list1. A method maximum() that returns maximum of list1. A method average that returns average of list1. A method median() that return median of lsit1 as follows: If the number of elements are odd then the median is the middle one in the sorted list If the number of elements is even, the median is the average of the middle two elements. For example: the median of 1, 2, 2, 3, 5 is 2, then middle element. The median of 1, 2, 2, 3, 4, 5, is 2.5 the average of the two middle values 2 and 3. Write a Java class TestDemoList, that has a main method to do the followings: Create an object of DemoList class call it dl. Call a proper method to fill dl with data. Call a proper method to print content of dl. Call a proper method to print content of dl after sorting it. Call a proper method to print the maximum in dl. Call a proper method to print the average of dl. Call a proper method to print the median of dl.
Write a Java class DemoList, the class has:
a private attribute list1 as an ArrayList of Integer.
Zero argument constructor that create and initilaise list1 to an empty list.
A method fill(), which take no argument and return no values. The method should allow the user to read the list of integers: user should be prompted, to enter a series of integers one at a time, until the user enters 0. Those values are used to fill list1.
A method sortList() that return the sorted list1.
A method brint(): that print contents of list1.
A method maximum() that returns maximum of list1.
A method average that returns average of list1.
A method median() that return median of lsit1 as follows:
If the number of elements are odd then the median is the middle one in the sorted list
If the number of elements is even, the median is the average of the middle two elements.
For example: the median of 1, 2, 2, 3, 5 is 2, then middle element. The median of 1, 2, 2, 3, 4, 5, is 2.5 the average of the two middle values 2 and 3.
Write a Java class TestDemoList, that has a main method to do the followings:
Create an object of DemoList class call it dl.
Call a proper method to fill dl with data.
Call a proper method to print content of dl.
Call a proper method to print content of dl after sorting it.
Call a proper method to print the maximum in dl.
Call a proper method to print the average of dl.
Call a proper method to print the median of dl.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images