What is the output of the following code?public class Rectangle{ // Instance variables private double length; private double width; // Getters and setters for length and width public double getLength(){ return length; } public void setLength(double length){ this.length = checkData(length); } public double getWidth(){ return width; } public void setWidth(double width){ this.width = checkData(width); } // Constructor public Rectangle(double length, double width){ this.length = checkData(length); this.width = checkData(width); } // Error-checking method public double checkData(double val){ // If value is negative, make it positive if(val < 0) val = val * -1; return val; } public double getArea(){ return length * width; } public double getPerimeter(){ return 2 * (length + width); } public

String getData(){ return "Length: " + this.length + "\nWidth: " + this.width + "\nArea: " + this.getArea() + "\nPerimeter: " + this.getPerimeter(); }}public class MakeRectangles{ public static void main(String[] args){ Rectangle rect1 = new Rectangle(-4.0, 2.0); Rectangle rect2 = new Rectangle(8.0, 6.0); System.out.println("Rectangle 1:\n" + rect1.getData()); System.out.println("Rectangle 2:\n" + rect2.getData()); }}

A. Rectangle 1:
Length: 4.0
Width: 2.0
Area: 8.0
Perimeter: 12.0
Rectangle 2:
Length: 8.0
Width: 6.0
Area: 48.0
Perimeter: 28.0
B. Rectangle 1:
Length: -4.0
Width: 2.0
Area: -8.0
Perimeter: -12.0
Rectangle 2:
Length: 8.0
Width: 6.0
Area: 48.0
Perimeter: 28.0
C. Rectangle 1:
Length: -4.0
Width: 2.0
Area: -8.0
Perimeter: -4.0
Rectangle 2:
Length: 8.0
Width: 6.0
Area: 48.0
Perimeter: 28.0
D. Rectangle 1:
Length: -4.0
Width: 2.0
Area: 8.0
Perimeter: 12.0
Rectangle 2:
Length: 8.0
Width: 6.0
Area: 48.0
Perimeter: 28.0


Answer: A

Computer Science & Information Technology

You might also like to view...

Which of the following arithmetic operations has the highest level of precedence?

(A) +- (B) */ (C) ^ (D) ( )

Computer Science & Information Technology

A(n) ________ is a processor whose elements have been miniaturized into one or a few integrated circuits.

A) Microprocessor B) Motherboard C) Micro controller D) Integrated circuit

Computer Science & Information Technology

________ are used to add predesigned page designs and formats

Fill in the blank(s) with correct word

Computer Science & Information Technology

Which tool is used by an administrator to manage many routers and provide an overall view of all the network?

A. traceroute B. ping C. Network Management System (NMS) D. MTR

Computer Science & Information Technology