Question

In: Computer Science

The files provided contain syntax and/or logic errors. In each case, determine and fix the problem,...

The files provided contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly.

3.

public abstract class DebugBoat

{

   String boatType = new String();

   int passengers

   String power = new String();

   public FebugBoat(String bt)

   {

      boatType = bt;

   }

   public boolean equals(otherBoat)

   {

      boolean result;

      if((passengers == otherBoat.passengers) && (power.equals(otherBoat.power)))

         result = true;

      else

         result = true;

      return result

   }

   public String toString()

   {

      return("This " + boatType + "boat carries " + passengers +

        " and is powered by + power);

   }

   public abstract void setPower();

   public abstract void setPassengers();

}

// Two boats should be equal

// if they hold the same number of passengers

// and also 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

     (" not equal");

   }

}

public class DebugRowboat extends DebugBoat

{

   public DebugRowboat()

   {

      super("row");

      setPower();

   }

   public void setPassengers()

   {

      super.passengers = 2;

   }

   public void setpower()

   {

      super.power = "oars";

   }

}

4.

public abstract class DebugBoat

{

   String boatType = new String();

   int passengers

   String power = new String();

   public FebugBoat(String bt)

   {

      boatType = bt;

   }

   public boolean equals(otherBoat)

   {

      boolean result;

      if((passengers == otherBoat.passengers) && (power.equals(otherBoat.power)))

         result = true;

      else

         result = true;

      return result

   }

   public String toString()

   {

      return("This " + boatType + "boat carries " + passengers +

        " and is powered by + power);

   }

   public abstract void setPower();

   public abstract void setPassengers();

}

// Creates and displays an array of boats -

// some are rowboats; some are ocean liners

import java.util.*;

public class DebugEleven4

{

   static Scanner input = new Scanner(System.in);

   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] = new DebugOceanLiner();

     }

   }

   public static char getBoat()

   {

      String boatType;

      System.out.println("Enter r for rowboat; o for ocean liner ");

      boatType = input.next();

        

      return boatType.charAt(0);

   }

   public static void displayArray()

   {

      for(int x = 0; x < boatArray.length)

      System.out.println("Boat #" + (x + 1) + " " +

         boatArray[x].toString());

   }

}

public class DebugOceanLiner extends DebugBoat

{

   public DebugOceanLiner()

   {

      super("ocean liner ");

      setPassengers();

  }

   public void setPassengers()

   {

      super.passengers = 2400;

   }

   public void setPower()

   {

      superpower = "four engines";

   }

}

public class DebugRowboat extends DebugBoat

{

   public DebugRowboat()

   {

      super("row");

      setPower();

   }

   public void setPassengers()

   {

      super.passengers = 2;

   }

   public void setpower()

   {

      super.power = "oars";

   }

}

Solutions

Expert Solution

3.CODE:

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 = true;

      return result;

   }

   public String toString()

   {

      return("This " + boatType + "boat carries " + passengers + " and is powered by " + power);

   }

   public abstract void setPower();

   public abstract void setPassengers();

}

// Two boats should be equal

// if they hold the same number of passengers

// and also 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.equals(blueBoat))

         System.out.println(" equal");

      else

        System.out.println(" not equal");

   }

}

class DebugRowboat extends DebugBoat

{

   public DebugRowboat()

   {

      super("row");

      setPower();

   }

   public void setPassengers()

   {

      super.passengers = 2;

   }

   public void setPower()

   {

      super.power = "oars";

   }

}

4. CODE:

import java.util.*;
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 = true;

      return result;

   }

   public String toString()

   {

      return("This " + boatType + "boat carries " + passengers + " and is powered by "+ power);

   }

   public abstract void setPower();

   public abstract void setPassengers();

}

// Creates and displays an array of boats -

// some are rowboats; some are ocean liners

public class DebugEleven4

{

   static Scanner input = new Scanner(System.in);

   static DebugBoat[] boatArray = new DebugBoat[5];

   public static void main(String[] args)

   {

      buildArray();

      displayArray();

   }

   public static void buildArray()

   {

     char boatType;

     for(int x = 0; x < boatArray.length; ++x)

     {

        boatType = getBoat();

        if(boatType =='r')

         boatArray[x] = new DebugRowboat();

        else

          boatArray[x] = new DebugOceanLiner();

     }

   }

   public static char getBoat()

   {

      String boatType;

      System.out.println("Enter r for rowboat; o for ocean liner ");

      boatType = input.next();

      

      return boatType.charAt(0);

   }

   public static void displayArray()

   {

      for(int x = 0; x < boatArray.length; x++)

      System.out.println("Boat #" + (x + 1) + " " +

         boatArray[x].toString());

   }

}

class DebugOceanLiner extends DebugBoat

{

   public DebugOceanLiner()

   {

      super("ocean liner ");

      setPassengers();

}

   public void setPassengers()

   {

      super.passengers = 2400;

   }

   public void setPower()

   {

      super.power = "four engines";

   }

}

class DebugRowboat extends DebugBoat

{

   public DebugRowboat()

   {

      super("row");

      setPower();
      setPassengers();
   }

   public void setPassengers()

   {

      super.passengers = 2;

   }

   public void setPower()

   {

      super.power = "oars";

   }

}


Related Solutions

The files provided in the code editor to the right contain syntax and/or logic errors. In...
The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. DebugBox.java public class DebugBox { private int width; private int length; private int height; public DebugBox() { length = 1; width = 1; height = 1; } public DebugBox(int width, int length, height) { width = width; length = length; height =...
The files provided in the code editor to the right contain syntax and/or logic errors. In...
The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. Please Fix code and make Copy/Paste avaliable // Application allows user to enter a series of words // and displays them in reverse order import java.util.*; public class DebugEight4 {    public static void main(String[] args)    {       Scanner input = new Scanner(System.in);       int...
Each of the following files in the Chapter15 folder of your downloadable student files has syntax and/or logic errors.
Each of the following files in the Chapter15 folder of your downloadable student files has syntax and/or logic errors. In each case, determine the problem and fix the program. After you correct the errors, save each file using the same filename preceded with Fix. For example, DebugFifteen1.java will become FixDebugFifteen1.java. a. DebugFifteen1.java b. DebugFifteen2.java c. DebugFifteen3.java d. DebugFifteen4.java    
C++ : Find the syntax errors in the following program. For each syntax error, fix it...
C++ : Find the syntax errors in the following program. For each syntax error, fix it and add a comment at the end of the line explaining what the error was. #include <iostream> #include <cmath> using namespace std; int main(){ Double a, b, c; 2=b; cout<<"Enter length of hypotenuse"<<endl; cin>>c>>endl; cout>>"Enter length of a side"<<endl; cin>>a; double intermediate = pow(c, 2)-pow(a, 2); b = sqrt(intermediate); cout<<"Length of other side is:" b<<endline; return 0; }
The following code segment which uses pointers may contain logic and syntax errors. Find and correct...
The following code segment which uses pointers may contain logic and syntax errors. Find and correct them. a) Returns the sum of all the elements in summands int sum(int* values) { int sum = 0; for (int i = 0; i < sizeof(values); i++) sum += *(values + i); return sum; } b) Overwrites an input string src with "61C is awesome!" if there's room. Does nothing if there is not. Assume that length correctly represents the length of src....
Part 1: Find and fix errors and add following functionalities 1. There are several syntax errors...
Part 1: Find and fix errors and add following functionalities 1. There are several syntax errors in the code that are preventing this calculator from working, find and fix those errors. When they are fixed, the number buttons will all work, as well as the + (add) and -- (decrement) buttons. a. To find the errors, open up the Developers Tool of the browser and look at the console (F12). Verify the add functionality works. For a binary operator, you...
Please identify each error present, explain the type of error (syntax/logic/run-time), and provide a fix which...
Please identify each error present, explain the type of error (syntax/logic/run-time), and provide a fix which changes the given code as little as possible (i.e. don't rewrite the whole thing; just point out what is wrong and a fix for it). 5) // Assign a grade based on the score char score; cin>>score; if score < 0 && score > 100     cout<<"The score entered is invalid"<<endl; if (score <= 90)     grade = "A"; if (score <= 80)    ...
To earn full credit, program must be free of syntax, run-time, and logic errors; include program...
To earn full credit, program must be free of syntax, run-time, and logic errors; include program comments; use reasonable readable variable names and prompts. To include variables in the input prompt, you must use concatenation character (+). For example: assume you already asked for input of employee's first name and last name (they are stored into variables FirstName and LastName, then use this prompt to ask for employee's weekly hours which includes the employee's full name in the input statement....
The number of errors in each of 300 files has a Poisson distribution with 1.4 errors...
The number of errors in each of 300 files has a Poisson distribution with 1.4 errors per file on average. Assume the errors in different files are independent. Use the Central Limit Theorem to approximate the probability that the total number of errors is at least 400. (Use a calculator.)
Please use C++. You will be provided with two files. The first file (accounts.txt) will contain...
Please use C++. You will be provided with two files. The first file (accounts.txt) will contain account numbers (10 digits) along with the account type (L:Loan and S:Savings) and their current balance. The second file (transactions.txt) will contain transactions on the accounts. It will specifically include the account number, an indication if it is a withdrawal/deposit and an amount. Both files will be pipe delimited (|) and their format will be the following: accounts.txt : File with bank account info...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT