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 Vehicle(int numRows, int numSeatsPerRow)
{
this.numberOfRows = numRows;
this.maxSeatsPerRow = numSeatsPerRow;
this.personsOnBoard = new Person[numberOfRows][];
this.numSeatsPerRow = new int[numberOfRows];
for (int i =0; i numberOfRows; i++)
{
this.personsOnBoard[i]= new Person[numSeatsPerRow];
this.numSeatsPerRow[i]= maxSeatsPerRow;
}
}
public Vehicle(int [] numSeatsPerRow)
{
this.numberOfRows = numSeatsPerRow.length;
this.maxSeatsPerRow = numSeatsPerRow[0];
this.personsOnBoard = new Person[numberOfRows][];
this.numSeatsPerRow = numSeatsPerRow;
for(int i =0; i numberOfRows; i++)
{
personsOnBoard[i]= new Person[numSeatsPerRow[i]];
if(numSeatsPerRow[i] maxSeatsPerRow)
{
maxSeatsPerRow = this.numSeatsPerRow[i];
}
}
}
public Vehicle(Person driver, int[] numSeatsPerRow)
{
this(numSeatsPerRow);
if(driver.hasDriverLicense())
{
personsOnBoard[0][0]= driver;
}
}
public abstract boolean loadPassenger(Person p);
public abstract int loadPassengers(Person[] peeps);
public void setDriver(Person p) throws InvalidDriverException
{
if(p.hasDriverLicense())
{
personsOnBoard[0][0]= p;
}
else
{
throw new InvalidDriverException();
}
}
public Person getDriver()
{
return personsOnBoard[0][0];
}
public boolean hasDriver()
{
return (personsOnBoard[0][0]!= null);
}
public int getNumberOfAvailableSeats()
{
int availableSeats =0;
for(int i =0; i numberOfRows; i++)
{
for(int j =0; j numSeatsPerRow[i]; j++)
{
if(personsOnBoard[i][j]== null)
{
availableSeats++;
}
}
}
return availableSeats;
}
public int getNumberOfAvailableSeatsInRow(int row)
{
int availableSeats =0;
if(row >=0 && row numberOfRows)
{
for (int i =0; i numSeatsPerRow[row]; i++)
{
if (personsOnBoard[row][i]== null)
{
availableSeats++;
}
}
}
return availableSeats;
}
public int getNumberOfPeopleOnBoard()
{
int peopleOnBoard =0;
for(int i =0; i numberOfRows; i++)
{
for(int j =0; j numSeatsPerRow[i]; j++)
{
if(personsOnBoard[i][j]!= null)
{
peopleOnBoard++;
}
}
}
return peopleOnBoard;
}
public int getNumberOfPeopleInRow(int row)
{
int peopleInRow =0;
if(row >=0 && row numberOfRows)
{
for(int i =0; i numSeatsPerRow[row]; i++)
{
if(personsOnBoard[row][i]!= null)
{
peopleInRow++;
}
}
}
return peopleInRow;
}
public Person getPersonInSeat(int row, int col)
{
if (row >=0 && row numberOfRows && col >=0 && col numSeatsPerRow[row])
{
return personsOnBoard[row][col];
}
return null;
}
public int[] getLocationOfPersonInVehicle(Person p)
{
int location[]={-1,-1};
for(int i =0; i numberOfRows; i++)
{
for(int j =0; j numSeatsPerRow[i]; j++)
{
if(personsOnBoard[i][j]!= null)
{
if(personsOnBoard[i][j].equals(p))
{
location[0]= i;
location[1]= j;
return location;
}
}
}
}
return location;
}
public Person[] getPeopleInRow(int row)
{
int numPeople = getNumberOfAvailableSeatsInRow(row);
if(numPeople ==0)
{
return null;
}
if(numPeople >0)
{
Person[] personsInRow = new Person[numPeople];
int count =0;
for(int i =0; i numSeatsPerRow[row]; i++)
{
if(personsOnBoard[row][i]!= null)
{
personsInRow[count]= personsOnBoard[row][i].clone();
count++;
}
}
return personsInRow;
}
 Having some issues with my Vehicle Class PLEASE provide corrected codes

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!