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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started