Question

In: Computer Science

The following program supposes to calculate the area of a rectangle and square. Then, produce the...

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

Area of Rectangle:
50

Unfortunately, the program has compile-time and run-time errors that prevent the program from running and producing the correct result. Using table 3.1 below, allocate the error(s) on each program line.

1 public class RectangleArea {  
2   Public static void main() {  
3     int width == 10;
4     int height = 5;
5     int recArea = width + height;
6      System.Out.print(Area of Rectangle:);
7      System.out.println(“recArea”)
8     
9

Note:

Some of the answers are given to you as an example.

Table 3.1: compile-time / run-time error

Line No

compile-time / run-time error

1

No error

2

Error.

  1. Public should be public
  2. Missing main methods parameters String args[]

3

4

5

6

7

8

9

Solutions

Expert Solution

Here is the correct program that will print the output to the screen as defined in the question.

public class RectangleArea {  
  public static void main(String args[]) {  
    int width = 10;
    int height = 5;
    int recArea = width * height;
System.out.println("Area of Rectangle:");
   System.out.println(recArea);
  }
}

SCREENSHOT OF THE OUTPUT AND THE CODE :

ERROR IN YOUR PROGRAM WITH EXPLIANATION:

public class RectangleArea {  
Public static void main() { //This line encounters an error as the keyword public "P" should be small and the //String args[ ] statement is missing here.
int width == 10; //here we need to assign but not to the compare but we are using comparision operators.So we // need to use assigment operator "=".
int height = 5; //here no error
int recArea = width + height; //here we need to use the formula(l*b) but (l+b) will not result ot the area.
System.Out.print(Area of Rectangle:); //here the syntax is not correct and the correct syntax is //"System.out.println" and also there is no variable Area of Rectangle //and we need to write it in " " as it will print to the output.
System.out.println(“recArea”) //here we show not use " " as we need to print the value of the //variable. and termination "semicolon " is missing here.
//and the cosing braces need to be here there should be 2 closing braces.


Related Solutions

Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The...
Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The program to present the user with a menu where one of the shapes can be selected. Based on the selection made, the user enters the proper input, the program validates the input (i.e all entries must be greater than zero). Once the input is entered and validated, the intended area is calculated and the entered information along with the area are displayed. Area of...
REQUIREMENTS OF THE JAVA PROGRAM: Your task is to calculate geometric area for 3 shapes(square, rectangle...
REQUIREMENTS OF THE JAVA PROGRAM: Your task is to calculate geometric area for 3 shapes(square, rectangle and circle). 1. You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input a. Invalid input should throw a message for the user. Example: Invalid input, please try again 2. Each options should ask users for relevant data....
JAVA program: Calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a...
JAVA program: Calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input Invalid input should throw a message for the user. Example: Invalid input, please try again Each options should ask users for relevant data. HINT: use scanner object to take in length for square,...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user to input the length and width. Calculate the area as length * width. Calculate the perimeter as 2* length + 2* width. Display the area and perimeter. Please use a proper heading in a comment block (name, date, description of the program). Please use comments in your code. Run your program twice using different input. Copy the output and place it at the bottom...
The area of a particular rectangle is 12 times the area of a certain square, and...
The area of a particular rectangle is 12 times the area of a certain square, and the width of the rectangle is three times the length of a side of the square. The perimeter of the rectangle is 30 units greater than the perimeter of the square. Find the dimensiuons of both the rectangle and the square.
a function named area to calculate the area of a rectangle area = Length x width...
a function named area to calculate the area of a rectangle area = Length x width 2.a function named volume to calculate the volume of a sphere volume = 4/3 x 3.14 x radius x radius x radius 3.a function named volume to calculate the volume of a cuboid volume = Length x width x ht 4. Use a loop structure to calculate the sum of all odd numbers from 1 to 17 5) Use a loop structure to calculate...
Q 1 - The surface area of a square or rectangle can be determined by multiplying...
Q 1 - The surface area of a square or rectangle can be determined by multiplying the length by the breadth. In a method called GetArea(), write a Java program to determine the surface area of a given square or rectangle. Assume the measurements will be in metres. The program should prompt the user for length and breadth values. [15] Input None Output Given a rectangle with length 20 metres and breadth 15 metres, the output would be: 300 square...
The rectangle below is made up of 12 squares of the same size. Find the perimeter of the rectangle if the area of the rectangle is equal to 1728 square cm.
The rectangle below is made up of 12 squares of the same size. Find the perimeter of the rectangle if the area of the rectangle is equal to 1728 square cm.
If the area of a square is 25 square feet, calculate the perimeter of the
If the area of a square is 25 square feet, calculate the perimeter of the square. Enter the value for the perimeter in the first blank and enter the units in the second. Enter units as ft. or square ft. Round your final answer to tenths if rounding is necessary ? 
using C# Write a program named RectangleArea tocalculate the area of a rectangle with a...
using C# Write a program named RectangleArea to calculate the area of a rectangle with a length of 15.8 and a width of 7.9. The program should have two classes, one is theRectangleArea holding the Main(), and the other one is Rectangle. The Rectangleclass has three members: a property of length, a property of width, and a method with a name of CalArea() to calculate the area. You can invoke the auto-provided constructor or write a self-defined constructor to initialize...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT