Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5:36 ot 57 Q1 c) 20 pta, Create the following class Vehicle abstract class Vehicle # personsOnBoard: Person [][] # numberOfRows: int # maxSeatsPerRow: int

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
5:36 ot 57 Q1 c) 20 pta, Create the following class Vehicle abstract class Vehicle \# personsOnBoard: Person [][] \# numberOfRows: int \# maxSeatsPerRow: int \# numSeatsPerRow: int [] + Vehicle(int numRows, int numSeatsPerRow) /ISEE NOTE 1 + Vehicle(int [] numSeatsPerRow) /ISEE NOTE 2 + Vehicle(Person driver, int [] numSeatsPerRow) /ISEE NOTE 3 + abstract loadPassenger(Person p): boolean /ISEE NOTE 4 + abstract loadPassengers(Person I peeps): int /ISEE NOTE 5 + setDriver(Person p ): void throws InvalidDriverException MSEE NOTE 6 + getDriver(): Person + hasDriver(): boolean + getNumberOfAvailableSeats (0) int /ISEE NOTE 7 + getNumberO(AvallableSeatsinRow(int row): int IISEE NOTE 8 + getNumberOfPeopleOnBoard 0 : int /ISEE NOTE 9 + getNumberOfPeopleinRow(int row): int + getPersoninSeat(int row, int col): Person + getLocationOrPersoninVehicle(Person p): int [] I/SEE NOTE 10 + getPeoplelnRow(int row): Person[] IISEE NOTE 11 + getPeopleOnBoard (0: Person[ ][ ] IISEE NOTE 12 + isPersonlnVehicle(Person p): boolean + is PersonDriver(Person p): boolean Notes for Class Vehicle: 1. This constructor is used when all the rows have the exact same number of seats. 2. This constructor is used when all the rows do not have the same conngsencione of seats in each 5:36 a1 57 1. This constructor is used when all the rows have the exact same number of seats. 2. This constructor is used when all the rows do not have the same configuration. The number of seats in each row is provided by the array numSeatsPerRow, the number of rows is derived from the size of the array. 3. This constructor does everything specified by (2) above plus it sets the driver of the vehicle. Please note that the specified driver must have a driver's license, otherwise they are not qualified to be assigned to the driver position which is personsOnBoard[0][0]. 4. This abstract method will be implemented by derived classes to load the specified person into the vehicle at the first avallable seat. Searching for an avallable seat must start in the first row, please note that a person below the age of 5 or has a height less than 36 is not allowed to sit in the first row. This method returns true if there is room for the specified person, otherwise the method returns false. 5. This method attempts to load as many of the persons specified in the peeps array as possible. This method returns the number of people that were loaded into the Vehicle. 6. This method sets the driver of the Vehicle if the specified person has a driver's license. If the person does not have a driver's license, this method will throw the InvalidDriverException. 7. This method returns the number of availablelempty seats in the Vehicle. 8. This method returns the number of avallablelempty seats in the specified row. If the specified row is invalid, the method returns -1 . 9. This method counts the number of people currently assigned to seats in the vehicle, including the driver. 10. This method returns the location of the specified person in the vehicle by retuming an int array containing [ row, seatColumn ]. Please note that if the specified person is not seated in the vehicle, the method will return [1,1]. 11. This method will retum a Person array containing a clone of all the persons in the specified row. The populated Person array will not contain empty index locations. If the specified row has no one, or the specified row is invalid, this method returns a null. 12. This method returns a full clone of the 5:37 at 57 Q1 e ) (12 pts , Create the following class Car class Car extends Vehicle implements ComparablecCar. Announcements - numDoors: int - numWindows: int + Car(int numDoors, int numWindows) ISEE NOTE 1 + Car(int numDoors, int numWindows, int numSeatsPerRow ) //SEE NOTE 2 + Car(int numDoors, int numWindows, int [] numSeatsPerRow) /ISEE NOTE 3 + Car(int numDoors, int numWindows, Person driver, int [] numSeatsPerRow) //SEE NOTE 4 + canOpenDoor(Person p): boolean IISEE NOTE 5 + canOpenWindow(Person p): boolean ISEE NOTE 6 + getNumDoors(): int + getNumWindows(): int + equals(Object o): boolean /ISEE NOTE 7 + toString(): String //SEE NOTE 8 + compareTo(Car c): int IISEE NOTE 9 Notes for Class Car: 1. This constructor calls the parent class's constructor, passing in 2 for the numRows and 2 for the numSeatsPerRow, before assigning the numDoors and numWindows values. 2. This constructor calls the parent class's constructor passing in 2 for the numRows and the numSeatsPerRow argument, before assigning the numDoors and numWindows values. 3. This constructor calls the parent class's constructor passing in the numSeatsPerRow[ array as an argument, before assigning the numDoors and numWindows values. 4. This constructor calls the parent class's constructor passing in the driver and the numSeatsPerRow[ array, before assigning values to numDoors and numWindows. 5. This method retums true if the Person is seated in either of the exterior seats of a row that has a door (column index 0 or last index of that row) and is over age 5 . It returns false otherwise. If the number of doors is less than 2 " numberOrRows, the row/s past numDoors / 2 has/have no doors. 6. This methodremenstruer waremon is seated in passing in the numSeatsPerRow[ array as an argument, before assigning the numDoors and numWindows values. 4. This constructor calls the parent class's constructor passing in the driver and the numSeatsPerRow[ array, before assigning values to numDoors and numWindows. 5. This method returns true if the Person is seated in either of the exterior seats of a row that has a door (column index 0 or last index of that row) and is over age 5 . It returns false otherwise. If the number of doors is less than 2 numberOrRows, the row/s past numDoors /2 has/have no doors. 6. This method returns true if the Person is seated in either of the exterior seats of a row that has a window (column index 0 or last index of that row) and is over age 2. It returns false otherwise. If the number of windows is less than 2"numberORows,therowls past numWindows / 2 has/have no windows. 7. Two Car objects are considered equal if they have the same numDoors, same numWindows, same numberORRows, same maxSeatsPerRow, and the same seat configuration (numSeatsPerRowirow) at every row. 8. Return a string containing the Car's details formatted as follows: "Car: number of doors =%02d number of windows = %02d | number of rows =%02d | seats per row =% s | names of people on board =%sin The seats per row will be from the array of numSeatsPerRow as [val1,val2,val3, valn] The names of people on board will be separated by commas with no trailing comma. 9. This method returns - 1 if the calling object's total number of seats is less than the passed in object's total number of seats, 1 if the calling object's total number of seats is greater than the passed in object's total number of seats, 0 if they have the same total number of seats. 10. Be sure to implement the loadPassenger, and loadPassengers methods in the Car class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions