For this lab, you will write one class named DataInput. It will be due at 11:59pm on Thursday, March 12. The labs here will be about reading data from text files. You can download example files at this link: https://drive.google.com/drive/folders/1I5syEg3zz0ES1oCXrHvNVmGf4K-IH-tn?usp=sharing. Please feel free to change the values in the file to make sure it works in different situations. When I grade your code, I will insert a file with the same name but different values and test it with those.
This lab contains two files you will read data from:
-numbers.txt : you can assume each row contains int values separated by spaces
-ages.txt : you can assume each row contains a single String followed by an int
(example files are here: https://drive.google.com/drive/folders/1I5syEg3zz0ES1oCXrHvNVmGf4K-IH-tn?usp=sharing)
ALL METHODS IN THIS CLASS WILL BE STATIC!
Write a method named sumData() - this method will take no inputs and read its data from a file named "numbers.txt", of which I have included an example file in the link above. Your method should return an int representing the sum of all of the values in the file. For example, if numbers.txt has the following lines:
2
12
2
4
2
10
4
Your method should return 36 (the sum of each value).
Write a method named mean() - this method will take no inputs and read its data from a file named "numbers.txt". Your method should return a double representing the average of all of the values in the table. For the above example, it should return approximately 5.14285714286 (this value is 36 divided by 7).
Write a method named extremes() - this method will take no inputs and read its data from a file named "numbers.txt". It should return an int representing the difference between the maximum and minimum values in the table. For the above example, the maximum value is 12 and the minimum value is 2. Since 12-2 = 10, this method should return 10.
Write a method named howMany(int a) - this method will input an int and read the data from "numbers.txt". It will return an int representing how many times the parameter a appears in the text file. For example, in the above file, howMany(3) would return 3. howMany(12) would return 1. howMany(132) would return 0.
Write a method named mode() - this method will take no inputs and read its data from a file named "numbers.txt". It should return the number which appears most often in the file. Since the above example has three 2's, it should return the number 2. You could either call the previous method OR put all the inputs in an ArrayList<Integer> and loop through that.
Write a method named getAdults() - this method will take no inputs and read its data from a file named "ages.txt". It should return an ArrayList<String> containing the names of the people with an age greater than or equal to 18. For example, if the ages.txt file looks like this:
Greg 24
Nick 24
Kathryn 22
Brooke 14
Jason 67
Wesley 6
Ryan 2
Thai 13
Your method should return an ArrayList of Strings containing ["Greg","Nick","Kathryn","Jason"]. NOTE: this method might be easier to test in a main method rather than just right-clicking in blueJ.
Write a method named countTeens() - this method will take no inputs and read its data from a file named "ages.txt". It will return an int representing how many people have an age between 13 and 19 (inclusive). In the above example, this would return 2 (counting both Brooke and Thai).
Make sure to submit DataInput.java, numbers.txt, and ages.txt