Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this part of the lab, we will write and read objects of type LicensePlate to and from a binary file First create a class
In this part of the lab, we will write and read objects of type LicensePlate to and from a binary file First create a class named LicensePlate. Remember that to be able to write objects of type LicensePlate to a binary file, the class must implement the Serializable interface This class should have two instance variables of type String: the state and the plate number. The class should have one constructor that requires two arguments, the state and the plate number. This constructor should initialize the two instance variables. This class should also override the toString method. This overridden method should return the state followed by a colon followed by the plate number, (for example CO: ABC-123). To keep the lab simple, you do not need to provide any other methods for this class. Now do the following: 1. Create a class called BinaryFileDriver. In the main method of this class, create at least three LicensePlate objects and write them to a file named "plates.data" as objects. 2. Add code that reads license plate objects from the file "plates.data" and print each object to the console window using the toString method you created in the LicensePlate class. When reading the objects, you should assume that you do not know the number of objects in the file. I recommend that you use one try block (along with appropriate catch blocks) for the code that writes the file and another try block (along with appropriate catch blocks) for the code that reads the file. This will allow you to determine if an exception is caused by file output or file input. Sample output CO: ABC-123 NC: XYZ-6789 MT: 15-5432
Step 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