SlideShare a Scribd company logo
import java.util.ArrayList;
public class Bus {
private String name;
private int size;
private int basePrice;
private ArrayList<Trip> approvedTrips;
private int level; // 1,2,3 for low,medium, high repectively;
private int id;
private static int nextId=0;
private Ministry mny;
protected String tripTypes;
private int getNextId(){
return nextId++;
}
public Bus(){
approvedTrips=new ArrayList<Trip>();
}
public Bus( String name, int size, int basePrice, int lev, Ministry mny) {
approvedTrips=new ArrayList<Trip>();
this.name = name;
this.size =size;
this.basePrice = basePrice;
this.level = lev;
this.id = getNextId();
this.mny = mny;
tripTypes = "BASICTRANSPORT";
}
public boolean available(Date date){
boolean retval = true;
for (Trip t:approvedTrips)
if (t.getDate().getDay() == date.getDay())
retval = false;
return retval;
}
public int getBasePrice(){
return basePrice;
}
public int getId(){
return id;
}
public String getName(){
return name;
}
public double getSize(){
return size;
}
public String toString(){
return name;
}
public boolean isSuitable(String type){
return tripTypes.contains(type);
}
public int getEstimate(String type, int numPassengers, int comfortLevel){
return basePrice;
}
public boolean canHold(int numPassengers, int comfortLevel){
int capacity = (int)(size / mny.getSeparation(comfortLevel));
return numPassengers <=capacity;
}
public void promoteTrips(){
System.out.println();
System.out.println("TRIPS ON " +getName());
System.out.println("===================");
for (Trip t:approvedTrips)
System.out.println(t);
}
public int reserve(Trip trip, Ministry mny){
int retval = -1;
ApprovalRequest ar = new ApprovalRequest(trip, this);
int result = mny.checkApproval(ar);
if (result >=0){
int est = 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;
}
}
return retval;
}
Complete the following code based on these instructions :
COMPLETING THE PLANNER class The int planTrip(int numPassengers, String tripType,
Date date, int comfortLevel) method of Planner plans an trip of a given type with the specified
number of passengers on the specified date. Steps include: a. Determine the set of buses that the
promoter can afford b. Find the lowest cost Bus from the set of affordable buses that i. can hold
the number of passengers and ii. is available c. If there is at least one Bus that meets the
requirements i. Create an instance of a Trip ii. Call the reserve method of the Bus and capture the
return value in an integer iii. If the return value is greater than or equal to 0, 1. Call the setBus
method of the trip to the selected bus 2. Pay for the selected bus 3. Return the return value as the
result of planTrip d. If plans for the trip did not work out, return -1
import java.util.ArrayList;
public class Planner
{
private String name;
private double budget;
private Ministry mny;
private Bus[] buses;
private ArrayList<Bus> possibleBuses;
public Planner(String name, double budget, Ministry mny, Bus[] buses)
{
this.name = name;
this.budget = budget;
this.mny = mny;
this.buses = buses;
possibleBuses = new ArrayList<Bus>();
}
public String getName(){
return name;
}
public double getBudget(){
return budget;
}
public int planTrip(int numPassengers, String tripType, Date date, int comfortLevel) {
int retval = -1;
possibleBuses.clear();
/*
//populate possible buses by adding busses that are suitable,
// can hold the passengers at the comfortlevel,and can be afforded
*/
//System.out.println(possibleBuses.size() +" affordable buses ");
if (possibleBuses.size() >0){
Bus minBus=null;
/*
//find the suitable bus with minimum price and assign to minbus`
*/
if (minBus==null)
System.out.println("No suitable bus is available");
else{
//create a trp with the type, number of passengers and the comfortlevel
// attempt to get get an approval id by calling the reserve method of the bus
// if the id >=0
Trip trip = new Trip(tripType, numPassengers, date, comfortLevel,this);
int reserved = minBus.reserve(trip, mny);
if (reserved >= 0){
trip.setBus(minBus);
payFor(minBus,tripType, numPassengers, comfortLevel);
retval = reserved;
System.out.println(name + " successfully reserved " + trip);
}
}
}
else
System.out.println(name + " cannot afford to pay for any suitable buses");
return retval;
}
public void payFor(Bus bus, String tripType, int numPassengers, int comfortLevel){
budget-=bus.getEstimate(tripType, numPassengers, comfortLevel);
}
}

More Related Content

PDF
Complete the following- The int planTrip(int numPassengers- String tri.pdf
PDF
Vehicle.javapublic class Vehicle {    Declaring instance var.pdf
DOCX
Complete the below Trip class that could be used by a software for a t.docx
PDF
Monadic Java
PDF
Creating an Uber Clone - Part XXIX - Transcript.pdf
PDF
I have compilation errors that I'm struggling with in my code- please.pdf
PDF
Creating an Uber Clone - Part XXIX.pdf
PDF
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
Complete the following- The int planTrip(int numPassengers- String tri.pdf
Vehicle.javapublic class Vehicle {    Declaring instance var.pdf
Complete the below Trip class that could be used by a software for a t.docx
Monadic Java
Creating an Uber Clone - Part XXIX - Transcript.pdf
I have compilation errors that I'm struggling with in my code- please.pdf
Creating an Uber Clone - Part XXIX.pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf

More from GordonF2XPatersonh (20)

PDF
import java-lang-Comparable- -- new Main-String-() public class Main-.pdf
PDF
In 2022- Jacques paid the following interest- Interest on home mortgag.pdf
PDF
In 2020- the world was made aware of the highly contagious and occasio.pdf
PDF
Implement an extended version of the Caesar cipher that users the char.pdf
PDF
Implement FIFO queue using two stacks in Python- Methods should have O.pdf
PDF
Imagine a natural area near your hometown that has been identified as.pdf
PDF
If you wish to estimate a population mean with a sampling distribution.pdf
PDF
igate Search Project Run Window Help D eclipse-worksoace - Names javar.pdf
PDF
If you have a dataset with n-42- mean is 50- the standard deviation is.pdf
PDF
If you combine cooking oil (a lipid) with water in a measuring cup- th.pdf
PDF
If X has a binomial random variable with probability distribution f(x).pdf
PDF
If we look at the diagram below we notice that there are soveral chara.pdf
PDF
If total assets decrease- then which of the following statements is tr.pdf
PDF
If two different accountants were to estimate the percentage of custom.pdf
PDF
If the radius of the Earth were to increase by a factor of 4 while its.pdf
PDF
If the government suddenly decided to include the non-civilian employe.pdf
PDF
If the Earth's P-wave velocities were faster than they actually are- t.pdf
PDF
If the Earth was made-up entirely of crustal rocks- then what would th.pdf
PDF
If the anhydrous compound (AC) in the preceding problem has a molar ma.pdf
PDF
If the agenda has any ties between nodes- i-e- unsure of which selecti.pdf
import java-lang-Comparable- -- new Main-String-() public class Main-.pdf
In 2022- Jacques paid the following interest- Interest on home mortgag.pdf
In 2020- the world was made aware of the highly contagious and occasio.pdf
Implement an extended version of the Caesar cipher that users the char.pdf
Implement FIFO queue using two stacks in Python- Methods should have O.pdf
Imagine a natural area near your hometown that has been identified as.pdf
If you wish to estimate a population mean with a sampling distribution.pdf
igate Search Project Run Window Help D eclipse-worksoace - Names javar.pdf
If you have a dataset with n-42- mean is 50- the standard deviation is.pdf
If you combine cooking oil (a lipid) with water in a measuring cup- th.pdf
If X has a binomial random variable with probability distribution f(x).pdf
If we look at the diagram below we notice that there are soveral chara.pdf
If total assets decrease- then which of the following statements is tr.pdf
If two different accountants were to estimate the percentage of custom.pdf
If the radius of the Earth were to increase by a factor of 4 while its.pdf
If the government suddenly decided to include the non-civilian employe.pdf
If the Earth's P-wave velocities were faster than they actually are- t.pdf
If the Earth was made-up entirely of crustal rocks- then what would th.pdf
If the anhydrous compound (AC) in the preceding problem has a molar ma.pdf
If the agenda has any ties between nodes- i-e- unsure of which selecti.pdf
Ad

Recently uploaded (20)

PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Institutional Correction lecture only . . .
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Lesson notes of climatology university.
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Pharma ospi slides which help in ospi learning
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Classroom Observation Tools for Teachers
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Complications of Minimal Access Surgery at WLH
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
RMMM.pdf make it easy to upload and study
GDM (1) (1).pptx small presentation for students
Institutional Correction lecture only . . .
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
VCE English Exam - Section C Student Revision Booklet
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Final Presentation General Medicine 03-08-2024.pptx
Lesson notes of climatology university.
Abdominal Access Techniques with Prof. Dr. R K Mishra
Pharma ospi slides which help in ospi learning
Supply Chain Operations Speaking Notes -ICLT Program
Classroom Observation Tools for Teachers
O7-L3 Supply Chain Operations - ICLT Program
Complications of Minimal Access Surgery at WLH
2.FourierTransform-ShortQuestionswithAnswers.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Ad

import java-util-ArrayList- public class Bus { private String na.pdf

  • 1. import java.util.ArrayList; public class Bus { private String name; private int size; private int basePrice; private ArrayList<Trip> approvedTrips; private int level; // 1,2,3 for low,medium, high repectively; private int id; private static int nextId=0; private Ministry mny; protected String tripTypes; private int getNextId(){ return nextId++; } public Bus(){ approvedTrips=new ArrayList<Trip>(); } public Bus( String name, int size, int basePrice, int lev, Ministry mny) { approvedTrips=new ArrayList<Trip>(); this.name = name; this.size =size; this.basePrice = basePrice; this.level = lev;
  • 2. this.id = getNextId(); this.mny = mny; tripTypes = "BASICTRANSPORT"; } public boolean available(Date date){ boolean retval = true; for (Trip t:approvedTrips) if (t.getDate().getDay() == date.getDay()) retval = false; return retval; } public int getBasePrice(){ return basePrice; } public int getId(){ return id; } public String getName(){ return name; } public double getSize(){ return size; }
  • 3. public String toString(){ return name; } public boolean isSuitable(String type){ return tripTypes.contains(type); } public int getEstimate(String type, int numPassengers, int comfortLevel){ return basePrice; } public boolean canHold(int numPassengers, int comfortLevel){ int capacity = (int)(size / mny.getSeparation(comfortLevel)); return numPassengers <=capacity; } public void promoteTrips(){ System.out.println(); System.out.println("TRIPS ON " +getName()); System.out.println("==================="); for (Trip t:approvedTrips) System.out.println(t); } public int reserve(Trip trip, Ministry mny){ int retval = -1; ApprovalRequest ar = new ApprovalRequest(trip, this);
  • 4. int result = mny.checkApproval(ar); if (result >=0){ int est = 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; } } return retval; } Complete the following code based on these instructions : COMPLETING THE PLANNER class The int planTrip(int numPassengers, String tripType, Date date, int comfortLevel) method of Planner plans an trip of a given type with the specified number of passengers on the specified date. Steps include: a. Determine the set of buses that the promoter can afford b. Find the lowest cost Bus from the set of affordable buses that i. can hold the number of passengers and ii. is available c. If there is at least one Bus that meets the requirements i. Create an instance of a Trip ii. Call the reserve method of the Bus and capture the return value in an integer iii. If the return value is greater than or equal to 0, 1. Call the setBus method of the trip to the selected bus 2. Pay for the selected bus 3. Return the return value as the result of planTrip d. If plans for the trip did not work out, return -1 import java.util.ArrayList; public class Planner { private String name; private double budget; private Ministry mny;
  • 5. private Bus[] buses; private ArrayList<Bus> possibleBuses; public Planner(String name, double budget, Ministry mny, Bus[] buses) { this.name = name; this.budget = budget; this.mny = mny; this.buses = buses; possibleBuses = new ArrayList<Bus>(); } public String getName(){ return name; } public double getBudget(){ return budget; } public int planTrip(int numPassengers, String tripType, Date date, int comfortLevel) { int retval = -1; possibleBuses.clear(); /* //populate possible buses by adding busses that are suitable, // can hold the passengers at the comfortlevel,and can be afforded
  • 6. */ //System.out.println(possibleBuses.size() +" affordable buses "); if (possibleBuses.size() >0){ Bus minBus=null; /* //find the suitable bus with minimum price and assign to minbus` */ if (minBus==null) System.out.println("No suitable bus is available"); else{ //create a trp with the type, number of passengers and the comfortlevel // attempt to get get an approval id by calling the reserve method of the bus // if the id >=0 Trip trip = new Trip(tripType, numPassengers, date, comfortLevel,this); int reserved = minBus.reserve(trip, mny); if (reserved >= 0){ trip.setBus(minBus); payFor(minBus,tripType, numPassengers, comfortLevel); retval = reserved; System.out.println(name + " successfully reserved " + trip); } } }
  • 7. else System.out.println(name + " cannot afford to pay for any suitable buses"); return retval; } public void payFor(Bus bus, String tripType, int numPassengers, int comfortLevel){ budget-=bus.getEstimate(tripType, numPassengers, comfortLevel); } }