Question: Debug Java I've gotten the code to run; But in Cengage it says there's something wrong in the DebugRowboat class and the DebugEleven2 class The
Debug Java
I've gotten the code to run; But in Cengage it says there's something wrong in the DebugRowboat class and the DebugEleven2 class
The details say:
DebugRowboat
Custom TestIncomplete
Fix all logic and syntax errors in the DebugRowboat class
Test Output
AssertionError: The `DebugRowboat` class contains a logic error. Double check the constructor to make sure it is setting the number of passengers.
Test Contents
import sys sys.tracebacklimit = 0 with open('/root/sandbox/DebugRowboat.java', 'r') as f: contents = "" for line in f.readlines(): contents += line assert "setPassengers();" in contents, "The `DebugRowboat` class contains a logic error. Double check the constructor to make sure it is setting the number of passengers." assert "setpower()" not in contents, "There is a naming convention issue with the `setPower()` method." assert "setPower()" in contents, "There is a naming convention issue with the `setPower()` method."
----
DebugEleven2
1 out of 2 checks passed. Review the results below for more details.
Checks
Custom TestComplete
Fix all logic and syntax errors in the DebugEleven2 class
Test Output
Test Contents
import re import sys sys.tracebacklimit = 0 with open('/root/sandbox/DebugEleven2.java', 'r') as f: contents = "" for line in f.readlines(): contents += line keyword_count = contents.count('new') match = re.findall("int\sx", contents) assert keyword_count >= 3, "There are syntax errors with the `DebugRowboat` and `DebugOceanLiner` initializations." assert len(match) == 1, "There is a syntax error in the `for` loop." assert "ref.toString()" not in contents, "There is a syntax error within the print statement." assert "ref[x].toString()" in contents, "There is a syntax error within the print statement."Test Case Incomplete
The DebugEleven2 program runs without issue and works as expected
Input
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
Results
This rowboat carries 2 and is powered by oars
This ocean liner boat carries 2400 and is powered by four engines
Expected Output
This rowboat carries 2 and is powered by oars
This ocean liner boat carries 2400 and is powered by four engines
------------------------------------------------------------------------------------------------------------------------
Screenshot:

code to copy:
public abstract class DebugBoat
{
String boatType = new String();
int passengers;
String power = new String();
public DebugBoat(String bt)
{
boatType = bt;
}
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();
}
-----------
// An array for different boat types
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[x].setPassengers();
ref[x].setPower();
String str = ref[x].toString();
System.out.println(str);
}
}
}
------
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";
}
}
Debugging Exercise 11-2 Tasks Debug Boat.java DebugEleven2.java DebugOceanLine... DebugRowboat.ja... + >_ Terminal + Fix all logic and syntax errors in the ... > Fix all logic and syntax errors in the ... > sandbox $ rm -f * class sandbox $ sandbox $ sandbox $ javac DebugBoat.java DebugEleven2. java DebugOceanLiner.java DebugRowboat.java sandbox $ java DebugEleven2 This rowboat carries 2 and is powered by oar s This rowboat carries 2 and is powered by oar > Fix all logic and syntax errors in the Debugowboat class. S This ocean liner boat carries 2400 and is po wered by oceanLinear sandbox $ > Fix all logic and syntax errors in the DebugEleven2 class. 1 public abstract class DebugBoat 21 3 String boatType = new String(); 4 int passengers; 5 String power = new String(); 6 public DebugBoat(string bt) 7 { 8 boatType = bt; 9} 10 11 public boolean equals(DebugBoat otherBoat) 12 { 13 boolean result; 14 if((passengers == otherboat.passengers) && (power.equals(otherBoat.power))) 15 result = true; 16 else 17 result = false; 18 return result; 19 ) 20 public String toString() 21 { 22 return("This " + boat Type + "boat carries" + passengers + 23 " and is powered by " + power); 24 } 25 public abstract void setPower(); 26 public abstract void setPassengers(); 27 } 28 89 Run Checks Submit 68%
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
