CSIT121 Assignment2-Inheritance and Polymorphism Solved

35.00 $

Category:

Description

5/5 - (3 votes)

This assignment aims to provide you with some experience in writing codes using Java programming language that covers the following topics:

  • Inheritance and Polymorphism
  • Object Interactions
 

Remember that:

1.         All programs should be able to run on the lab’s computers.

2.         You must put the following information on the header of each text and source file you will be submitting in this assignment: 

     Student’s full name:  

     Student’s ID:  

     Modification Date: 

     Purpose of this file (or program):  

3.         Assignments that are not able to be compiled will result in zero mark given to the assignment.

4.         You must only use the Java features that have already been covered in the lectures

 

 

Question:

 

A resort near Pangkor Island offers rental items to their customers at a price. The customer may rent a number of rental items which can include a boat, a bicycle, or a jet ski. You are required to write a Java application that keeps track of the items rented by each customer and also able to calculate the total rental amount due.

 

To implement this, you need to declare several classes. The classes includes the RentalItem class which is inherited by the Boat class, the Bicycle class, and the JetSki class. A Customer class is also required to keep track of the customers renting the items. Lastly, you also need another class called Rental that will relate the Customer object with a number of RentalItem object.

 

The classes are partially described in the following diagrams:

The RentalItem class and its subclasses.

 

abstract RentalItem
+ RentalItem()

+ RentalItem(int,double,int)

+ calculateRental() : double

//necessary get and set methods

 

Include the necessary accessors and mutators to the classes. The calculateRental() method should perform different calculation to get the rental amount for each object. The calculation is as follows:

 

 

Boat Rental is calculated based on capacity. A boat for 10 passengers and more is charged with the rate per day plus additional charges of RM50 and a boat for less than 10 passengers has no additional charges.

 

Bicycle A mountain bike has additional charges of RM10 than the normal rate per day.

A kids bike is given half the price of the normal rate per day. Other bikes are charged at the normal rate.

 

JetSki A jet ski with 250 horse power or below has no additional charge. Others will be charged at 1.5 of the normal rate.

 

 

The Customer class.

 

–  name : String

–  contactNo : String

+ Customer(String,String)

//necessary get and set methods

 

The Rental Class

 

 

–  id : int

–  customer : Customer

–  rentalItems : ArrayList<RentalItem>

+ Rental()

+ setCustomer() : void

+ addRentalItem(RentalItem) : void

+ removeRentalItem() : void

+ calculateTotalRental() : double

 

 

 

The Rental class will include the object of class Customer and an ArrayList of RentalItem objects.

 

The rentalItems ArrayList should be declared as RentalItem type so that it can store any number of objects from different subclasses of RentalItem class (either Boat, Bicycle, or JetSki). Each customer can rent as many of these items as they wish.

 

The addRentalItem(RentalItem) method should receive a RentalItem object and add it to the ArrayList. The calculateTotalRental() method should add the rental amount from each rental items and return the value.

 

 

Lastly, write a main() method that keeps several Rental objects. Use suitable menu driven application to allow the user to add customer, add rental items, remove rental items, display all rental details and total rental charges, and display a single rental details and its total charges.

 

You are required to ensure that all errors are handled properly. Use exception handling technique and/or condition validation as necessary. Include meaningful comments in your programs and make your programs readable. Be creative in displaying your outputs.

 

 

 

 

 

 

  • CSIT121_Assignment2-8r8wsy.zip