Question: How can we code a method that has 3 parameters: no.Passengers, no.Days and Brand. It should return the object of the booked car. The method

How can we code a method that has 3 parameters: no.Passengers, no.Days and Brand. It should return the object of the booked car. The method should be able to find a car in the fleet (ArrayList) that has the same brand, not booked (isTaken = false) and has the minimum no.seats to fit the required passengers. In other words, the method should find the car that best fits the requirements, not the first occurrence. If two car objects have the same brand, and if (isTaken == false)then we are supposed to find the object with the minimum number of seats. If a car is found, the method should set the car to booked (set isTaken to true), set the no.Days to the value provided through the parameters, and return that car. Otherwise, if no car is found, the method should return null.

This method is to be coded in a different class than the Car class and should not use Scanner class as there will be a driver class in which input will be given through.

Instance variables of Car class:

int no.Passengers, int no.Days, String Brand, Boolean isTaken, int no.Seats

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 Programming Questions!