Question: Min, max, median (generic methods): JAVA Given main(), complete LabProgram.java by implementing the following methods: inputIntegers() Take a scanner as a parameter Read 5 integers
Min, max, median (generic methods): JAVA
Given main(), complete LabProgram.java by implementing the following methods:
inputIntegers()
Take a scanner as a parameter
Read 5 integers from a user
Store the integers in an ArrayList of type Integer
Return the ArrayList
inputDoubles()
Take a scanner as a parameter
Read 5 doubles from a user
Store the doubles in an ArrayList of type Double
Return the ArrayList
inputWords()
Take a scanner as a parameter
Read 5 one-word strings from a user
Store the strings in an ArrayList of type String
Return the ArrayList
print()
Take an ArrayList as a parameter
Output the elements of the ArrayList parameter
For coding simplicity, follow each output element by a space, including the last one
Output a newline after the last element
getStatistics()
Take an ArrayList as a parameter
Store the minimum, median, and maximum values of the ArrayList parameter in a new ArrayList
Return the new ArrayList containing the minimum, median, and maximum values
Hint: Sort the ArrayList by using Collections.sort() to find the minimum, median, and maximum values
import java.util.Scanner; import java.util.ArrayList; import java.util.Collections;
public class LabProgram {
// Input 5 Integers and return the Integers in an ArrayList public static ArrayList
// loop through for the 5 integers for(int i = 0; i < 5; i++) integers.add(scnr.nextInt());
// return the computed list of integers return integers; }
// Input 5 Doubles and return the Doubles in an ArrayList public static ArrayList
// loop through for the 5 doubles for(int i = 0; i < 5; i++) doubles.add(scnr.nextDouble());
// return the computed list of doubles return doubles; }
// Input 5 Strings, and return the Strings in an ArrayList public static ArrayList
// loop through for the 5 words for(int i = 0; i < 5; i++) words.add(scnr.next());
// return the computed list of words return words; }
// Output the elements of the ArrayList parameter public static
// Return the min, median, and max of the ArrayList parameter in a new ArrayList public static
// store the first element of the sorted list as the minimum value stats.add(lst.get(0)); // store the mid element of the sorted list as the median value stats.add(lst.get(lst.size() / 2)); // store the last element of the sorted list as the maximum value stats.add(lst.get(lst.size() - 1));
// return the statistics return stats; }
public static void main(String[] args) { Scanner scnr = new Scanner(System.in);
// Input a list of 5 Integers and print the ArrayList's statistics ArrayList
// Input a list of 5 Doubles and print the ArrayList's statistics ArrayList
// Input a list of 5 words (Strings) and print the ArrayList's statistics ArrayList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
