pa0_skeleton/LineReport.java pa0_skeleton/LineReport.java package pa0; // Import here as needed public class LineReport { // Variables here // Constructor public LineReport() {}...

1 answer below »
https://www.cs.umb.edu/cs310/homework/pa00.pdf
https://www.cs.umb.edu/cs310/homework/suggested_pa0.pdf



pa0_skeleton/LineReport.java pa0_skeleton/LineReport.java package pa0; // Import here as needed public class LineReport {     // Variables here     // Constructor     public LineReport() {}     // read input data, put facts into lines array     void loadData(String fname) {}     // given loaded lines array, generate report on lines     void generateReport() {}     public static void main(String[] args) {} } pa0_skeleton/LineUsage.java pa0_skeleton/LineUsage.java package pa0; // Import packages as needed // LineUsageData.java: Handle one line's data, using a Map public class LineUsage {     // Variables here     // Constructor     public LineUsage() {     }     // add one sighting of a user on this line     public void addObservation(String username) {     }     // find the user with the most sightings on this line     public Usage findMaxUsage() {     } } pa0_skeleton/Usage.java pa0_skeleton/Usage.java package pa0; // One user's record on one line: how many times // this user has been seen on this line public class Usage {     // Put variables here.     public Usage(String x, int count) {     }     public void setCount(int x) {     }     public String getUser() {     }     public int getCount() {     } } CS310: Advanced Data Structures and Algorithms, PA0 Due: Wednesday, Sep. 29 2021, on Gradescope Introduction This assignment was written by Prof. Betty O’Neil (slightly adapted). It aims to help you: • Learn about Maps (Symbol Tables), and get experience with their JDK classes • Think about performance and memory use • A brief revision of Java • Introduction to Gradescope (and hopefully to using Java on Unix/Linux) Reading Read S&W Section 3.1 on symbol tables (maps), Section 3.5 on applications including text indexes. Read the JDK API docs on at least Map, HashMap, and TreeMap. Project Description also see Suggested Steps for more information. A simple application using JDK collection classes The main server at your company maintains 500 terminal lines, numbered 1 through 500 inclusive. Every 10 minutes the system appends to a log file the terminal line numbers and user name of the person currently logged on, one terminal line number and username per line of text. (Not all lines are in use at every moment.) A fragment of the log file looks like this: 9 ALTEREGO 12 ALIMONY 433 HOTTIPS 433 USERMGR 12 BLONDIE 433 HOTTIPS 354 ALIMONY This log file shows HOTTIPS was on line 433 twice but USERMGR was on that line at an intervening time. It also shows that ALIMONY was on line 12 at one time and line 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 specifications. The program first reads a log file into memory, storing the input data as it encounters it. Read from a text file! Make sure you know about absolute and relative paths and don’t hard-code the file name. 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 terminal line usage: a header line and then one line of output for each terminal line showing the terminal line number, the most common user 1 http://www.cs.umb.edu/cs310/homework/suggested_pa0.pdf of that terminal line (in the event of a tie, choose one user), and a count of how many times that user was on that terminal line. Here is sample output: Line Most Common User Count 1 OPERATOR 174983 2 HANNIBAL 432 3 0 4 SYSMGR 945 ... ... ... Implementation Since the lines are numbered consecutively, it is easy to use an array with one spot for each line (500 entries in this case). Each line needs a container of user-count data, i.e. how many times each user has been seen on that line. The following class should be implemented: • Create a class named Usage to hold a single username and its count together. It is quite simple. It should have getters – getUser and getCount (these names specifically). The constructor should get the name, then the number. • Create a class named LineUsage to hold all the data on one particular terminal line. In this LineUsage class, use a Map from the JDK (HashMap or TreeMap), mapping each username to its count, an Integer. The map’s name should be lines. See the provided program FrequencyCounter.java for an example of using a Map to hold a count for each of many strings. 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. • The top-level class LineReport has an array of LineUsage objects to hold all the data on all the lines. See page 72 of S&W for discussion of an array of objects. LineReport.java should have several methods (at least two object methods or static methods), including a main() to run the program. Each method should be commented (a comment above the method to describe what it does). • To test your code you can add a simple test called TestLineUsage, which tests LineUsage: just create one LineUsage object, add data to it, and print it out. Do not submit it. • Since the array count starts from 0, remember to add 1 back to the index before you print. Directory setup In accordance with current Java programming practice, each project in this class will held in a directory system with a top level directory. We did not cover packages yet. For now, suffice to say that a java package is a module that groups together classes or interfaces that do similar things. Your sources should be a part of a package called pa0. This means they have to all reside in a directory called pa0 (case sensitive!) and every java file has to start with the following line: package pa0; If the sources are not in a directory called pa0 or the java source files don’t have a package statement is not at the top, the source files will not compile. If you do not put the java files in a package named pa0, the autograder will fail. I recommend that you start by creating a src directory for all Java sources, and the pa0 subdirectory will be under src. If you are using an IDE, the binaries will be separately held in directory bin (or classes). The simple case (no IDE in use) will have the following directory structure: src pa0 classes pa0 The src directory contains the following: • src/pa0/Usage.java • src/pa0/LineUsage.java • src/pa0/LineReport.java • src/pa0/TestLineUsage.java (for testing, not submission) Here forward slashes are used for directories. Under Windows, back slashes are used for directories, but we will consistently the Linux/Mac syntax of forward slashes: just reverse the slashes for Windows. You can create these on your home system, then transfer the whole pa0 directory system to a linux system for testing, e.g., users.cs.umb.edu. See AccessToCSSystems for file transfer instructions. To build LineReport, cd to the src directory and use the following command, on Linux/Mac. The reason to be cd’d to this directory is that this is the easiest way to get the right java ”classpath” in use, the search path for input files to the compiler (here pa0/*.java, remember the package discussion above) or the java command (here LineReport.class). The default classpath for java and javac is the current directory, and you’ve cd’d to the right place to set the desired classpath this way: javac -d ../classes pa0/*.java (while cd’d to src) java pa0.LineReport inputfile (while cd’d to classes. inputfile should be in your current working direc- tory. If not, specify its path) The -d command tells the compiler where to put the compiled .class files. For an IDE like eclipse, set up the directories as above (with src and bin or classes), put the sources in src, and then set up a project in the IDE. Eclipse can ”open project from file system” once it is set up. memo.txt In the file memo.txt, answer the following questions, in one to two pages (60-120 lines) of text. I will not take off points for minor typos or spelling errors but please use standard English and complete sentences, like you would in an English class. 1. Discuss your experiences in writing these programs. What development tools (IDE, etc.) did you use? Did you develop on cs.umb.edu servers, or if on your own PC/Mac did you have any problem recompiling and running on Linux? 2. Analyze the worst case big-O CPU performance of LineReport, for N input lines and O(N) different users, and thus max O(N) entries on each list once partially done. To make it easier, try to first figure out what is the run time for each separate line. 3. Show the command line compile and run using commands as shown above, and display of directories by the Windows tree command or Linux/Mac du command. Delivery Before† the due time, assemble files in the pa0 (lowercase pa, number 0) subdirectory as mentioned above. Make sure they compile and run on Linux! They should, since Java is very portable. It’s mainly a test that the file transfer worked OK. The following files should be uploaded to Gradescope: • memo.txt (plain txt file, try ”more memo.txt” on users to make sure it’s readable on Linux) • Usage.java • LineUsage.java • LineReport.java https://www.cs.umb.edu/cs310/AccessToCSHosts.html See recorded demo for instructions how to upload files to Gradescope and what to expect from the autograder. The java file names should be exactly as instructed, or the automatic grader will not recognize them and fail. Remember that case counts on UNIX/Linux! † When I say before I mean before. Do not wait until the last minute!. I will take points off for unauthorized late submissions. CS310: Advanced Data Structures and Algorithms, PA0 Suggested steps, more discussion Adapted from Prof. Betty O’Neil First get organized in your filesystem for this class. We are not using a VM, so the files for this class competes for attention with all your other computer activities. Decide on one top-level directory for all the projects, say c:/cs310 on Windows or ~/cs310 on Mac or Linux, but it’s up to you. Then make a src directory inside this top-level directory for this project, and a pa0 subdirectory inside src. Decide what IDE, if any, you want to use for this class. I prefer eclipse for Java, but also use Netbeans for other languages and could use it for Java. These are both free and in common use by working programmers. IDEs know the syntax of the language, and what methods each class has, for easier programming. They automatically compile as you edit, for immediate feedback on syntax problems. You can also use a simple text editor and compile and run through the command line. Make sure you understand all the terminology that goes with a Java class. First look at page 9 in the text: all those red notations on parts of this basic program. This program does not create an object, however. Then look at page 85 for the case of a Java source for an object class, again with red annotations showing terminology. LineUsage: a program using JDK Collection classes Suggested steps: a bottom-up approach, so we can execute something for each step. All the java files for this part will be in the src
Answered 2 days AfterSep 29, 2021

Answer To: pa0_skeleton/LineReport.java pa0_skeleton/LineReport.java package pa0; // Import here as needed...

Ramachandran answered on Oct 02 2021
145 Votes
Order-92390/cs310/classes/inputfile.txt
1 TOM
4 CHRIS
2 BOB
9 ALTEREGO
12 ALIMONY
1 TOM
433 HOTTIPS
433 USERMGR
12 BLONDIE
433 HOTTIPS
354 ALIMONY
Order-92390/cs310/classes/pa0/LineReport.class
package pa0;
public synchronized class LineReport {
private static final String PRINT
_FORMAT = %-15s%-45s%-20s;
private final LineUsage[] lineUsages;
public void LineReport();
void loadData(String);
void generateReport();
public static void main(String[]);
}
Order-92390/cs310/classes/pa0/LineUsage.class
package pa0;
public synchronized class LineUsage {
private java.util.Map userCountMap;
public void LineUsage();
public void addObservation(String);
public Usage findMaxUsage();
}
Order-92390/cs310/classes/pa0/TestLineUsage.class
package pa0;
public synchronized class TestLineUsage {
public void TestLineUsage();
public static void main(String[]);
}
Order-92390/cs310/classes/pa0/Usage.class
package pa0;
public synchronized class Usage {
private final int count;
private final String username;
public void Usage(int, String);
public int getCount();
public String getUsername();
public static void main(String[]);
}
Order-92390/cs310/memo.txt
-----------
Experience
-----------
The Programs were good introduction to java data strucures like Map. I learnt about how to create methods to do a single job. During the program i learnt how to use methods in Java Map. By creating classes i learnt how to create small piece of workable code that can be reused.
I used eclipse IDE for program development. The autocomplete feature of eclipse makes programming easy and fun.
I used my PC to build and run the program
-------------------
Complexity Analysis
-------------------
The average time complexity for a HashMap is 0(1) and the worst case is 0(n) is the number of records.
In worst case scenario, all keys are mapped to the same bucket, the lookup time of HashMap increases from O(1) to O(n).
In java 8 the worstcase time complexity is 0(log(n)). This is because balance tree is used instead of linkedlist for each bucket. To keep it simple we will use pre java 8 complexity
Let's divide our program into sections first and find the complexities
LineUsage addObservation - O(n) worst case
LineUsage findMaxUsage - O(n) as it iterates all the entries in the map.
LineReport loadData - O(n^2)
N line numbers and O(N) entries on each list
LineReport generateReport - O(n^2)
N line number and O(N) to find Maximum usage
--------
Commands
--------

hp@LAPTOP-MG1NG3D3 MINGW64 /d/cs310
$ dir
classes memo.txt src
hp@LAPTOP-MG1NG3D3 MINGW64 /d/cs310
$ cd src/
hp@LAPTOP-MG1NG3D3 MINGW64 /d/cs310/src ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here