Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Design and implement the Usage class. This has an integer count and a String username in it as instance variables, a constructor taking both

1. Design and implement the Usage class. This has an integer count and a String username in it as instance variables, a constructor taking both count and username, and getters for the two instance variables (setters are not needed). You can add an increment method if you want. See page 84 for class terminology and make sure you know all these concepts. For getters and setters, see dzone.com article.

2. Test Usage.java as follows. In main of Usage.java, create a Usage object, add one to its count, and then print out its username and count using the getters. Putting test code in main is convenient, but is not as hands-off as test code in another class, because main is part of the class code, giving it rights to access private members. It is often done just temporarily during development, but leave it in this case. Note that test code in main is not meant to be part of the API of the class and can't be put in an interface for the class because main is a static method.

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.

3. 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.

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.

Please I need help this question the answers

Thank you

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions