We are going to build a system for a small transport company which can transport both passengers and goods. There will be a main class called TransportCompany
. Your task is to avoid code duplication and make the design future-proof, e.g. it should be easy to extend the program with new functionality.
This assignment is mostly about the data model and your choice of interfaces and/or inheritance. We will therefore keep the drawing and printing in the application to a minimum. Since this assignment is about modelling, we strongly recommend drawing the class diagram first. Read the description below carefully, draw the class diagram and then start implementing.
The main functionality should be:
Therefore, implement at least the following methods:
loadPassengers(int amount)
and/or loadCargo(double weightInTonnes)
void addVehicle(Vehicle v)
ArrayList<Vehicle> getVehiclesWithRoomForPassengers(int amountOfPassengers)
ArrayList<Vehicle> getVehiclesWithRoomForCargo(int weightInTonnes)
What you need to know about the transport company:
Truck
is only suitable for transporting cargo and has certain dimensions (height, width, depth) that are relevant to store. A truck may carry a maximum of 30 tons but this maximum may obviously be smaller.Bus
is dedicated solely to carrying passengers and thus cannot carry cargo. All buses also have a descriptive name and a maximum range (in km).Boat
is also dedicated solely to carrying passengers (and thus cannot have cargo). Also boats still have a descriptive name and the number of life jackets found on board. It also records whether there is a refrigerator on board. The number of life jackets obviously determines the maximum number of people allowed on board.ContainerShip
can also carry only goods and contains as the only additional information how many containers are (and can be) loaded. Each container can carry a maximum weight of 25 tons.Train
is a combination of both and thus can carry both passengers and goods. This works because a train can consist of multiple freight cars and passenger cars. So for each train, if you register the amount of freight and passengers cars, you know how much freight and passengers can be transported. Each passenger car can hold 50 people, and each freight car can carry up to 200 tons.