Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

I need help with Car.java I ve attached the instructions as well as the errors I m receiving. PLEASE provide corrected codes if possible. My

I need help with Car.java
Ive attached the instructions as well as the errors Im receiving.
PLEASE provide corrected codes if possible.
My code:
public class Car extends Vehicle implements Comparable, Announcements
{
private int numDoors;
private int numWindows;
public Car(int numDoors, int numWindows)
{
super(2,2);
this.numDoors = numDoors;
this.numWindows = numWindows;
}
public Car(int numDoors, int numWindows, int numSeatsPerRow)
{
super(2, numSeatsPerRow);
this.numDoors = numDoors;
this.numWindows = numWindows;
}
public Car(int numDoors, int numWindows, int [] numSeatsPerRow)
{
super(numSeatsPerRow);
this.numDoors = numDoors;
this.numWindows = numWindows;
}
public Car(int numDoors, int numWindows, Person driver, int [] numSeatsPerRow)
{
super(driver, numSeatsPerRow);
this.numDoors = numDoors;
this.numWindows = numWindows;
}
public boolean canOpenDoor(Person p)
{
if(this.numDoors >=2* super.numberOfRows)
{
Person person = super.getPersonInSeat(0, super.getPeopleInRow(0).length-1);
if(person != null && person.getAge()>5)
{
return true;
}
}
return false;
}
public boolean canOpenWindow(Person p)
{
if(this.numWindows >=2* super.numberOfRows)
{
Person person = super.getPersonInSeat(0, super.getPeopleInRow(0).length-1);
if(person != null && person.getAge()>2)
{
return true;
}
}
return false;
}
public int getNumDoors()
{
return numDoors;
}
public int getNumWindows()
{
return numWindows;
}
public boolean equals(Object o)
{
Car car =(Car) o;
if(car.getNumDoors()== this.numDoors && car.getNumWindows()== this.numWindows)
{
if(car.numberOfRows == this.numberOfRows && car.maxSeatsPerRow == this.maxSeatsPerRow){}
{
for(int i =0; i car.numberOfRows; i++)
{
if(car.getNumberOfPeopleInRow(i)!= this.getNumberOfPeopleInRow(i))
{
return false;
}
}
return true;
}
}
return false;
}
public String toString()
{
String carDetails ="";
carDetails += String.format("number of doors =%02d", this.numDoors);
carDetails += String.format("| number of windows =%02d", this.numWindows);
carDetails += String.format("| number of rows =%02d", super.numberOfRows);
carDetails +="| seats per row ={";
for(int i =0; i super.numberOfRows;i++)
{
Person [] p = super.getPeopleInRow(i);
carDetails += p.length;
if(i super.numberOfRows-1)
{
carDetails +=",";
}
}
carDetails +="}";
for(int i =0; i super.numberOfRows; i++)
{
Person [] p = super.getPeopleInRow(i);
carDetails +="|[";
for(int j =0; j p.length; j++)
{
if(p[j]!= null)
{
if(j !=0)
{
carDetails +=",";
}
carDetails +=""+ p[j].getName()+"";
}
}
carDetails +="]";
}
return carDetails;
}
public int compareTo(Car c)
{
Person [][] p1= c.personsOnBoard;
Person [][] p2= this.personsOnBoard;
int totalNumberOfSeats =0;
int totalNumberOfSeatsPassed =0;
for(int i =0; i p1.length; i++)
{
totalNumberOfSeats += p1[i].length;
}
for(int j =0; j p2.length; j++)
{
totalNumberOfSeatsPassed += p2[j].length;
}
if(totalNumberOfSeats totalNumberOfSeatsPassed)
{
return -1;
}
else
{
if(totalNumberOfSeats > totalNumberOfSeatsPassed)
{
return 1;
}
else
{
return 0;
}
}
}
@Override
public String departure()
{
return "All Aboard
";
}
@Override
public String arrival()
{
return "Everyone Out
";
}
@Override
public String doNotDisturbTheDriver()
{
return "No Breakseat Driving
";
}
@Override
public boolean loadPassenger(Person p)
{
if(p.getAge()>=5 && p.getHeight()>=36)
{
for(int i =0; i super.numberOfRows; i++)
{
if(super.getNumberOfAvailableSeatsInRow(i)!=0)
{
super.personsOnBoard[i][super.getNumberOfPeopleInRow(i)]= p;
return true;
}
}
}
return false;
}
@Override
public int loadPassengers(Person[] peeps)
{
int count =0;
for(int i =0; i peeps.length; i++)
{
if(this.loadPassenger(peeps[i])== true)
{
count++;
}
}
return count;
}
}
image text in transcribed

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

Question

What are the role of supervisors ?

Answered: 1 week ago