Question: Having some issues with my Vehicle Class PLEASE provide corrected codes if possible. This is my code: public abstract class Vehicle { protected Person [
Having some issues with my Vehicle Class
PLEASE provide corrected codes if possible.
This is my code:
public abstract class Vehicle
protected Person personsOnBoard;
protected int numberOfRows;
protected int maxSeatsPerRow;
protected int numSeatsPerRow;
public Vehicleint numRows, int numSeatsPerRow
this.numberOfRows numRows;
this.maxSeatsPerRow numSeatsPerRow;
this.personsOnBoard new PersonnumberOfRows;
this.numSeatsPerRow new intnumberOfRows;
for int i ; i numberOfRows; i
this.personsOnBoardi new PersonnumSeatsPerRow;
this.numSeatsPerRowi maxSeatsPerRow;
public Vehicleint numSeatsPerRow
this.numberOfRows numSeatsPerRow.length;
this.maxSeatsPerRow numSeatsPerRow;
this.personsOnBoard new PersonnumberOfRows;
this.numSeatsPerRow numSeatsPerRow;
forint i ; i numberOfRows; i
personsOnBoardi new PersonnumSeatsPerRowi;
ifnumSeatsPerRowi maxSeatsPerRow
maxSeatsPerRow this.numSeatsPerRowi;
public VehiclePerson driver, int numSeatsPerRow
thisnumSeatsPerRow;
ifdriverhasDriverLicense
personsOnBoard driver;
public abstract boolean loadPassengerPerson p;
public abstract int loadPassengersPerson peeps;
public void setDriverPerson p throws InvalidDriverException
ifphasDriverLicense
personsOnBoard p;
else
throw new InvalidDriverException;
public Person getDriver
return personsOnBoard;
public boolean hasDriver
return personsOnBoard null;
public int getNumberOfAvailableSeats
int availableSeats ;
forint i ; i numberOfRows; i
forint j ; j numSeatsPerRowi; j
ifpersonsOnBoardij null
availableSeats;
return availableSeats;
public int getNumberOfAvailableSeatsInRowint row
int availableSeats ;
ifrow && row numberOfRows
for int i ; i numSeatsPerRowrow; i
if personsOnBoardrowi null
availableSeats;
return availableSeats;
public int getNumberOfPeopleOnBoard
int peopleOnBoard ;
forint i ; i numberOfRows; i
forint j ; j numSeatsPerRowi; j
ifpersonsOnBoardij null
peopleOnBoard;
return peopleOnBoard;
public int getNumberOfPeopleInRowint row
int peopleInRow ;
ifrow && row numberOfRows
forint i ; i numSeatsPerRowrow; i
ifpersonsOnBoardrowi null
peopleInRow;
return peopleInRow;
public Person getPersonInSeatint row, int col
if row && row numberOfRows && col && col numSeatsPerRowrow
return personsOnBoardrowcol;
return null;
public int getLocationOfPersonInVehiclePerson p
int location;
forint i ; i numberOfRows; i
forint j ; j numSeatsPerRowi; j
ifpersonsOnBoardij null
ifpersonsOnBoardijequalsp
location i;
location j;
return location;
return location;
public Person getPeopleInRowint row
int numPeople getNumberOfAvailableSeatsInRowrow;
ifnumPeople
return null;
ifnumPeople
Person personsInRow new PersonnumPeople;
int count ;
forint i ; i numSeatsPerRowrow; i
ifpersonsOnBoardrowi null
personsInRowcount personsOnBoardrowiclone;
count;
return personsInRow;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
