Pertaining to Question one, I am unable to solve the program.
I have attached the assignment questions into the file section.
Please take note of the following typo errors in the questionaire:
1. The late penalty stated in Table 1 should be 20%.
2. Remove the duplicate methods in the Truck and Car Class UML diagram in Figure 1.
3. Page 5, (b) second bullet, remove the following: ” (by default, set number of child seats to 0 for car and set the driver to false for truck when the object is created). “
Please help me! I will need to submit the documents before Monday.
ICT201
Further Programming and Object-Oriented
Concepts Using Java
Tutor-Marked Assignment
January 2018 Presentation
Copyright © 2017 SIM University
ICT201
Tutor-Marked Assignment
TUTOR-MARKED ASSIGNMENT
This tutor-marked assignment is worth 21% of the final mark for ICT201 – Further Programming
and Object-Oriented Concepts Using Java.
The cut-off date for this assignment is Monday, 16 April 2018, 2355 hours.
Submit your solution document in the form of a single MS Word file, clearly headed with
your name and your personal identifier, on or before the cut-off date shown above. You
should make only one submission for a TMA.
Marks will be allocated for tidiness so that your tutor will have minimum difficulties in
assessing your answers. In particular, take note that program code should follow proper code
convention in layout and format. This includes:
(a) The use of meaningful and appropriate variable names
(b) Proper indentation of program lines
(c) Differentiation between uppercase and lowercase especially in variable names
(d) Suitable but not excessive comments, if necessary
SIM UNIVERSITY
Tutor-Marked Assignment – Page 2 of
19
ICT201
Tutor-Marked Assignment
Question 1 [ 60 marks ]
The objectives of this question are
(a)
to introduce subclasses in a case study
(b)
to apply the various OOP concepts
Reliance Rental, a vehicle rental company on our island country state, has engaged you to
develop a computerised vehicle rental system to streamline its rental process. Its management
has requested for a simple prototype for a vehicle rental system to be developed for a start.
The company has a fleet of cars and trucks for rental. These are the business rules:
– Only walk-in rental is allowed. No pre-bookings.
– A customer may choose to rent a vehicle with the option of having a driver.
– Maximum rental is 5 days, after which a 20% penalty is imposed per day for both the
vehicle and driver across all vehicle types.
The current charges is listed in Table 1.
Vehicle Rate
Car
Truck
Driver
Late Penalty
after 5 days
Rate is $100 per day.
$100 per day.
10% per day
Smaller capacity cars 1600cc and Higher capacity cars 2000cc and for each day
below 10% discount.
above 10% more.
late
Car older than 10 years, another
(including
10% discount (of the base rate).
the driver)
Classification 2, $100 per day
Classification 2, $100 per day for
Classification 3, 10% more per day Classification 3, 10% more.
Table 1 Rental Charges
Truck
Car
A selection of the fleet of vehicles is listed in Table 2.
Registration No
SJV1883R
SJZ2987A
SKA4370H
SKD8024M
GB3221K
GB8283M
GBA113X
YX123Z
Make
Honda
Toyota
Honda
Toyota
Toyota
Isuzu
Nissan
Kia
Model
Civic
Wish
Accord
Camry
LiteAce
NPR
Cabstar
KX2500
Year Mfg
2015
2010
2016
2005
2000
2017
2010
2005
Capacity
1600
1800
2200
2000
Classification
2
3
3
2
Table 2 – Information of the vehicles
The company records the NRIC number, name and mobile number of the customers. Assume
that the customers who rent a vehicle is one of the pre registered as shown in Table 3.
NRIC
Number
S9099999A
S8958911B
S7970326C
SIM UNIVERSITY
Name
Mobile
Adrian
Benjamin
Christina
91112222
96668888
93335555
Tutor-Marked Assignment – Page 3 of 14
ICT201
Tutor-Marked Assignment
Table 3 – Existing customer data
The fragment of class diagram is given in Figure 1.
VehicleRentalSystem
+initialiseVehicles(vehicleList ArrayList) : void
+initialiseCustomers(customerList : ArrayList) : void
+displayMenu() : void
+listCustomers(customerList : ArrayList ) : void
+listVehicles( vehicleList : ArrayList, onlyAvailable : boolean ) : void
+rentVehicle(customerList : ArrayList , vehicleList ArrayList , rentalList : ArrayList ) : void
+eturnVehicle(customerList :ArrayList , rentalList : ArrayList ) :void
+searchCustomer(customerList : ArrayList , nric : String):Customer
+searchVehicle(vehicleList : ArrayList, vehNo:String) : Vehicle
+displayCustomerRentalDetail( customerList : ArrayList, rentalList : ArrayList ):void
+displayAllRentalRecords(rentalList : ArrayList ) : void
Vehicle
– regNo : String
– make : String
– model : String
– yearMfg : int
– isAvailable : boolean
#latePenalty : double
Rental
-counter : int
-rentalNo : int
-customer :Customer
-vehicle : Vehicle
-pickUpDate : LocalDate
-returnDate : LocalDate
-hasDriver : boolean
-double totalCharge;
+Vehicle(regNo: String, make:String, model:String)
+getRegNo() : String
+getMake() : String
+getModel() : String
+getYearMfg() : int
+getAvailability() : boolean
+setAvailability(avail : boolean) : void
+getLatePenality() : double
+toString() : String
+getDailyRate() : double
+getDriverRate() : double
+calculateCharges(days:int, driver:boolean) : double
+Rental(veh : Vehicle, cust : Customer,
puDate : LocalDate, needDriver :
boolean)
+getRentalNo() : int
+getCustomer() : Customer
+getVehicle() : Vehicle
+getPickUpDate() : LocalDate
+setPickUpDate(date : LocalDate) : void
+setReturnDate(date : LocalDate) : void
+getReturnDate() : LocalDate
+getHasDriver() : boolean
+getTotalCharge() :double
+calculateRental():double
Customer
-nricNo : String
-name:String
-mobile:String
+Customer(nric:String, name:String, mobile:String)
+getNricNo() : String
+getName() : String
+getMobileNo() : String
+toString() : String
Car
Truck
-driverPerDay : double
-ratePerDay : double
-classification : int
-driverPerDay : double
-ratePerDay : double
-capacity : int
+Truck(regNo: String, make:String, model:String, classification: int)
+getDailyRate() : double
+getDriverRate() : double
+getDailyRate() : double
+getDriverRate() : double
+toString() : String
+calculateCharges(days:int, driver:boolean) : double
+Car(regNo: String, make:String, model:String, capacity: int)
+getDailyRate() : double
+getDriverRate() : double
+getDailyRate() : double
+getDriverRate() : double
+toString():String
+calculateCharges(days:int, driver:boolean) : double
Figure 1. Class diagram for the Car Rental System
The description of the classes for the system are as follows:
Class Vehicle:
This class models the vehicles in the company. Every vehicle has a unique registration
number (String), make (String), model (string), and whether it is available (boolean). The
late penalty of 20% is stored as a static field in this class. There are 3 abstract methods in
this class:
–
public abstract double getDailyRate()
public abstract double getDriverRate()
public abstract double calculateCharges( days, withDriver )
Class Car:
This class is a subclass of Vehicle. It models the cars in the company. On top of the
attributes that inherits from the super class, it has an integer value to record capacity of the
car. It has static values for the daily rate and driver rate.
Class Truck:
This class is a subclass of Vehicle. It models the trucks in the company. On top of the
attributes that inherits from the super class, it has an integer value that classifies the type of
truck. It has static values for the daily rate and driver rate.
Class Rental:
SIM UNIVERSITY
Tutor-Marked Assignment – Page 4 of 14
ICT201
Tutor-Marked Assignment
This class models the rentals of vehicle in the company. Every rental has a rental number
generated by the system in the running sequence, the first rental number is 1. It also records
the information of the customer (Customer) who rents the vehicle, the vehicle (Vehicle)
that it is rented for, pick-up date (LocalDate), return date (LocalDate), totalCharges(double)
and whether it comes with a driver(boolean). The accessor methods are listed in the UML
diagram in Figure 1. The calculateRental() method calculates the total charge according to
the charges listed in Table 1.
Class Customer:
This class models the customers in the company. Every customer has a unique NRIC
number (String), a name (String) and mobile number (String).
(a)
Implement the Java class for Vehicle as an abstract class. You should include the
following in the class:
The instance and class variables according to the description given above.
The constructor that does all the necessary initializations (set available to true when
the vehicle is created).
The get and set methods for all the instance variables.
The toString() method that returns a string showing the values of all the
attributes with the appropriate descriptions.
The 3 abstract methods.
(10 marks)
(b)
Implement the two subclasses: Car and Truck. You should include the following in the
classes:
The instance and class variable(s) according to the description given above.
The constructor that does all the necessary initializations (by default, set number of
child seats to 0 for car and set the driver to false for truck when the object is created).
The get and set methods where required.
The toString() method that returns a string showing the values of all the
attributes with the appropriate descriptions.
The method calculateCharges() that calculates and returns the total charges
according to the rates specified in Table 1.
Implement the getDailyRate() and getDriverRate() methods.
(12 marks)
(c)
Implement the Java class for Rental. You should include the following in the class:
The instance and class variables according to the class description given above.
The constructor that will do all the necessary initializations.
The get and set methods where required.
The method calculateRental() that calculates and returns the rental charges for
the vehicle.
Implement the getDailyRate() and getDriverRate() methods.
(8 marks)
(d)
Implement the Java class for Customer. You should include the following in the class:
The instance variables according to the class description given above.
The constructor that will do all the necessary initializations.
The get and set methods where required.
The toString() method.
(4 marks)
SIM UNIVERSITY
Tutor-Marked Assignment – Page 5 of 14
ICT201
(e)
Tutor-Marked Assignment
Write a program to test your classes created in parts (a) to (d).
Copy the program template given in Appendix A. The main method has 3 separate
ArrayList, one for customers, one for vehicles and one for rentals. This is a brief
description of some of the methods in the VehicleRental Class:
listVehicles(ArrayList vehicleList, boolean
onlyAvailable)
This method displays vehicles in the vehicle list. If the onlyAvailable is true,
then only vehicles available for rental will be displayed. Otherwise, all vechicles will
be displayed.
rentVehicle(ArrayList customerList,
ArrayList vehicleList, ArrayList rentalList)
The sequence of steps for renting a vehicle is as follows:
i. Display customer list. User enters nric. If nric not found, display “Customer not
found!”. Input of Q will quit the renting process.
ii. Display available vehicle list only. User enters vehicle number. If vehicle number
not found, display “Vehicle not found!”. Input of Q will quit the renting process.
iii. Prompt whether a driver is needed.
iv. Display rental details. Create the rental only when the user enters y to confirm.
Upon confirmation, display the rental number. This is the number that will be used
to return the vehicle.
returnVehicle(ArrayList customerList,
ArrayList rentalList)
The sequence of steps for returning a vehicle is as follows:
i. Prompt for rental number.
ii. If rental number exists, display the details as shown in the sample below.
iii. If return date is more than 5 days, display the penalty.
displayAllRentalRecords(ArrayList rentalList)
This method displays 2 options to display the rental records:
1) Display open transactions.
2) Display closed transactions.
The first option displays all rental information for vehicles not returned yet. The
second option displays all completed transactions.
The other methods listed in the UML diagram are self-explainatory.
You may add any additional methods to make your program modular. A sample run is
shown in Figure 2 below:
MENU
1. Rent a vehicle
2. Return a vehicle
3. Display rental details of a customer
4. Display all rental records
0. Exit
Enter your choice: 1
S/No
NRIC No
Name
Mobile No
Display “Customer
1
S9099999A
Adrian
91112222
not found” if cannot
2
S8958911B
Benjamin
96668888
3
S7970326C
Christina
93335555
find customer
Enter NRIC of customer (Q to Quit): S9099999A
S/No
Reg No
Make
Model
Year Mfg Daily Rate ($)
1
SJV1883R
Honda
Civic
2015
90.00
2
SJZ2987A
Toyota
Wish
2010
90.00
3
SKA4370H
Honda
Accord
2016
100.00
4
SKD8024M
Toyota
Camry
2005
90.00
SIM UNIVERSITY
Tutor-Marked Assignment – Page 6 of 14
ICT201
5
GB3221K
Toyota
LiteAce
6
GB8283M
Isuzu
NPR
7
GBA113X
Nissan
Cabstar
8
YX123Z
Kia
KX2500
Enter vehicle registration number(Q
Do you need a driver (y/n): y
*** Rental Confirmation ***
Customer NRIC:
S9099999A
Customer Name:
Adrian
Customer mobile: 91112222
Vehicle No:
SJV1883R
Rate:
$90.00
Driver required: Yes
Driver rate:
$100.00
Rental Date:
05/03/2018
Maximum 5 days, otherwise a penalty
will be imposed for the late days.
Confirm rental (y/n): y
Confirmed. Rental number is: 1
Proceed to collect vehicle
Tutor-Marked Assignment
2000
90.00
2017
90.00
2010
80.00
2005
90.00
to quit): SJV1883R
Same here.
of 20% per day overall
MENU
1. Rent a vehicle
2. Return a vehicle
3. Display rental details of a customer
4. Display all rental records
0. Exit
Enter your choice: 1
S/No
NRIC No
Name
Mobile No
1
S9099999A
Adrian
91112222
2
S8958911B
Benjamin
96668888
3
S7970326C
Christina
93335555
Enter NRIC of customer (Q to Quit): S9099999A
1
SJZ2987A
Toyota
Wish
2010
90.00
2
SKA4370H
Honda
Accord
2016
100.00
3
SKD8024M
Toyota
Camry
2005
90.00
4
GB3221K
Toyota
LiteAce 2000
90.00
5
GB8283M
Isuzu
NPR
2017
90.00
6
GBA113X
Nissan
Cabstar 2010
80.00
7
YX123Z
Kia
KX2500
2005
90.00
Enter vehicle registration number(Q to quit): SKD8024M
Do you need a driver (y/n): n
*** Rental Confirmation ***
Customer NRIC:
S9099999A
Customer Name:
Adrian
Customer mobile: 91112222
Vehicle No:
SKD8024M
Rate
$90.00
Driver required: No
Rental Date:
05/03/2018
Maximum 5 days, otherwise a penalty of 20% per day overall
will be imposed for the late days.
Confirm rental (y/n): y
Confirmed. Rental number is: 2
Proceed to collect vehicle
MENU
1. Rent a vehicle
2. Return a vehicle
3. Display rental details of a customer
4. Display all rental records
0. Exit
Enter your choice: 2
Enter rental No: 1
Enter return date (DD MM YYYY): 06 03 2018
*** INVOICE ***
Customer NRIC:
S9099999A
Customer Name:
Adrian
Customer mobile: 91112222
Vehicle No:
SJV1883R
Rate
$90.00
Driver required: Yes
Driver rate:
$100.00
Pick up Date:
05/03/2018
Return Date:
06/03/2018
Number of days: 1
Total charges:
$190.00
MENU
1. Rent a vehicle
2. Return a vehicle
3. Display rental details of a customer
4. Display all rental records
SIM UNIVERSITY
Only available
vehicles are listed.
If rental number not
found, display “No
such rental no”.
If customer not
found, display “No
Tutor-Marked Assignment – Page 7 of 14
such customer”.
ICT201
0. Exit
Enter your choice: 3
Enter NRIC of customer: S9099999A
Tutor-Marked Assignment
Rental No Veh Number Pick Up Date Return Date Total Charges
1
SJV1883R
05/03/2018
06/03/2018 $190.00
2
SKD8024M
05/03/2018
Open
$0.00
Vehicles not returned yet
MENU
1. Rent a vehicle
should be displayed as
2. Return a vehicle
“open”
3. Display rental details of a customer
4. Display all rental records
0. Exit
Enter your choice: 4
2 options, 1 for not yet return, and 2
1) Display open transactions.
2) Display closed transactions.
for returned transactions.
Enter option: 1
Rental No Veh Reg No Customer Name Mobile phone
Rental Date Return Date Charges
2
SKD8024M
Adrian
91112222
05/03/2018 Open
$
0.00
MENU
1. Rent a vehicle
2. Return a vehicle
3. Display rental details of a customer
4. Display all rental records
0. Exit
Enter your choice: 4
1) Display open transactions.
2) Display closed transactions.
Enter option: 2
Rental No Veh Reg No Customer Name Mobile phone
Rental Date Return Date Charges
1
SJV1883R
Adrian
91112222
05/03/2018 06/03/2018 $ 190.00
MENU
1. Rent a vehicle
2. Return a vehicle
3. Display rental details of a customer
4. Display all rental records
0. Exit
Enter your choice: 2
Enter rental No: 2
Enter return date (DD MM YYYY): 11 03 2018
*** INVOICE ***
Customer NRIC:
S9099999A
Customer Name:
Adrian
Customer mobile: 91112222
Vehicle No:
SKD8024M
Rate
$90.00
Driver required: No
Pick up Date:
05/03/2018
Return Date:
11/03/2018
Number of days: 6
There is a penalty of 20.0%
Total charges:
$558.00
Penalty displayed if more than 5
days.
MENU
1. Rent a vehicle
2. Return a vehicle
3. Display rental details of a customer
4. Display all rental records
0. Exit
Enter your choice: 0
End
Figure 2 – sample run of the Vehicle Rental System
Submit your program listing and the screenshot of the output to convince your tutor that
your program is working. Include your student id and name at the start of your program.
A sample program template is shown in Appendix A.
(20 marks)
(f) Explain the term method overriding. Did you make use of this concept in any of the
classes? Justify your answer.
(3 marks)
SIM UNIVERSITY
Tutor-Marked Assignment – Page 8 of 14
ICT201
Tutor-Marked Assignment
(g) Explain the term polymorphism in Java. Did you make use of this concept in any of the
classes? Justify your answer.
(3 marks)
Question 2 [ 20 marks ]
The objective of this question is
(a)
to use the Java exception handling facility in a program
(b)
to define and use an exception class
(c)
to write program code that will throw user-defined exceptions
The body mass index (BMI) is a statistical measurement which compares a person’s weight
and height.
Given a person’s height in metre and weight in kilogram, the formula that calculates the BMI is
bmi
weight
height * height
Base on the BMI, the statistical category for an adult is as follows:
Category
BMI range – kg/m2
Underweight
below 18.5
Normal
from 18.5 to 23
Overweight
from 23 to 27.5
Obese
above 27.5
Write a program BMICalculator to calculate and display the BMI and its statistical category.
Write a InvalidValueException class that has a constuctor with a string message as
parameter.
Your program should prompt user for the NRIC Number, height and weight. It should
validate the user input and throw the InvalidValueException for the following:
o the NRIC entered does not start with ‘S’ or ‘T’, or it is not 9 characters long, or the
2nd to 8th character contain a non-digit, or the check digit is not valid.
o the height entered is not numeric or it is not a valid adult height (any adult should
have the height between 1.2m and 2.5m)
o the weight entered is not numeric or it is not a valid adult weight (any adult should
have the height between 30kg and 200kg)
SIM UNIVERSITY
Tutor-Marked Assignment – Page 9 of 14
ICT201
Tutor-Marked Assignment
Your program should have the following methods:
o
String validateNric(String nric)
To validate and throw InvalidValueException object with the appropriate
message if the NRIC number is invalid:
– Invalid NRIC number – must be 9 characters long
– Invalid NRIC number – must begin with either ‘S’ or ‘T’
– Invalid NRIC number – 2nd to 8th character must be digit ‘0’ to ‘9’
– Invalid NRIC number – wrong check digit
Otherwise return the NRIC entered.
[ You may use the method validateCheckDigit(String nric) given in
Appendix B to validate the check digit ]
o double validateHeight(String aHeight)
To validate and throw InvalidValueException object with the appropriate
message if the height entered is invalid:
– Invalid height – must be between 1.2 and 2.5
– Invalid height – must be a numeric value
Otherwise return the height as a double value.
o double validateWeigth(String aWeight)
To validate and throw InvalidValueException object with the appropriate
message if the weight entered is invalid:
– Invalid weight – must be between 30 and 200
– Invalid weight – must be a numeric value
Otherwise return the weight as a double value.
Your program should call the methods defined in the bullet point above to validate the data,
calculate and display the BMI together with the category.
Submit your program together with screenshots showing the input and output from the full
program testing. Your screenshot must show your name and student identification number as part
of the program output.
Sample of one run of the program is given below:
SIM UNIVERSITY
Tutor-Marked Assignment – Page 10 of 14
ICT201
Tutor-Marked Assignment
Question 3 [ 20 marks ]
The objectives of this question are
(a)
to use object-oriented programming concepts to build an application.
(b)
to implement graphical user interface program in Java.
Your task for this question is to write a simple Java program to display a graphical user interface
for the calculation of car loan.
The sample GUI is given in the figures below. Your layout need not be exactly the same but it
must have all the essential components shown.
Figure 3.1 – Initial GUI
Figure 3.2 – GUI with user input and response
The details required for this GUI are:
The widgets in the GUI are
o A label showing the title of the application in larger font size and bold face.
o The text fields for user to enter the loan amount, interest rate and duration,
together with the necessary labels as description.
o The radio buttons for the user to select whether there is any referral.
o Two buttons, one to perform calculation and the other one to clear the text fields
and reset the values to 0.
o The text fields to display the monthly payment and total payment calculated,
together with the necessary labels.
o A label showing your name at the bottom of the GUI in smaller font size and italic
style.
The formula to calculate the monthly payment is
where P is the loan amount, r is the interest rate and m is the duration in months
You may assume that all input values are valid.
SIM UNIVERSITY
Tutor-Marked Assignment – Page 11 of 14
ICT201
Tutor-Marked Assignment
The customer will enjoy a 0.5% reduction of interest rate if he has any referral, i.e. if the
interest rate is 3%, he needs only to pay 2.5% interest if he has referral.
Your program should display the monthly payment and total payment amounts when the
“Calculate” button is clicked; set the text fields to “0” when the “Clear” button is
clicked.
The result should be displayed in two decimal places.
The GUI should have your name in its title bar.
Your submission for the TMA should consist of:
A listing of your program, properly formatted for easy reading.
Two screenshots showing two runs of your program.
SIM UNIVERSITY
Tutor-Marked Assignment – Page 12 of 14
ICT201
Tutor-Marked Assignment
Appendix A
Program template for Q1(e):
import java.text.*;
import java.util.*;
import java.time.*;
import java.time.format.*;
import java.time.temporal.ChronoUnit;
public class VehicleRentalSystem
{
public static void main(String[] args) {
// create some vehicles, add them into ArrayList vehicleList
ArrayList vehicleList = new ArrayList();
initialiseVehicles(vehicleList);
// create some customers and add them into ArrayList customerList
ArrayList customerList = new ArrayList();
initialiseCustomers(customerList);
// Add an ArrayList here…
//Display menu and process the opitons
}
// method to initialise vehicles in the vehicle rental system
public static void initialiseVehicles(ArrayListvehicleList)
{
Vehicle vehicle;
vehicle = new Car(“SJV1883R”, “Honda”, “Civic”, 1600);
vehicleList.add(vehicle);
vehicle = new Car(“SJZ2987A”, “Toyota”, “Wish”, 1800);
vehicleList.add(vehicle);
vehicle = new Car(“SKA4370H”, “Honda”, “Accord”, 2200);
vehicleList.add(vehicle);
vehicle = new Car(“SKD8024M”, “Toyota”, “Camry”, 2200);
vehicleList.add(vehicle);
vehicle = new Truck(“GB3221K”, “Toyota”, “LiteAce”, 2);
vehicleList.add(vehicle);
vehicle = new Truck(“GB8283M”, “Isuzu”, “NPR”, 3);
vehicleList.add(vehicle);
vehicle = new Truck(“GBA113X”, “Nissan”, “Cabstar”, 3);
vehicleList.add(vehicle);
vehicle = new Truck(“YX123Z”, “Kia”, “KX2500”, 2);
vehicleList.add(vehicle);
}
// method to initialise customers in the vehicle rental system
public static void initialiseCustomers(ArrayListcustomerList)
{
Customer customer;
customer = new Customer(“S9099999A”,”Adrian”,”91112222″);
customerList.add(customer);
customer = new Customer(“S8958911B”,”Benjamin”,”96668888″);
customerList.add(customer);
customer = new Customer(“S7970326C”,”Christina”,”93335555″);
customerList.add(customer);
}
// implement other methods here …
}
SIM UNIVERSITY
Tutor-Marked Assignment – Page 13 of 14
ICT201
Tutor-Marked Assignment
Appendix B
Method validateCheckDigit(String) for Q2:
public static boolean validateCheckDigit(String nric)
{
String weight = “2765432”;
String ref = “ABCDEFGHIZJ”;
int sum = 0;
for (int i=0; i