please debug these programes //DebugBoat.java //Teacher Notation //CAREFUL ----
ID: 3772918 • Letter: P
Question
please debug these programes
//DebugBoat.java
//Teacher Notation
//CAREFUL ---- Must be compiled before DebugEleven1.java is compiled and run!!
public abstract class DebugBoat
{
String boatType = new String();
int passengers;
String power = new String();
public FixDebugBoat(String bt)
{
boatType = bt;
}
public String toString()
{
return("This " + boatType +"boat carries " + passengers + " and is powered by " + power);
}
public abstract void setPower()
public abstract void setPassengers()
}
//DebugRowBoat.java
//Teacher Notation
//CAREFUL ---- Must be compiled before DebugEleven1.java is compiled and run!!
public class DebugRowboat extends DebugBoat
{
public DebugRowboat()
{
super("row");
}
public void setPassengers()
{
passengers=2;
}
public void setPower()
{
super.power ="oars";
}
}
//DebugEleven1.java
// Instantiates Rowboat
// Rowboat is child of Boat
public class DebugEleven1
{
public static void main(String [ ] args)
{
DebugRowboat myBoat = DebugRowboat();
System.out.println(myBoat.tostring());
}
/DebugOceanLiner.java
//Teacher Notation
//CAREFUL ---- Must be compiled before DebugEleven2.java is compiled and run!!
public class DebugOceanLiner extends DebugBoat
{
public DebugOceanLiner()
{
super("ocean liner ");
setPassengers;
setPower;
}
public void setPassengers()
{
super.passengers=2400;
}
public void setPower()
{
super.power = four engines ;
}
}
//DebugEleven2.java
// An array for different boat types
public class xDebugEleven2
{
public static void main(String[] args)
{
DebugBoat[] ref = new FixDebugBoat[3];
DebugRowboat blueBoat = DebugRowboat();
DebugRowboat redBoat = DebugRowboat();
DebugOceanLiner bigBoat = xDebugOceanLiner();
ref[0] = redboat;
ref[1] = greenBoat;
ref[2] = bigBoat;
for(int x = 0; x < ref.length; ++x)
{
ref[x]setPassengers();
ref[x].setPower;
}
}
}
//DebugEleven3.java
// Two boats should be equal
// if they hold the same number of passengers
// and have the same power source
public class DebugEleven3
{
public static void main(String args[])
{
DebugRowboat redBoat = new DebugRowboat();
DebugRowboat blueBoat = new DebugRowboat();
System.out.print("The two boats are");
if(redBoat = blueBoat)
System.out.println(" equal");
else
System.out.println(" not equal);
}
}
//DebugEleven4.java
// Creates and displays an array of boats -
// some are rowboats; some are ocean liners
import javax.swing.*;
public class DebugEleven4
{
static DebugBoat [] boatArray = new DebugBoat [5];
public static void main(String[] args)
{
buildArray();
displayArray();
}
public static void buildArray()
{
char boatType;
for(x=0; x < boatArray.length; x++)
{
boatType = getBoat();
if (boatType == 'r')
boatArray[x] = DebugRowboat();
else
boatArray[x] = DebugOceanLiner();
}
}
public static char getBoat()
{
string boatType;
boatType = JOptionPane.showInputDialog(null,
"Enter r for rowboat; o for ocean liner ");
return boatType.charAt(0);
}
public static void displayArray()
{
for(x = 0; x < boatArray.length; x)
JOptionPane.showMessageDialog(null, "Boat #" + (x + 1) +
boatArray[x].toString());
}
}
Explanation / Answer
/please debug these programes
//DebugBoat.java
//Teacher Notation
//CAREFUL ---- Must be compiled before DebugEleven1.java is compiled and run!!
abstract class DebugBoat
{
String boatType = new String();
int passengers;
String power = new String();
public DebugBoat(String bt)
{
boatType = bt;
}
public String toString()
{
return("This " + boatType +"boat carries " + passengers + " and is powered by " + power);
}
public abstract void setPower();
public abstract void setPassengers();
}
//DebugRowBoat.java
//Teacher Notation
//CAREFUL ---- Must be compiled before DebugEleven1.java is compiled and run!!
class DebugRowboat extends DebugBoat
{
public DebugRowboat()
{
super("row");
}
public void setPassengers()
{
passengers=2;
}
public void setPower()
{
super.power ="oars";
}
}
//DebugEleven1.java
// Instantiates Rowboat
// Rowboat is child of Boat
public class DebugEleven1
{
public static void main(String [ ] args)
{
DebugRowboat myBoat =new DebugRowboat();
System.out.println(myBoat.toString());
}
}
//DebugOceanLiner.java
//Teacher Notation
//CAREFUL ---- Must be compiled before DebugEleven2.java is compiled and run!!
public class DebugOceanLiner extends DebugBoat
{
public DebugOceanLiner()
{
super("ocean liner ");
setPassengers();
setPower();
}
public void setPassengers()
{
super.passengers=2400;
}
public void setPower()
{
super.power = "four engines" ;
}
}
//DebugEleven2.java
// An array for different boat types
public class DebugEleven2
{
public static void main(String[] args)
{
DebugBoat[] ref = new FixDebugBoat(3);
DebugRowboat blueBoat =new DebugRowboat();
DebugRowboat redBoat = new DebugRowboat();
DebugOceanLiner bigBoat = xDebugOceanLiner();
ref[0] = redboat;
ref[1] = greenBoat;
ref[2] = bigBoat;
for(int x = 0; x < ref.length; ++x)
{
ref[x].setPassengers();
ref[x].setPower();
}
}
}
//DebugEleven3.java
// Two boats should be equal
// if they hold the same number of passengers
// and have the same power source
public class DebugEleven3
{
public static void main(String args[])
{
DebugRowboat redBoat = new DebugRowboat();
DebugRowboat blueBoat = new DebugRowboat();
System.out.print("The two boats are");
if(redBoat == blueBoat)
System.out.println(" equal");
else
System.out.println(" not equal");
}
}
//DebugEleven4.java
// Creates and displays an array of boats -
// some are rowboats; some are ocean liners
public class DebugEleven4
{
static DebugBoat [] boatArray = new DebugBoat [5];
public static void main(String[] args)
{
buildArray();
displayArray();
}
public static void buildArray()
{
char boatType;
for(x=0; x < boatArray.length; x++)
{
boatType = getBoat();
if (boatType == 'r')
boatArray[x] = DebugRowboat();
else
boatArray[x] = DebugOceanLiner();
}
}
public static char getBoat()
{
string boatType;
boatType = JOptionPane.showInputDialog(null,
"Enter r for rowboat; o for ocean liner ");
return boatType.charAt(0);
}
public static void displayArray()
{
for(x = 0; x < boatArray.length; x++)
JOptionPane.showMessageDialog(null, "Boat #" + (x + 1) +
boatArray[x].toString());
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.