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:
Line Most Common User Count
1 OPERATOR 174983
2 HANNIBAL 432
30
4 SYSMGR 945
... ... ...
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 Nodehead; // 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(Nodenode, T element) {
// create the new node
Noden = 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
Nodecurrent = 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
Nodecurrent = 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) {
SinglyLinkedListlist = 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));
SinglyLinkedListlist1 = 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;
Nodenext;
Node(T data, Nodenext) {
this.data = data;
this.next = next;
}
}