Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The e the a In this lab, you're going to build on your code from the last lab. You will use the Ticket classes to
The e the a
In this lab, you're going to build on your code from the last lab. You will use the Ticket classes to create a new TicketProcessing class that reads in a sales file and generates a summary report of the sales. As you know, sometimes mistakes happen. Files get corrupted; data is saved incorrectly; programmers make mistakes. However, you don't want these types of errors to cause your program to crash. This is where handling exceptions and gracefully ending the program comes in. On the other hand, sometimes your program enters a state from which it cannot recover. What do you do when you can't find the file you're supposed to read? You can't just make up data! This is where throwing an exception is appropriate - fail fast and fail loudly. Watch the Lab05 Overview video for an introduction to exceptions, how we're using exceptions in this lab, how to write tests for exceptions, how to use the debugger, and how to use the GUI to run Gradle tasks Note: the video should say throw new InvalidDateException("Unable to parse date"); TicketProcessing TicketProcessing should have the following functionality: - Read a file with ticket sales data - Generate a report with sales statistics Look through TicketProcessing.java for the required methods and functionality. You may add helper methods, but do not change the public interface. Add whatever private instance variables you feel are necessary. Throwing Exceptions In Ticketprocessing, you will throw exceptions if the file you read has invalid data. You will verify the data before you create any Ticket objects. If the data is not valid, you will throw one of the following custom exceptions: - InvalidDateException - thrown if the date is not in dd/mm/yyyy format or if the day, month, or year has an invalid value - It should be thrown with the message "Unable to parse date" - NosuchLocationexception - thrown if the zone value is not in the range [10,20] or if the box value is not in the range [1,8] - [10,20] between 10 and 20 , including 10 and 20 - It should be thrown with the message "Box or Zone value is invalid" You will also throw the following standard exceptions: - FileNotFoundexception - if the file cannot be found or opened - this is the only checked exception - IllegalargumentException - if the event type is invalid or data is missing - It should be thrown with the message "Datafile is missing information" Do not catch an exception in the same method you threw it. You threw the exception let it go! It is up to the method that called your method to choose how to handle the exception. Handling Exceptions In App.java, you will write a short driver program that will use a TicketProcessing object to read event summary files and print the sales summaries. This is where you will have to handle (catch) the exceptions thrown by TicketProcessing. Look through App. j ava and see Retroact ive.md for specific details. Task 1 - Examine Provided Code As always, the first thing you should do is read README.md. Then look through the other files so you understand what you have to work with and what your goals for this lab are. Task 2 - Implement Remaining TicketProcessor Tests In TicketprocessorTest.java, you will find several tests implemented and several test method stubs. Use the already implemented tests to help you implement the rest of the tests. Note the number and type of tests that you're writing. How many exceptions do you test? What kind of files do you test? Which methods do you test? Why are some tests replicated with varying data? You should be beginning to get a sense of what should be tested when you write tests for your code. In the javadocs at the top of the file, list all of the test cases that are tested in the tester file. A couple are given to you as examples. Task 3 - Implement First Draft of TicketProcessor Implement the methods in TicketProcessor.java. The input file should have the following format: ... There are several sample text files, both valid and invalid, in the app/ folder. There are several sample text files, both valid and invalid, in the app/ folder. To parse the date, you can use String.split("/") to split the line into day, month, and year. Note split returns an array of Strings, so you still need to turn each String into an int Integer.parselnt(...) will do the trick. Then verify each value is in the correct range. Refer to InvalidDateException. java for valid values. To create Ticket objects, recall that zones have values [10, 20] and box numbers are in the range [1,8]. You will have to figure out which type of Ticket object to construct based on if it has a zone or a box number. For your first pass at implementation, only throw the checked exceptions (the ones that the compiler will enforce that you catch or declare your method throws). Task 4 - Add Unchecked Exceptions Implement InvalidDateException.java. Use NoSuchLocationException.java as a model. Then, after you get your code working for valid input files, implement throwing the exceptions in Ticketprocessing. java so that your program throws the unchecked exceptions when it encounters any issue in the input files. Task 5 - Write Main Method Implement the main method as instructed in the comments. You will create a TicketProcessing object, and print the summary statistics. Your main method should gracefully handle all exceptions and print a custom message stating what exception was caught and what caused the exception to be thrown. Your main method should not crash! You also should not print any stack traces (so don't just print the exception). Task 6 - Complete the Retrospective Once you have completed all the tasks open the file Retrospective.md and complete each section that contains a TODO comment. Don't forget to answer all of the Lab Questions. EADME.md 1 Lab 5: Ticket Processing (part 2) \#\# Learning objectives - Apply inheritance and polymorphism - Write exception safe code - Understand the difference between checked and unchecked exceptions. - Apply using the try/catch keywords - Explore different approaches to handling exceptions in an application \#\# Overview This project contains the following source files: - App.java - Driver class; uses TicketProcessing to read a ticket data file and print a summary of the file. It should gracefully handle all exceptions raised [read: shouldn't crash] - Ticketinterface.java - Interface defining methods all tickets should have - Basicticket.java - Abstract class implementing methods that will be the same for all tickets - VIPTicket.java - Child class of BasicTicket. Represents a box seat ticket. You should copy your file from the last lab and overwrite this file. - FloorTicket.java - Child class of BasicTicket. Represents a ticket for a specific zone. You should copy your file from the last lab and overwrite this file. - TicketProcessing.java - Class for reading and storing information from a ticket sales summary file. You need to implement several methods in this class and add exception handling and the following test files: i) README.md J InvalidDateException.java 1 J InvalidDateException.java >{} lesson uchLocationException.java 1 SuchLocationException.java >{} lesson cetProcessing.java >{} lesson TicketProcessing.java 1 J TicketProcessing.java > \& TicketProcessing > getRevenue(Event) 3 sers > PC > Downloads > Comp lab winrar > lab05 > app >src> test > java > lesson >J TicketProcessingTest.java >{} less J TicketProcessingTest.java 2 C > Users > PC > Downloads > Comp lab winrar > lab05 >app > src > test > java > lesson > J TicketProcessingTest.java > \& TicketProcessingTest > ocessingTest.java 1 ocessingTest.java 1 rocessingTest.java 1 cessingTest.java 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started