Question
2. Now start on LineUsage. It is supposed to use a Map of String to Integer to hold the counts so far for each user
2. Now start on LineUsage. It is supposed to use a Map of String to Integer to hold the counts so far for each user seen on a particular line. Thus if OPERATOR was seen on the line 34 times and USERMGR seen 12 time, the map would hold "OPERATOR" --> 34 ad "USERMGR" --> 12. You could find the 34 by calling map's get method, get("OPERATOR"). Use the Map type for the type of the instance variable, but of course use you need to use the concrete type HashMap or TreeMap for creating the container object. Study the supplied program FrequencyCounter.java to see the details of repeatedly adding one to the count for a certain string. Here the map itself is held in an instance variable of LineUsage, private of course, not a local variable of method main as you see in FrequencyCounter.java. Thus each LineUsage object has its own map for its own data, separate from the data for a different line number. The constructor of LineUsage creates an instance of the map for the value of this instance variable.LineUsage should have methods addObservation(String username) and Usage findMaxUsage(), which returns the Usage object for the user with the highest count. Note that Usage is not used in the map, only in the delivery of results once the Map is full of data. Pls help me write the class LineUsage.java, and help me go through it if possible! here is the Usage.java I wrote public class Usage{ private String username; private int count; public Usage(String x) { count = 0; username = x; } public String getUsername() { return username; } public int getCount() { return count; } public void increment() { count++; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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