Question

The following program supposes to calculate the area of a rectangle and produce the following output....

The following program supposes to calculate the area of a rectangle and produce the following output. Area of rectangle = 20 Unfortunately, the program has Compile-time and Run-time errors that prevent the program from running and producing the correct result. Using the table 2.1 below, allocate the error(s) on each program line. 1 class Rectangle{ 2 int length 3 Int width; 4 viod insert(int l, int w){ 5 length == l; 6 width = ww; 7 8 void calculateArea( { 9 System.out.println("Area of rectangle = "+ length / width);} 10 } 11 class TestRectangle1{ 12 public void main(String args[]){ 13 Rectangle r1 = Rectangle(); 14 r.insert(5,4); 15 r1.calculatearea(); 16 }} 17 }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

JAVA CODE after removal of errors

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

package hello;

class Rectangle{
   int length;
   int width;
   void insert(int l, int w)
   {
       length = l;
       width = w;
   }
   void calculateArea()
   {
       System.out.println("Area of rectangle = "+ length*width);
   }
}

public class TestRectangle1 {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Rectangle r1 = new Rectangle();
       r1.insert(5,4);
       r1.calculateArea();
   }

}

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

Output

Add a comment
Know the answer?
Add Answer to:
The following program supposes to calculate the area of a rectangle and produce the following output....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Modify the code to create a class called box, wherein you find the area. I...

    JAVA Modify the code to create a class called box, wherein you find the area. I have the code in rectangle and needs to change it to box. Here is my code. Rectangle.java public class Rectangle { private int length; private int width;       public void setRectangle(int length, int width) { this.length = length; this.width = width; } public int area() { return this.length * this.width; } } // CONSOLE / MAIN import java.awt.Rectangle; import java.util.Scanner; public class Console...

  • My assignment is to create a rectangle class in java. •Create a MyRectangleClass •There are two...

    My assignment is to create a rectangle class in java. •Create a MyRectangleClass •There are two private instance variables, length l and width w with double data type. •There is a constructor with two parameter •There are 4 public methods which are circumference, area, getWidth, and getLength. •circumference method will return circumference to the caller.(the formula for circumference is 2 *l + 2*w ) •Area method Return the area to the caller(:l*w) •getLength method will return length to the caller....

  • // This program uses the programmer-defined Rectangle class. #include "Rectangle.cpp" #include <iostream> using namespace std; int...

    // This program uses the programmer-defined Rectangle class. #include "Rectangle.cpp" #include <iostream> using namespace std; int main() {    Rectangle rectangle1;    Rectangle rectangle2;    rectangle1.setLength(10.0);    rectangle1.setWidth(5.0);    rectangle2.setLength(7.0);    rectangle2.setWidth(3.0);    cout << "Perimeter of rectangle1 is " << rectangle1.calculatePerimeter() << endl;    cout << "Area of rectangle1 is " << rectangle1.calculateArea() << endl;    cout << "Perimeter of rectangle2 is " << rectangle2.calculatePerimeter() << endl;    cout << "Area of rectangle2 is " << rectangle2.calculateArea() << endl;...

  • package rectangle; public class Rectangle {    private int height;    private int width;    public...

    package rectangle; public class Rectangle {    private int height;    private int width;    public Rectangle(int aHeight, int aWidth) {    super();    height = aHeight;    width = aWidth;    }    public int getHeight() {    return height;    }    public int getWidth() {    return width;    }    public void setHeight(int aHeight) {    height = aHeight;    }    public void setWidth(int aWidth) {    width = aWidth;    }    public int...

  • In Lab 5, you completed the MyRectangle class, which is a simple representation of a rectangle....

    In Lab 5, you completed the MyRectangle class, which is a simple representation of a rectangle. Review Lab 5 before completing this lab and retrieve the MyRectangle class that you completed for this lab, since you will need it again in this lab. Before starting this lab, edit your MyRectangle class in the following way: • change the declaration of your instance variables from private to protected This will enable access of these variables by your MySquare subclass. Here is...

  • Question: Modify the Rectangle and Box classes that are below, so that they implement the Comparable...

    Question: Modify the Rectangle and Box classes that are below, so that they implement the Comparable interface. The compareTo() method shall compare rectangles and boxes by areas and volumes. In main(), create an ArrayList of rectangles and an ArrayList of boxes. Randomly generate ten rectangles and ten boxes adding to the two ArrayLists. Use Collections.sort() to sort the two ArrayLists, respectively. Print the ArrayLists before and after being sorted. Three classes that need to be edited are below: Main class,...

  • Find the errors in the following program. You must use pass by reference. #include <iostream> using...

    Find the errors in the following program. You must use pass by reference. #include <iostream> using namespace std; void area2(int area, int length, int width = 0); int main() { int length, width, area; // for rectangle use two arguments cout << "Enter length and width of a rectangle" << endl; cin >> length >> width; cout << "The area is " << area2(area, length, width) << endl; // for squares use one argument cout << "Enter side of a...

  • I have this program: It passes on certain test cases. The Demo five has the %.1f...

    I have this program: It passes on certain test cases. The Demo five has the %.1f to cut down the number to one decimal place. But I get a failed attempt such as: Enter length: \n Enter width: \n You entered: 87.3, 2.0, and 174.7\n -- Rectangle info --\n Length: 87.34\n Width: 2.0\n Area: 174.68\n And I know it is because the length and area both have 2 decimal places. Could you help me fix this? Thank you. Program Content:...

  • JAVA: Write a program that prints a rectangle with a border of asterisks (*). Prompt the...

    JAVA: Write a program that prints a rectangle with a border of asterisks (*). Prompt the user for the width and height of the rectangle. For example: Enter the width and the height of our box. 3 5 *** * * * * * * *** import java.util.Scanner; public class DrawBox { public static void main(String[] args) { Scanner in = new Scanner(System.in);        System.out.println("Enter the width and the height of our box."); /* Type your code here. */...

  • Why is my program returning 0 for the area of a triangle? public class GeometricObjects {...

    Why is my program returning 0 for the area of a triangle? public class GeometricObjects {    private String color = " white ";     private boolean filled;     private java.util.Date dateCreated;     public GeometricObjects() {         dateCreated = new java.util.Date();     }     public GeometricObjects(String color, boolean filled) {         dateCreated = new java.util.Date();         this.color = color;         this.filled = filled;     }     public String getColor() {         return color;     }     public void setColor(String color)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT