0%
0 / 7 answered

Expressions and Output() Practice Test

7 Questions
Question
1 / 7
Q1

public class Rectangle {

private double length;

private double width;



public Rectangle(double l, double w) {

    length = l;

    width = w;

}



public double getArea() {

    return length * width;

}



public double getPerimeter() {

    return 2 * (length + width);

}



public void scale(double factor) {

    length *= factor;

    width *= factor;

}

}

Consider the following code segment that uses the Rectangle class shown above:

Rectangle rect = new Rectangle(4.0, 6.0);

double original = rect.getArea();

rect.scale(1.5);

double scaled = rect.getArea();

System.out.println(scaled / original);

What is printed as a result of executing this code segment?

Question Navigator