The SearchDriver simply takes in the ID of a vehicle (from theuser input) and displays it’s information. The brand of vehicles isgrouped by ID ranges (inclusive), as follows:
Instructions
Joe has decided to take 10% off the price of all Toyotavehicles. Follow the steps below to adjust the price usingcomposition.
Create a Toyota class and place it in thecom.sait.itsc315.problemdomain package. The class will:
Change the class declaration for Vehicle and Toyota so theycannot be inherited by another class.
Add methods with the same definitions that are in the Vehicleclass to the Toyota class.
Modify the SearchDriver so it checks the ID and creates a Toyotaobject instead.
Notes
Submission
Answer the following questions.
What changes did you make to the Vehicle class?
Copy and paste the class header for the Toyota class.i.e.: public class Example {
Copy and paste the getPrice method you implemented in the Toyotaclass.
What modifications did you make to the SearchDriver?
What advantage(s) does composition have over inheritance? Shouldcomposition always be used instead of inheritance?
Include the outputs after doing a search for IDs 231 and470.
Immutability
Instructions
Examine and run the supplied ModifyDriver, then run theSearchDriver to find the modified vehicle with ID 150.
Perform the same steps you did in lab 2 to make the Vehicleclass immutable.Note: Rather than remove the setter methods, have them throw theUnsupportedOperationException to indicate the method isn’timplemented.
Verify that ModifyDriver no longer works by deletingres/vehicles.bin, running it again, and use SearchDriver to verifyvehicle #150 isn’t modified.
Notes
Submission
Answer the following questions.
What changes were made to make Vehicle immutable?
Is the VehicleManagementSystem class immutable? If not, whatchanges need to be made to make it immutable?
Cloning
The EvilAddDriver and AddDriver both add vehicles to Joe’sdatabase, in different ways.
Instructions
Examine and run the supplied EvilAddDriver to add a vehicle tothe database.
Examine and run the supplied GoodAddDriver to add anothervehicle to the database.
Use the supplied SearchDriver to find the added vehicles in thedatabase.
Modify the VehicleManagementSystem so the EvilAddDriver doesn’tadd the vehicle, and the GoodAddDriver still works.
Notes
Submission
Answer the following questions.
How is the EvilAddDriver able to add a vehicle? Why is itconsidered “evil”?
What changes did you make to the VehicleManagementSystem torender the EvilAddDriver useless?
What is the difference between a shallow and deep copy? Did youuse one of these and if so, which one?
How could the addVehicle method in VehicleManagementSystem beimproved?
Anti-Patterns
Research and find another anti-pattern (besides Singleton) thatyou have used in another course at SAIT. The anti-pattern does nothave to be related to programming.
What is the anti-pattern?
Which course did you encounter this anti-pattern?
How will you avoid this anti-pattern in the future?
The SearchDriver simply takes in the ID of a vehicle (from the user input) and displays it’s information. The brand of v
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am