$24
In this assignment we will expand on your Java programming skills by implementing multiple classes with different features.
You will rely on Java’s library for certain tasks and design each class to maximum reusability with fewer lines of code.
Note: please do your own work, sharing and/or copying code and/or solution ideas with/from others will result in a grade of 0 and disciplinary actions for all involved parties. If you run into any problems and have done your best to solve them, please see me before/after class or e-mail me.
Problem Description:
Implement the classes shown in the class diagram below ( Figure 1). Please adhere to the names shown in the diagram. The classes are self-explanatory; however, note the following:
Class LogEntry :
Non-default constructor: throws an IllegalArgumentException if one of the following is true:
Id is not a valid numeric string. Numeric strings are strings consisting of numbers ONLY.
timestamp, source, destination, protocol, length, description: cannot be empty or null
toString: this method returns a comma-delimited string of all the class’ variables. i.e. the values of
id, timestamp, source, destination, protocol, length, description
Class NetworkLogManager :
loadFile: reads records from the provided text file (Network.log). Refer to the section below for the file’s structure. Valid records should be added to listLogEntries. This method should handle Exceptions from the class LogEntry by printing the message Skipping line: followed by the skipped line. There are 147 invalid records (see Figure 2).
Hints:
Use Scanner class to read the input file’s lines. This is similar to reading from the standard command prompt.
Use the String class’ split method to parse each line.
toString: this method returns the string shown next. Replace ?? with the number of entries in listLogEntries.
NetworkLogManager: there are ?? records
searchByRange: returns a list of records between the provided dates (inclusive). You will need to convert the String parameters to type Date in order to perform the search. To do this, use the SimpleDateFormat class with pattern "MMM dd yyy HH:mm:ss".
searchBy: the remaining 7 required methods allow searching by a specific field. It is inefficient to implement each one independently, therefore you should create a private common method which contains the search logic. This method should select the proper field. One way to do this is to create an internal enumerator and use a switch structure.
Class A3Driver :
This is the provided test class. Your code should work with this class AS IS. Please DO NOT modify this class and adhere to the names provided in the class diagram (Figure 1)
Your code’s output should match the output shown in Figure 3.
Input file’s format:
The file contains 501 comma‐delimited rows.
Each row consists of 7 columns (id, timestamp, source, destination, protocol, length, description).
Some columns contain invalid values. Valid rows have ID and LENGTH that is NOT 0. All columns should have values (i.e. cannot be empty). If either column contains an invalid value, the entire column is rejected. There are 74 invalid rows (Figure 2).
Grades:
Item
Points
Class LogEntry
Constructor
10
Getters/setters
5
Class NetworkLogManager
Constructor
5
loadFile
10
toString
5
searchByRange
15
7 searchBy methods
20
Common method for 7 searchBy methods
20
Correct output
10
100
LogEntry
id
timestamp
source
destination
protocol
length
description
LogEntry(String,String,String,String,String,String,String)
toString() : String
getId() : String
getTimestamp() : String
getSource() : String
getDestination() : String
getProtocol() : String
getLength() : String
getDescription() : String
NetworkLogManager
listLogEntries : ArrayList<LogEntry
NetworkLogManager()
loadFile(String) : Boolean
toString() : String
searchById(String) : LogEntry
searchByRange(String) : LogEntry
searchBySource(String) : LogEntry
searchByDestination(String) : LogEntry
searchByProtocol(String) : LogEntry
searchByLength(String) : LogEntry
searchByDescription(String) : LogEntry
Figure 1: Class diagram.
Skipping line: #,Time Stamp,Source,Destination,Protocol,Length,Description
Skipping line: ,Oct 13 2019 05:09:42,192.168.5.138,192.229.189.15,‐,491,communication with play.google.com
Skipping line: ,Mar 01 2019 07:46:18,192.168.5.102,.55.163.53,TCP,174,TCP communication with microsoft.com
Skipping line: 6,Oct 11 2019 12:14:45,192.168.5.134,17.172.224.47,TCP,0,TCP communication with 192.168.5.148
Skipping line: 7,Jan 14 2019 08:47:45,192.168.5.233,135.195.175,TCP,0,TCP communication with netflix.com
Skipping line: ,Oct 12 2019 10:29:46,192.168.5.140,g208.82.237.226,TCP,1049,TCP communication with 192.168.5.148
Skipping line: 11,Feb 03 2018 01:02:52,192.168.5.216,192.168.1.1,‐,1269,communication with ebay.com
Skipping line: 12,Mar 09 2018 23:40:30,192.168.5.242,31.13.66.35,‐,0,communication with linkedin.com
Skipping line: 13,Oct 01 2019 04:43:08,192.168.5.210,172.217.11.14,TCP,0,TCP communication with espn.com
Skipping line: 15,Jan 06 2019 01:08:28,192.168.5.244,161.170.232.170,TCP,0,TCP communication with ebay.com
Skipping line: 18,Feb 11 2019 18:27:30,192.168.5.114,161.170.232.170,TCP,0,TCP communication with pinterest.com
Skipping line: 19,Jul 16 2018 00:57:45,192.168.5.203,a.org208.80.154.224,‐,424,communication with reddit.com
………………………………………………………
Figure 2: first 12 skipped Records
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
NetworkLogManager: there are 354 records
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Record with id 1: null
Record with id 9: 9,Sep 13 2018 22:50:35,192.168.5.151,101.193.67,TCP,197,TCP communication with amazon.com
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
There are 146 entries from 2018
Figure 3: output of test class
The City College of New York
Department of Compute Science
CSc 221: Software Design Laboratory