Midterm 2021
Midterm 2021
Midterm Examination
Date: 13/11/2021; Duration: 90 minutes
Online; open book exam
Full name: Nguyễn Văn Sinh Full name: Trần Thanh Tùng
Proctor 1 Proctor 2
Signature Signature
STUDENT INFO
Student name:
Student ID:
1. (20 marks) In Object-Oriented Programming, describe, explain, and give an example to illustrate each
of the following keywords:
a. protected and private (10 marks)
b. super (10 marks)
public A(int x) {
//TO IMPLEMENT
System.out.println("Ctor of A");
A.count1++;
count2++;
}
}
public class B extends A {
protected int y;
private int z;
public B (int x, int y, int z) {
// TO IMPLEMENT
System.out.println("Ctor of B");
}
}
2 / 3
HCMC National University Student Name:………...……………………….
International University Student ID:…………………………….
In the system, there are drivers, clients, and services. Implement the system with the following
requirements
• Services. There are 3 types of services: food delivery, express delivery and in-day delivery. Each
service has a name and a price. A food delivery costs 1$ per km, an express delivery costs 2$ per
km, and in-day delivery costs 0.5$ per km. Each service has a status: booked, delivering, and
delivered.
• A driver can serve any type of service, but he can serve only one service at a time.
• A client can book many services and can check the status of all booked services.
• Each time a client books a service, the client must provide the distance for the delivery, and can
know the cost of the service but cannot select a driver.
• The system manages all booked service, and a driver can select and accept any booked service.
The status of the accepted service becomes delivering.
After finishing a delivery, the status of the service becomes delivered, 80% of cost of the service
goes to the account of the driver, and the driver is free to take another service.
a. (20 marks) Write classes to store services, clients, and drivers.
b. (15 marks) Implement a function name “MyDeli” to test the following scenario in order
1.Create 2 drivers (d1 and d2) and 2 clients (c1 and c2)
2.Client c1 books one 2km food delivery, one 5km express delivery.
3.Client c2 books one 10km express delivery.
4.Driver d1 accepts the food delivery
5.Show the status of all services of client c1
6.Driver d2 accepts the 5km express delivery, after finishing the service, accepts the 10km
express delivery.
7.Show the balance (account) of two drivers
8.Driver d1 finish all services, driver d2 finish all services
9.Show the status of all services of client c2
c. (10 marks) Implement the in-day delivery service where many booked in-day delivery services
can be grouped together and given to a driver. Write a function to test the scenario
o Client c1 books one 7km in-day delivery
o Client c2 books one 5km in-day delivery
o Combine 2 booking into a single service and give it to the driver d1.
o Show the balance of driver d1
-- The end --
3 / 3