Question: Lab 7 Objects and Classes, Inheritance, Abstract Classes **Note that the Autograder can't grade every aspect of these programs. A portion of your grade will

 Lab 7 Objects and Classes, Inheritance, Abstract Classes **Note that the Autograder can't grade every aspect of these programs. A portion of your grade will be calculated when the instructor has reviewed your code.** ## Problem 1: HVAC, Service Calls, Inheritance This is a prototype of a program for managing calls to a Heating, Ventilation and Air Conditioning repair/servicing company. Customers will call to set up servicing of their furnaces, air conditioning etc. units. This program keeps a list of pending calls, and allows the operator to add new calls, and store resolutions of calls that have been done. Run the program, and review the code. There are a couple of new things: * HVACInput.java uses a TreeMap; which behaves like a HashMap but keeps the keys in sorted order. * An **enum** in the Furnace class. An enum is a collection of named constants; useful if you know a variable can only have one of a defined number of values - like types of furnace. Please make these changes to the program: a. Create a new class called WaterHeater. This represents a service call for a  water heater. A water heater service call needs to have these variables: an **address**, **date service requested**, **description of the problem**, and the **age** of the water heater. The age variable should be an integer. Resolved service calls for WaterHeater objects also need the **resolved date**, **description of the resolution**, and the **fee** charged to the customer. Note that many of these variables are already declared in ServiceCall, and a WaterHeater is a type of ServiceCall. So make WaterHeater should be a subclass of ServiceCall, and it will have the same variables that ServiceCall does. You'll need to add the WaterHeater-specific variables. b. The city that this HVAC company operates in, requires that all service calls to water heaters have a mandatory $20 extra charge added. As this applies to all water heaters, add a private static variable called **cityFee** to your class to store this data. This should be a double. c. Override that **toString** method in WaterHeater which returns a String containing all the static and instance variables for a WaterHeater. You should break down the fee into the service charge plus the $20 mandatory city fee. d. Create a constructor to set the following variables, in this order: address, description of the problem, date reported, and the age of the water heater. e. Add code to ServiceCallManager.java to test your new class. Make sure you can add service calls for water heaters to the list of today's ServiceCalls. Note that the tests only check for the correct behavior of the WaterHeater object, and do not check any of the code you'll add to ServiceCallManager. This will be human-graded. ## Question 2 Support Ticket Manager This program is a prototype to manage IT support tickets for a company. Users would call or email a helpdesk to report computer problems, and this program keeps a record of all current problems. Tickets need to store a description of the problem, the date the issue was reported, and the user who reported it. The tickets are assigned a priority between 1-5. 1 is the most urgent (e.g. all servers down) 5 is the least serious (e.g. missing mouse mat). Each ticket will have a unique integer ID. This is generated internally in the `Ticket` class. (We'll improve on this approach later in the semester when we cover databases.) When a problem is fixed, the ticket is removed from the list of open tickets and added to a separate list of resolved tickets. A String describing the resolution is stored in the Ticket, and the date the ticket was resolved. For this question, you'll add some features to the program. Run and test the program with some example support tickets. ### Problem 1: Review Design To think about: * What is each class for? How are different responsibilities divided between the classes? * If `TicketStore` used a database instead of an in-memory LinkedList, would `TicketUI` or `Question_3_Support_Ticket_Manager` have to do anything differently? * Make sure you understand the role of the static and instance `ticketID` and `ticketIdCounter` variables in the Ticket class. Why are a static variable, and an instance variable, declared in the class? How are these used to create ID values for each ticket? * How does Q3_Ticket_Manager access a TicketStore object? Is it possible to create more than one TicketStore object? Why do you think this is? Hint: Google the "Singleton design pattern." ### Problem 2: Validate ticket priorities Add a check to `TicketUI.getNewTicketInfo()` method, to ensure that the priority entered for a new ticket is between 1 and 5, inclusive. ### Problem 3: New menu options Add two new options to the menu: **Delete by Description**, and **Search by Description**. You'll need to add some more int constants; and modify the `configureMenuOptions` method; and modify the switch statement in `manage`. Problem 4: Implement search by description The Search By Description feature will search your ticket list and returns a new list of Tickets whose descriptions contain a certain String. For example, you might want to search for all tickets with the word "server" in the description. The search should NOT be case sensitive. Note that you should not modify the description when you save tickets. So, the approach of saving all descriptions in lowercase or uppercase is not an acceptable solution for this problem. Implement `TicketStore.searchByDescription` to search the list and return all matching tickets. If `TicketStore.searchByDescription` doesn't find any matches, return an empty list. If `TicketStore.searchByDescription` is called with an empty string, or a null string, it should return an empty list. Implement Question_2_Support_Ticket_Manager.menuOptionSearchByDescription. Use the `askUserQuestion` method in TicketUI to ask the user for the search String. Use `TicketStore.searchByDescription` to search for matching tickets Use the `displayTickets` method in TicketUI to display all matching tickets. ### Problem 5: Store information about deleted/resolved tickets In your program, when a ticket is deleted, it has been resolved in some way. Either a technician fixed the problem, or the user has figured out how to change their own screensaver, or it's become a non-issue in some other way. Modify the program so you can save information about deleted tickets. Add two new fields (variables) to the Ticket class. Another Date; `resolvedDate`, the date the ticket was closed. And, a String that documents why the ticket was closed - the fix or the resolution for the ticket. This String should be called `resolution` Problem 6: Implement delete by ID A ResolvedTicketStore class is provided for you. It stores resolved tickets in a list, and provides an `addTicket` method.  Create a ResolvedTicketStore object in Question_2_Ticket_Manager when the program starts. Note that you'll need to use the `ResolveTicketStore.getInstance()` method to access the singleton `resolvedTickets` object. Now, when you delete a Ticket, your `deleteTicketById` method should ask for the resolution. Store the resolution String, plus the current Date in the correct Ticket. Now, remove this Ticket from the ticketQueue list. Finally, add the resolved ticket to your ResolvedTicketStore. Problem 7: Implement delete by description Implement Delete by Description. As before, you'll need to ask for the resolution, save the resolution and date resolved in the Ticket, remove the ticket from the TicketStore, and add it to the ResolvedTicketStore. Follow the notes in `deleteTicketByDescription`. Problem 8: Save ticket information to file At the moment, when the program is closed, all the data is lost. Add the ability to save all data to files. You will need to save your files in a specific location, and using specific file names. But, you can decide how to organize and structure the data in your files. Use `TicketFileIO` to manage the file input and output. Question_3_Support_Ticket_Manager will use methods in this class when the program starts and ends.  Your `Question_2_Support_Ticket_Manager` should **not** do any file reading or writing. Delegate these tasks to your TicketFileIO class. Write all files to the directory given by the `ticketDataDirectory` in TicketFileIO. When the program closes, write out all the data about all open tickets to one file in the **TicketData** directory of your project. These open tickets should be saved in a file called `open_tickets.txt`. Write all data about resolved tickets to a separate file. Resolved tickets should go into one file per day. This file should have the current date in the filename. Example, if the resolved tickets are saved on February 20, 2014, the filename will be `resolved_tickets_as_of_February_20_2014.txt`. If the program is run more than once on a given day, append any more resolved tickets to the same file. For example, if the program is run on February 20, 2014, and some tickets are resolved, they should be saved to `resolved_tickets_as_of_February_20_2014.txt`. Then, if the program is run again on the same day, and more tickets are resolved, these tickets should be appended to the same `resolved_tickets_as_of_February_20_2014.txt` file. Create a static method with this name, and arguments. This method should be used for writing open tickets, and resolved tickets. ``` Write the list of tickets to the file with the name provided. The append argument specifies what to do if the file already exists. If append=true, add data to the file If append=false, create a new file for this data. */ public static void saveTickets(LinkedList ticketList, String fileName, boolean append) { // TODO implement this method } ``` Here's some code to generate today's date and time as a string in the correct format, ``` SimpleDateFormat filenameFormatter = new SimpleDateFormat("MMMM_dd_yyyy_hh"); Date date = new Date(); //defaults to today, right now String s = filenameFormatter.format(date); // s will be in the format "September_28_2017" ``` Problem 9: Read open tickets when program starts When your program opens, it should look for a file called `TicketData/open_tickets.txt`. If this file exists, read in this file, and create Ticket objects, and store these in the TicketStore object list so the user can see all open tickets. Use a static method with this name and arguments. ``` Read a file, turn the data into Ticket objects, and return a list of Ticket objects */ public static LinkedList loadTickets(String fileName) { // TODO implement this method and return a LinkedList of Tickets from the file of the given name } ``` You don't need to read in the previous resolved tickets, you only need to read the open tickets from the `open_tickets.txt` file. The ResolveTicketStore object will have an empty list when the program starts. What happens to ticket IDs when the program is closed and opened? Make sure they don't reset to 1 when the user restarts the program. Every ticket created should always have a unique positive integer ID, (excluding 0) no matter how many times the program is used. If you save the ticket ID in a file, make sure it's also in the the **TicketData** directory. The tests will create a separate test directory and will read and write to this location, so if you keep all of your files in **TicketData** then the tests won't overwrite your files. You will need to create a second constructor for creating a tickets when the ID is already known. Make sure you don't break your mechanism for ensuring unique IDs. *Actually, you'll only be able to create approx 2 billion ticket IDs with this approach. That should be enough for now, although perhaps something that will be revisited in a future version using a relational database. 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!