Reference no: EM133389668
Part 1: demonstrate inheritance of classes
You are creating a system for the traffic portion of a police department in a new source package named traffic. It will one day be placed in new handheld computers so the officers on traffic duty can print these tickets from handheld computers. Java is a perfect language to make this kind of application as we learned earlier in the course. There are several types of Ticket though so this is a perfect one to demonstrate inheritance with.
Every Ticket has a Tag (license plate number), Make, Model, and Color.
Each Ticket also has a special version.....these are the inheriting classes....
A TimeExpiredTicket is a Ticket for a car parked too long in a timed zone or when a parking meter has no time left and shows the expired flag while the car is there. This type of ticket has a $50 charge.
A HandicappedTicket is a Ticket for a car parked in a handicapped zone with no handicapped permit on it. This type of ticket has a $100 charge.
A FireLaneTicket is a Ticket for a car parked in fire lane or beside a fire hydrant. This type of ticket has a $150 charge.
Make the ticket super class, and the three subclasses inheriting from it. Then write a class with main() to test your new classes by making at least one object of each of the three types of tickets (expired, handicapped, and fire lane) and later report their information stored in them to the user.
Note: You can put the charge in the a message being printed or as a variable holding the value. It's up to you. You do have to have the tag, make, model, and color along with their gets and sets only in the ticket superclass. You have to demonstrate inheritance here by inheriting from the base class which is holding these values.
Part2: demonstrate Polymorphism of Classes
Make a copy of the part 1 to a new source package named abstarcttraffic and make the following changes:
Your system is going to have to have an array of the different tickets. They are going to be printed and processed in order. This means you have to use polymorphism to do because they are different types of tickets.
Make sure Ticket is now abstract. There are no general tickets. They must all be of one of the subclass types.
Make an abstract method called printTicket() in the base Ticket class.
Make a method called printTicket() in each of the subclasses that prints out the tag, make, model, color, and charge information along with a message for what kind of ticket it is.
In the class testing the classes you created....make an array of tickets including at least one of the three types of tickets (expired, handicapped, and fire lane). Then use a loop to process the whole array and call printTicket() to polymorphically print them all out.
Part 3: Polymorphism of Interfaces
Copy the Account class from your completed assignment 2 to a new source package named accounts.
Create class in the same package accounts with name CarLoan. Carloan class should have a name of type String, amount owed of type double, a rate of type double, and a monthly payment of type double.
Create Interface called iMailable to print the monthly statements for all Accounts and all Carloans in the same print run. It should have one method in it called printStatement()
Demonstrate polymorphism with interfaces by having both Account and Carloan implement iMailable and add code to each to have the printStatement() that prints out their data.
Finally, create class named Bank with only a main method to print statements of an array of iMailables. In the main method, define an array of at least 2 iMailable and have at least one Account and at least one CarLoan in it, and use a loop to call printStatement() to show all the statements of the customers accounts and car loans in this array of the interface.