Cs4001 programming - create a class to represent a car at a


Aim

The aim of this assignment is to create a class to represent a car at a local car dealership, together with two subclasses to represent a car to buy and a car to rent respectively. You will also need to write a report about your program. You are advised to study the learning aid on reflective practice, which is linked from the module in WebLearn. Your report should be no more than 1200 words in length (excluding the table of contents, class diagram and code listing).

Program

The program should consist of the following classes (with no additional attributes or methods).

1) The Car class has two attributes, which correspond to the description and the customer's name. The description and the customer's name are each represented as a string of text. The description is initialised in the constructor, by being assigned the value of the constructor's only parameter. The customer's name is assigned an empty string ("").

Each attribute has a corresponding accessor method and there is another method to set the customer's name to a new name. A display method will output (suitably annotated) the description and, if the customer's name is not an empty string, the customer's name too.

2) The CarToBuy class is a subclass of the Car class and it has four attributes:

price a whole number
registration year a whole number
mileage a whole number
sold true or false

The constructor accepts four parameters, which are the description, the price, the registration year and the mileage. A call is made to the superclass constructor with one parameter, the description. The price, registration year and mileage attributes are given the corresponding parameter values. Additionally, the constructor initialises sold to false.

Each attribute has a corresponding accessor method.

A method is required to set the price as changes to the price inevitably occur. The method accepts a new price as a parameter and, if the car already been sold, a suitable message is output to the user indicating that it is therefore not possible to change the price. Otherwise, the new value is assigned to the price attribute.

There is a method for buying the car. The method has one parameter, the customer's name and, if the car already been sold, a suitable message is output to the user indicating that it is therefore not possible to sell it. Otherwise, the method to set the customer's name is called with the customer's name as a parameter and sold is set to true.

A method to display the details of the car is required. It must have the same signature as the display method in the Car class. It will call the method in Car class to display the description and, if applicable, the customer name. If the car has not been sold then the price, registration year and mileage must also be displayed. Each output must be suitably annotated.

3) The CarToRent class is also a subclass of the Car class and has seven attributes:

rental date a string of text
return date a string of text
admin fee a whole number 
number of days a whole number 
daily rate a whole number 
total accumulated a whole number 
on loan either true or false

Whenever the car is rented, the amount that the customer pays is calculated by multiplying the daily rate by the number of days and then adding the admin fee. The total accumulated represents the total amount paid by all customers to date.

The constructor accepts three parameters, which are the description, the admin fee and the daily rate. A call is made to the superclass constructor with one parameter, the description. The admin fee and daily rate attributes are assigned the corresponding parameter values and the rental date and return date are each

initialised to an empty string. Also in the constructor, the number of days and the total accumulated are each initialised to 0 and the attribute indicating whether the car is on loan is initialised to false.

Each attribute has a corresponding accessor method.

A method is required to set the daily rate as changes to the rate inevitably occur. The method accepts a new daily rate as a parameter and assigns that value to the daily rate attribute.

A method is required to set the admin fee as changes to that also occur. The method accepts a new admin fee as a parameter and assigns that value to the admin fee attribute.

There should be a method to rent the car. The method accepts, as parameters, the customer's name, the rental date, the return date and the number of days the car is required. If the car is already on loan, an appropriate error message including the return date is output to the customer. Otherwise, the rental date, the return date and the number of days are all updated by the input parameter values, the method to set the customer's name is called with the customer's name as a parameter, the attribute indicating whether the car is on loan is changed to true and the amount paid by the customer is added to the total accumulated.

There should be a method for returning the car to the rental company. If the car is on loan, the method to set the customer's name is called with an empty string as a parameter, the number of days is set to 0, the date of hire and the date of return are each set to empty strings and the loan status is set to false. Otherwise, a suitable error message is output.

There should be a method to print the description of the car together with its total accumulated, suitably annotated. (To access the description, the method to get the description must be called.)

A method to display the details of the car is required. It must have the same signature as the display method in the Car class. It will call the method in Car class to display the description and, if applicable, the customer's name. The method should then display the admin fee and the daily rate. If the car is on loan then the rental date, the return date and the number of days should also be displayed. Each output must be suitably annotated.

Report

A class diagram showing the inheritance relationship between the three classes and, for each class, the name of the class, the data types and names of the fields and the return types and signatures of the methods

A short description of what each method does

You should give evidence (through appropriate screenshots) of the following testing that you carried out on your program:

Test 1: Inspect a car to buy, buy the car, re-inspect the car to buy

Test 2: Display all the details of a car to buy

Test 3: Inspect a car to rent, rent the car, re-inspect the car to rent

Test 4: Display the description and total accumulated, before and after renting the car

Test 5: Display all the details of a car to rent

Test 6: Inspect a car to rent, return the car, re-inspect the car to rent

The report should contain a section on error detection and error correction where you give examples and evidence of three errors encountered in your implementation. The errors (syntax and/or runtime) should be distinctive and not of the same type.

The report should contain a conclusion, where you evaluate your work, reflecting on what you learnt from the assignment. You are advised to study the learning aid on reflective practice, which is linked from the module in WebLearn.

The report should include a title page (including your name and ID number), a table of contents (with page numbers), and a listing of the code (in an appendix). Marks will also be awarded for the quality of writing and the presentation of the report.

Solution Preview :

Prepared by a verified Expert
Dissertation: Cs4001 programming - create a class to represent a car at a
Reference No:- TGS02549971

Now Priced at $35 (50% Discount)

Recommended (99%)

Rated (4.3/5)