public class Bus { privateStringname; privateintsize; privateintbasePrice; privateArrayListapprovedTrips; privateintlevel;// 1,2,3 for low,medium, high repectively; privateintid; privatestaticintnextId=0;
import java.util.ArrayList;
public class Bus {
privateStringname;
privateintsize;
privateintbasePrice;
privateArrayList<Trip>approvedTrips;
privateintlevel;// 1,2,3 for low,medium, high repectively;
privateintid;
privatestaticintnextId=0;
privateMinistrymny;
protectedStringtripTypes;
privateintgetNextId(){
returnnextId++;
}
publicBus(){
approvedTrips=newArrayList<Trip>();
}
publicBus(Stringname,intsize,intbasePrice,intlev,Ministrymny){
approvedTrips=newArrayList<Trip>();
this.name=name;
this.size=size;
this.basePrice=basePrice;
this.level=lev;
this.id=getNextId();
this.mny=mny;
tripTypes="BASICTRANSPORT";
}
publicbooleanavailable(Datedate){
booleanretval=true;
for(Tript:approvedTrips)
if(t.getDate().getDay()==date.getDay())
retval=false;
returnretval;
}
publicintgetBasePrice(){
returnbasePrice;
}
publicintgetId(){
returnid;
}
publicStringgetName(){
returnname;
}
publicdoublegetSize(){
returnsize;
}
publicStringtoString(){
returnname;
}
publicbooleanisSuitable(Stringtype){
returntripTypes.contains(type);
}
publicintgetEstimate(Stringtype,intnumPassengers,intcomfortLevel){
returnbasePrice;
}
publicbooleancanHold(intnumPassengers,intcomfortLevel){
intcapacity=(int)(size/mny.getSeparation(comfortLevel));
returnnumPassengers<=capacity;
}
publicvoidpromoteTrips(){
System.out.println();
System.out.println("TRIPS ON "+getName());
System.out.println("===================");
for(Tript:approvedTrips)
System.out.println(t);
}
publicintreserve(Triptrip,Ministrymny){
intretval=-1;
ApprovalRequestar=newApprovalRequest(trip,this);
intresult=mny.checkApproval(ar);
if(result>=0){
intest=getEstimate(trip.getType(),trip.getNumPeople(),trip.getComfortLevel());
if(trip.getPlanner().getBudget()>=getEstimate(trip.getType(),trip.getNumPeople(),trip.getComfortLevel())){
approvedTrips.add(trip);
trip.setBus(this);
retval=result;
}
}
returnretval;
}
THE SPORTBUS CLASS (15 marks)
The SportBus class is a specialized Bus.
It stores private integer data items that represent competitorArea and spectatorArea, as well as an
ArrayList of strings, each of which represent a sport for which the bus will be configured.
Methods of SportBus are as follows
1. SportBus(String name, int basePrice, int lev, Ministry mny,
int competitorArea, int spectatorArea, String sportList)
– initialize instance
-Set the size of the associated parent class is as the sum competitorArea+spectatorArea;
- append “ ,SPORT” to the protected tripTypes attribute of the superclass
- split the sportList into an array, then populate the list of sports from the array (Hint.
splitting a delimited string can be achieved using String.split())
2. double getCompetitorArea() – returns the area available for competitors
3. double getSpectatorArea() – returns the area available for spectators
4. int getBasePrice() – returns 3 * the base price of the superclass
5. int getEstimate(String type, int numPersons, int level) – returns an estimated cost to
run the trip. The cost is calculated as getBasePrice() * 10 * (competitorArea+spectatorArea)
/competitorArea.
THE TRAININGBUS CLASS(15 marks)
The TrainBus class is a specialized Bus.
It stores private integer data items that represent teacherArea, studentArea and wifiRange, as well
as an ArrayList of strings, each of which represent a course for which the bus will be configured.
Methods of TrainingBus are as follows
1. TrainingBus (String name, int basePrice, int wifiRange, int lev, Ministry mny,
int teacherArea, int studentArea, String sportList)
–initialize instance–
-Set the size of the associated parent class is as the sum teacherArea + studentArea;
- append “ ,TRAINING” to the protected tripTypes attribute of the superclass
- split the sportList into an array, then populate the list of sports from the array (Hint.
Splitting a delimited string can be achieved using String.split())
2. double getTeacherArea() – returns the area available for teachers
3. double getStudentArea() – returns the area available for students
4. int getBasePrice() – returns 2 * the base price of the superclass
5. int getEstimate(String type, int numPersons, int level) – returns the 5 x teacherArea x
the getEstimate method of the superclass, divided by the number of courses managed
THE PARTYBUS CLASS(40 marks)
Some persons were concerned over whether a ministry should be getting involved with an activity
that could be considered non-productive. To appease detractors, the ministry came up with a
solution that every party should have a purpose. The effect on your implementation is that your
PartyBus will be EITHER a specialized SportBus
1. If the first letter of your surname is M or smaller, a PartyBus is a specialized SportBus.
The PartyBus has attributes that represent a barArea, a foodArea and a securityCrew. It’ s
constructor initializes the instance, and appends “, PARTY” the protected tripTypes attribute. The
PartyBus overloads the getEstimate method. Again, the ministry seeks to assess various models.
Your calculation for the getEstimate
formula: foodArea x superclass getEstimate(type, numPersons, level)/(3 x barArea)
Step by step
Solved in 4 steps