Wednesday, May 6, 2020

Logmanagement Java Program Documentation

Questions: 1. Populate the objects with the data read form the specified log file. 2. Manipulate these classes to generate custom reports. 3. Provide text based menu for the program for user interactivity. Answers: Logmanagement Java Program documentation The program is designed to achieve the following tasks. Populate the objects with the data read form the specified log file. Manipulate these classes to generate custom reports. Provide text based menu for the program for user interactivity. The whole program is composed of the following classes Main LogEntry Event PolicyEvent InventoryEvent SoftwareUpdates We use a generalization concept to implement the Event class. That is the classes, PolicyEvent, InventoryEvent, SoftwareUpdates are extended or inherited from the abstract class Event. Event consists of two abstract methods. getEventName() getEventStatus() The getEventName() method is overridden by its subclasses to return their respective event names. getEventStatus() method is used to return the individual status of the event subclasses. Here we use the concept of polymorphism. Now let us examine how the program works. The Main class is the class that contains the main() function. Executions start here. It first reads user input using a BufferedReader class for reading the log file. If the user typed the wrong file name then it asks again for the right file name. Once the correct log file name is specified the program displays a menu containing two options. Menu is constructed using a do-while loop. Just before the menu appears, the program reads the logfile line by line. Each line split to words. These are stored on the objects of LogEntry class and Event class. LogEntry class consists of the following members Time as string Machine Name as String Event as the Event class. The first two parts of the line of the logfile is stored in the Time, Machine Name respectively. The remaining parts are stored using the Event class. Event class specifies the generalization of the each event. There are two data structures are used to hold the collection of the LogEntry class. ArrayList HashMap HashMap is used to hold the collection of the LogEntrys using a key. One specialty of the HashMap is it does not allow the duplicate keys. We can use this facility to uniquely display the machine names. The printMachines() method in the main class makes use of this HashMap. Since HashMap not containing the whole log data, We use the ArrayList to keep them. In both cases of ArrayList and HashMap we use iterate interface to iterate through the objects. We use FileWriter and BufferedReader to write to and read from the file. These classes are handy for manipulating file I/O. We also use StringBuilder Class to manipulate strings in this program.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.