Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 11 (18 points) Write a complete Java program (no documentation required) that will read all the data from a file, create a histogram
Question 11 (18 points) Write a complete Java program (no documentation required) that will read all the data from a file, create a histogram from the data, and then display it on the screen. The data file (called ages.txt) is error-free and contains only ages of a large sample of random students in a school. All the ages are between 18 and 30, inclusive. The size of the file is unknown, but each row of the data file has the age of just one student. You must use several methods to accomplish this task, including: 1. [6 marks] a Java method that takes a data file (notice the parameter type), extracts all the data from it and produces a frequency array. Use the following header for your method: public static int[] getFrequencyData (Scanner theData) A frequency array is a single array that compactly records that there were 4 students of age 18, 8 students of age 19, 13 students of age 20, etc. 2. [6 marks] a Java method that when given a frequency array, displays a histogram like the example following on the screen that shows the frequency of each age. Use the following header for method: public static void displayFrequencies(int[] frequencies) your In the diagram, each dash after the age number represents a student of that age. For example, according to the following diagram, there are 4 students of age 18 and 3 students of age 22. There is nobody of age 27, 29 nor 30. 18 19 20 21 22 --- 23 24 26 3456 25 -- 27 28- 29 30 Total: 55 students 3. [6 marks] Other methods and statements necessary to complete the rest of the program requirements, including properly calling the above two methods. Note: Put all the methods, including main method in a class so that your program can compile and run.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres the complete Java program import javaioFile import javaioFileNotFoundException import javautil...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started