SlideShare a Scribd company logo
Complete the following:
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
look at this bus class code and utilize the methods in order to complete the int planTrip question
here it is to be clear i need you to complete the int PlanTrip i have my attempted below the bus
class so you can use that to guide you please and thanks
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;
}
}
attempted code planner code
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();
for (Bus bus : buses ) {
if (bus.getEstimate(tripType, numPassengers, comfortLevel) <= budget &&
bus.canHold(numPassengers, comfortLevel)) {
possibleBuses.add(bus);
//System.out.println(possibleBuses.size() +" affordable buses ");
}
}
//populate possible buses by adding busses that are suitable,
// can hold the passengers at the comfortlevel,and can be afforded
if (possibleBuses.size() > 0) {
Bus minBus = null;
for (Bus bus : possibleBuses) {
if (bus.available(date) && (minBus == null || bus.getEstimate(tripType, numPassengers,
comfortLevel) < minBus.getEstimate(tripType, numPassengers, comfortLevel)) &&
bus.isSuitable(tripType)) {
minBus = bus;
}
}
/*
//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
if (minBus != null){
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
import java-util-ArrayList- public class Bus { private String na.pdf
PDF
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf
PDF
Language Abstractions and Techniques for Developing Collective Adaptive Syste...
PDF
Vehicle.javapublic class Vehicle {    Declaring instance var.pdf
PPTX
SOLUTION OF MIXED INTUITIONISTIC FUZZY TRANSPORTATION PROBLEMS.pptx
PDF
A New Method to Solving Generalized Fuzzy Transportation Problem-Harmonic Mea...
PDF
Child vaccination chart Objective Take user inputs and add them to the.pdf
PDF
Centering a webpage is easy in comparison to middling a webpage- Open.pdf
import java-util-ArrayList- public class Bus { private String na.pdf
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf
Language Abstractions and Techniques for Developing Collective Adaptive Syste...
Vehicle.javapublic class Vehicle {    Declaring instance var.pdf
SOLUTION OF MIXED INTUITIONISTIC FUZZY TRANSPORTATION PROBLEMS.pptx
A New Method to Solving Generalized Fuzzy Transportation Problem-Harmonic Mea...
Child vaccination chart Objective Take user inputs and add them to the.pdf
Centering a webpage is easy in comparison to middling a webpage- Open.pdf

More from 2adretail (20)

PDF
CHAPTER 32 Constructive Dialogue and ERM Lessons from the Financial Cr (1).pdf
PDF
Ch 14mn cosencosen Carist 3 B-Minter fatine tiens the ientG 4 minewin.pdf
PDF
Case- Using Demand and Supply Analysis Assume there is a well-defined.pdf
PDF
Ch 12 - Decentralization What is one advantage of a decentralized orga.pdf
PDF
Chapter 3- Numerical Descriptive Measures Chapter 4- Basic Probability.pdf
PDF
CASE STUDY - Answer the following questions in 2-3 sentences using you.pdf
PDF
CHAPTER 32 Constructive Dialogue and ERM Lessons from the Financial Cr.pdf
PDF
CDE7- Enter the beginning balances in the MyLab Accounting Excel templ.pdf
PDF
Cells that provide direct protection and physical support to neurons a.pdf
PDF
Computer Science- In relation to procedure calls- explain what happen.pdf
PDF
Compose a written reflection on the practical implications of a Suprem.pdf
PDF
Compute 90-day forward premium for USD to EUR exchange rate by using t.pdf
PDF
Complex I -15 marks- Complex I contains a hydrophobic and hydrophilic.pdf
PDF
Complete the following table based on the topolocy- Allow enough extra.pdf
PDF
Chapter 5 covers Merchandise Inventory and a Multiple-Step Income Stat.pdf
PDF
Complete each sentence by dragging the proper label into the appropria.pdf
PDF
Compilers 2-14- Construct an NFA that recognizes the RE a(abc)- and fi.pdf
PDF
Compare and contrast using examples or definitions- Epicardium- myocar.pdf
PDF
Compiete the missing amounts and labels in the Traccounts- (1) (Cick t.pdf
PDF
Compare the current interglacial ( 0 to 10-000 years ago) to previous.pdf
CHAPTER 32 Constructive Dialogue and ERM Lessons from the Financial Cr (1).pdf
Ch 14mn cosencosen Carist 3 B-Minter fatine tiens the ientG 4 minewin.pdf
Case- Using Demand and Supply Analysis Assume there is a well-defined.pdf
Ch 12 - Decentralization What is one advantage of a decentralized orga.pdf
Chapter 3- Numerical Descriptive Measures Chapter 4- Basic Probability.pdf
CASE STUDY - Answer the following questions in 2-3 sentences using you.pdf
CHAPTER 32 Constructive Dialogue and ERM Lessons from the Financial Cr.pdf
CDE7- Enter the beginning balances in the MyLab Accounting Excel templ.pdf
Cells that provide direct protection and physical support to neurons a.pdf
Computer Science- In relation to procedure calls- explain what happen.pdf
Compose a written reflection on the practical implications of a Suprem.pdf
Compute 90-day forward premium for USD to EUR exchange rate by using t.pdf
Complex I -15 marks- Complex I contains a hydrophobic and hydrophilic.pdf
Complete the following table based on the topolocy- Allow enough extra.pdf
Chapter 5 covers Merchandise Inventory and a Multiple-Step Income Stat.pdf
Complete each sentence by dragging the proper label into the appropria.pdf
Compilers 2-14- Construct an NFA that recognizes the RE a(abc)- and fi.pdf
Compare and contrast using examples or definitions- Epicardium- myocar.pdf
Compiete the missing amounts and labels in the Traccounts- (1) (Cick t.pdf
Compare the current interglacial ( 0 to 10-000 years ago) to previous.pdf

Recently uploaded (20)

PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
01-Introduction-to-Information-Management.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Presentation on HIE in infants and its manifestations
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Pharma ospi slides which help in ospi learning
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Complications of Minimal Access Surgery at WLH
PPTX
master seminar digital applications in india
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Cell Structure & Organelles in detailed.
PDF
RMMM.pdf make it easy to upload and study
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Lesson notes of climatology university.
Pharmacology of Heart Failure /Pharmacotherapy of CHF
01-Introduction-to-Information-Management.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Final Presentation General Medicine 03-08-2024.pptx
Presentation on HIE in infants and its manifestations
202450812 BayCHI UCSC-SV 20250812 v17.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Microbial disease of the cardiovascular and lymphatic systems
Microbial diseases, their pathogenesis and prophylaxis
Pharma ospi slides which help in ospi learning
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Complications of Minimal Access Surgery at WLH
master seminar digital applications in india
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
GDM (1) (1).pptx small presentation for students
Cell Structure & Organelles in detailed.
RMMM.pdf make it easy to upload and study
2.FourierTransform-ShortQuestionswithAnswers.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Lesson notes of climatology university.

Complete the following- The int planTrip(int numPassengers- String tri.pdf

  • 1. Complete the following: 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 look at this bus class code and utilize the methods in order to complete the int planTrip question here it is to be clear i need you to complete the int PlanTrip i have my attempted below the bus class so you can use that to guide you please and thanks 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(){
  • 2. 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(){
  • 3. 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();
  • 4. 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; } } attempted code planner code import java.util.ArrayList; public class Planner
  • 5. { 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();
  • 6. for (Bus bus : buses ) { if (bus.getEstimate(tripType, numPassengers, comfortLevel) <= budget && bus.canHold(numPassengers, comfortLevel)) { possibleBuses.add(bus); //System.out.println(possibleBuses.size() +" affordable buses "); } } //populate possible buses by adding busses that are suitable, // can hold the passengers at the comfortlevel,and can be afforded if (possibleBuses.size() > 0) { Bus minBus = null; for (Bus bus : possibleBuses) { if (bus.available(date) && (minBus == null || bus.getEstimate(tripType, numPassengers, comfortLevel) < minBus.getEstimate(tripType, numPassengers, comfortLevel)) && bus.isSuitable(tripType)) { minBus = bus; } } /* //find the suitable bus with minimum price and assign to minbus` */ if (minBus == null) { System.out.println("No suitable bus is available"); } else{
  • 7. //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 if (minBus != null){ 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); }
  • 8. }