Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//debug 2, chapter 11 //java programming, joyce farrell, 8th ed //output 1 // An

ID: 3672479 • Letter: #

Question

//debug 2, chapter 11

//java programming, joyce farrell, 8th ed

//output

1 // An array for different boat types
2 public class DebugEleven2
3 {
4 public static void main(String[] args)
5 {
6 DebugBoat[] ref = FixDebugBoat[3];
7 DebugRowboat blueBoat = DebugRowboat();
8 DebugRowboat redBoat = DebugRowboat();
9 DebugOceanLiner bigBoat = DebugOceanLiner();
10 ref[0] = redBoat;
11 ref[1] = blueBoat;
12 ref[1] = bigBoat;
13 for(int x = 0; x < refLength; ++x)
14 {
15 ref[x].setPassengers();
16 ref[x].setPower();
17 ref[x].toString();
18 }
19 }
20 }
21

==============

1 public abstract class DebugBoat
2 {
3 String boatType = new String();
4 int passengers;
5 String power = new String();
6 public DebugBoat(String bt)
7 {
8 boatType = bt;
9 }
10 // override equals() method to satisfy
11 // requirements of Debug Exercise 3.
12 public boolean equals(DebugBoat otherBoat)
13 {
14 boolean result;
15 if((passengers == otherBoat.passengers) && (power.equals(otherBoat.power)))
16 result = true;
17 else
18 result = false;
19 return result;
20 }
21 public String toString()
22 {
23 return("This " + boatType + "boat carries " + passengers +
24 " and is powered by " + power);
25 }
26 public abstract void setPower();
27 public abstract void setPassengers();
28 }

=================

1 public class DebugOceanLiner extends DebugBoat
2 {
3 public DebugOceanLiner()
4 {
5 Debug("ocean liner ");
6 setPassengers();
7 setPower();
8 }
9 public void setPassengers()
10 {
11 super.passengers = 2400;
12 }
13 public void power()
14 {
15 super.power = "four engines";
16 }
17 }
18

=============

1 public class DebugRowboat extends DebugBoat
2 {
3 public DebugRowboat()
4 {
5 super("row");
6 }
7 public void setPassengers()
8 {
9 super.passengers = 2;
10 }
11 public void setPower()
12 {
13 super.power = "oars";
14 }
15 }

Explanation / Answer

Hi, I have fixed all issues, please find code:


public class DebugEleven2
{
public static void main(String[] args)
{
DebugBoat[] ref =new DebugBoat[3];
DebugRowboat blueBoat = new DebugRowboat();
DebugRowboat redBoat = new DebugRowboat();
DebugOceanLiner bigBoat = new DebugOceanLiner();
ref[0] = redBoat;
ref[1] = blueBoat;
ref[2] = bigBoat;
for(int x = 0; x < ref.length; ++x)
{
ref[x].setPassengers();
ref[x].setPower();
String str = ref[x].toString();
System.out.println(str);
}
}
}

public abstract class DebugBoat
{
String boatType = new String();
int passengers;
String power = new String();
public DebugBoat(String bt)
{
boatType = bt;
}
// override equals() method to satisfy
// requirements of Debug Exercise 3.
public boolean equals(DebugBoat otherBoat)
{
boolean result;
if((passengers == otherBoat.passengers) && (power.equals(otherBoat.power)))
result = true;
else
result = false;
return result;
}
public String toString()
{
return("This " + boatType + "boat carries " + passengers +
" and is powered by " + power);
}
public abstract void setPower();
public abstract void setPassengers();
}

public class DebugOceanLiner extends DebugBoat
{
public DebugOceanLiner()
{
super("ocean liner ");
setPassengers();
setPower();
}
public void setPassengers()
{
super.passengers = 2400;
}
public void power()
{
super.power = "four engines";
}
   @Override
   public void setPower() {
       super.power = "oceanLinear";
      
   }
}

public class DebugRowboat extends DebugBoat
{
public DebugRowboat()
{
super("row");
}
public void setPassengers()
{
super.passengers = 2;
}
public void setPower()
{
super.power = "oars";
}
}

/*

Output:

This rowboat carries 2 and is powered by oars
This rowboat carries 2 and is powered by oars
This ocean liner boat carries 2400 and is powered by oceanLinear

*/