Question: 4. Try out your LineUsage object: Write a test program TestLineUsage.java that, in main, creates one such object, and adds an observation of OPERATOR to
4. Try out your LineUsage object: Write a test program TestLineUsage.java that, in main, creates one such object, and adds an observation of OPERATOR to it, then an observation of USERMGR, then a second observation of OPERATOR, then finds the most frequent from the container by calling findMaxUsage and prints the results out. Note that putting the test code in a different source fileprovides a better test than putting test code in main, and clearly removes it from API considerations.
5. Write the main program with the big array of LineUsage objects in LineReport.java. This code , working just one of its elements (itself a LineUsage object) as appropriate for each line of input. For a small example of an array of objects, see example, but add "private" to the Employee instance variables in that example. To parse the input file, use Scanner. With line-oriented input like this, it's best to pull each line into a String (using hasNextLine and nextLine), and then process the line, now in a String. That String for one line can be processed by String.split or another Scanner for this String. Put this code that reads the file into the array in its own method: this can be a static method or an object method. Once the input line is parsed, you have a terminal line number and username. Find the right LineUsage object in the big array and add the username observation to it.
6. Continuing in LineReport, write a method that outputs the data as specified. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LineUsage.java as follow import java.util.HashMap; import java.util.Map.Entry;
public class LineUsage {
private HashMap
public LineUsage(HashMap
public void addObservation(String username) { int count=0; if(usageMap.containsKey(username)) { count=(int)usageMap.get(username)+1; usageMap.put(username, count); } else { count=1; usageMap.put(username, count); } } public Usage findMaxUsage() { int maxCount=0; String maxUser=null; Usage usageObj=null; for(Entry
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
