Question: Complete the following: THE PLANNER CLASS The Planner class represents an trip organizer who comes up with a trip idea and initiates the process of

Complete the following:

THE PLANNER CLASS The Planner class represents an trip organizer who comes up with a trip idea and initiates the process of getting it approved. Public methods include 1. Planner (String name, double budget, Ministry mny, Bus[] buses) Initializes an instance of a promoter, by setting a name and a budget. An association to the ministry as well as set of buses is also established. 2. double getBudget() returns the budget associated with the planner 3. String getName() returns the name associated with the planner 4. void payFor(Bus bus, Trip trip , int numPassengers, int comfortLevel) Pays for the bus and reduces the budget by the cost 5. ****int planTrip(minBus,tripType, numPassengers, comfortLevel)

code so far:

import java.util.ArrayList;

public class Planner { private String name; private double budget; private Ministry mny; private Bus[] buses; private ArrayList 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(); } 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); } now

COMPLETING THE PLANNER CLASS(25 marks) 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

}

THE DATE CLASS(5 marks) The Date class, used to represent a date in the system, exposes the following public methods 1. Date(int day) instantiates a Date object, by setting its internal value to day 2. void setDay(int day) sets the internal value to day 3. int getDay() returns the internal value 4. Date next(int day) returns a date corresponding to argument incremented by 1 5. String toString() returns a string representation of the internal value

public class Date { private int day; public void setDay(int day){ } public int getDay(){ return 0; } public String toString(){ return ""; } public Date(int date) { }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!