Your company has a server and there are 500 PC stations whose lesystem resides on it, numbered 1 through 500 inclusive. Every 10 minutes the system appends to a log le the PC numbers and user name of the person currently logged on, one PC number and username per line of text. (Not all stations are in use at every moment). A fragment of the log le looks like this:

... ......
9 ALTEREGO
12 ALIMONY
433 HOTTIPS
433 USERMGR
12 BLONDIE
433 HOTTIPS
354 ALIMONY
... ...

This log le shows HOTTIPS was on PC station 433 twice but USERMGR was on that station at an intervening time. It also shows that ALIMONY was on station 12 at one time and station 354 later on. The log does not display the time at which each line was written. Your job is to write a program in Java that meets the following specications:

  • The program rst reads a log le into memory, storing the input data as it encounters it. Assume IO redirection when your program is invoked, so it can read from System.in rather than by actually opening a named text le. User names are ASCII (plain text) strings with no embedded whitespace and a maximum length of 40 characters.
  • After all the data has been read your program should print data about PC station usage: a header line and then one line of output for each PC showing the PC station number, the most common user of that station (in the event of a tie, choose one user), and a count of how many times that user was on that PC station. Here is sample output:
Line Most Common User Count
1 OPERATOR 174983
2 HANNIBAL 432
3 0
4 SYSMGR 945
... ... ...
  • Program design: The attached listing shows class SinglyLinkedList.java, for your use to hold all the information about one PC. Do not change this class, but instead, wrap it in another class LineUsageData (i.e. LineUsageData HAS-A SinglyLinkedList.) Although normally we would use a JDK LinkedList or other JDK container for this, for the qualier the essential thing is to check that you know how to work with any reasonable Java classes. Design and implement a class Usage to hold a (username, count) pair, and a class TermReport for the top-level code. Usage can be a nested class of TermReport, or a top-level class. An object of type LineUsageData holds all the data for one particular PC station, and has methods addObservation(String username) and Usage ndMaxUsage(). TermReport.java should be decomposed into methods; including a main(). Each method should be commented (a comment above the method to describe it and comments for internal statements as needed).

Turn in the code for classes Usage, TermReport, and LineUsageData. Also please put a working email address and phone number at the top of the paper. Your program should be complete (except for the provided code) but need not compile. We would rather you wrote it with a text editor and turned in hard copy, but legible(!) handwritten copy is OK for now (but keep in mind that one of the future assignments will require you to compile and run this code). We will be looking for correct, clear logic, organization and style, not for the precise placement of semicolons or other trivial bugs. Be sure to acknowledge any sources for material you incorporate in your program. Tell us if you used a textbook, a project from another course, code o the web, etc.

SinglyLinkedList implementation: do not change this code, just use an object of this type as a eld in LineUsageData. This le is available on the class website at www.cs.umb.edu/cs310.

/* * SinglyLinkedList.java */
public class SinglyLinkedList {

private Node head; // the head dummy node
private int size; // list size (# elements)

public SinglyLinkedList() {
head = new Node(null, null);
// dummy header node!
}
// helper method
// insert a new node with given element after a given node in list

private void insertAfter(Node node, T element) {
// create the new node
Node n = new Node(element, node.next);
// insert the node in the list
node.next = n;
// update the list size
size++;
}
// add o to end of list

public boolean add(T o) {
// we move to the last node
Node current = head;
while (current.next != null) {
current = current.next;
}
insertAfter(current, o);
current = null;
return true;
}
// get the ith element, or throw if beyond end of list

public T get(int index) {
// we move to the ith node, if possible
Node current = head.next; // start after dummy
int i = 0;
while (current.next != null && i < index) {
current = current.next;
i++;
}

if (i == index) {
return current.data;
} else {
throw new IndexOutOfBoundsException();
}
}

public int size() {
return size;
}

public boolean isEmpty() {
return size == 0;
}
// quick test of this code: list of Strings, list of Integers
//

public static void main(String[] args) {
SinglyLinkedList list = new SinglyLinkedList();
list.add("foo");
list.add("bar");
list.add("bar");
System.out.println("list size = " + list.size());
System.out.println("#0 element = " + list.get(0));
System.out.println("#1 element = " + list.get(1));
System.out.println("#2 element = " + list.get(2));
SinglyLinkedList list1 = new SinglyLinkedList();
list1.add(6);
System.out.println("list1 size = " + list1.size());
System.out.println("#0 element = " + list1.get(0));
// this will throw an IndexOutOfBoundsException-
System.out.println("#1 element = " + list1.get(1));
}
}

// this is our node class, a singly linked node
class Node {

T data;
Node next;

Node(T data, Node next) {
this.data = data;
this.next = next;
}
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.