Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This quiz uses the three classes below. Watch out for bugs! public class Trapezo

ID: 3791559 • Letter: T

Question

This quiz uses the three classes below. Watch out for bugs!

public class Trapezoid {
private double height, width, base;

public Trapezoid(double h, double w, double b) {
setHeight(h);
setWidth(w);
setBase(b);
}

public double getHeight() { return height; }
public double getWidth() { return width; }
public double getBase() { return base; }

public void setHeight(double h) { height = h; }
public void setWidth(double w) { width = w; }
public void setBase(double b) { base = b; }

public double area() {
return getHeight() * (getWidth() + getBase()) / 2;
}

public double perimeter() {
return 2 * getHeight() + getWidth() + getBase();
}
}


public class Rectangle extends Trapezoid {
public Rectangle(double h, double w) {
super(h, w, w);
}

public double area() { return getHeight() * getWidth(); }
}


public class Square extends Rectangle {
public Square(double w) {
super(w, w);
}

public double area() { return getWidth() * getWidth(); }
}

QUESTION 11

What is output by the following code?

Rectangle r = new Rectangle(4, 6);
r.setBase(8);
double a = r.area();
double p = r.perimeter();
System.out.print(a + " " + p);

5 points   

QUESTION 12

What is output by the following code?

Square s = new Square(6);
s.setBase(8);
double a = s.area();
double p = s.perimeter();
System.out.print(a + " " + p);

5 points   

QUESTION 13

What is output by the following code?

Trapezoid t = new Trapezoid(1, 1, 1);
t.setHeight(6);
t.setWidth(4);
t.setBase(2);
double a = t.area();
double p = t.perimeter();
System.out.print(a + " " + p);

5 points   

QUESTION 14

What is output by the following code?

Trapezoid t = new Rectangle(1, 1);
t.setHeight(6);
t.setWidth(4);
t.setBase(2);
double a = t.area();
double p = t.perimeter();
System.out.print(a + " " + p);

5 points   

QUESTION 15

What is output by the following code?

Trapezoid t = new Square(1);
t.setHeight(6);
t.setWidth(4);
t.setBase(2);
double a = t.area();
double p = t.perimeter();
System.out.print(a + " " + p);

5 points   

QUESTION 16

What is output by the following code?

Trapezoid t = new Trapezoid(1, 1, 1);
Rectangle r = new Rectangle(2, 2);
Square s = new Square(3);
double a1 = t.area();
double a2 = r.area();
double a3 = s.area();
System.out.print(a1 + " " + a2 + " " + a3);

5 points   

QUESTION 17

What is output by the following code?

Trapezoid t = new Trapezoid(1, 1, 1);
Rectangle r = new Rectangle(2, 2);
Square s = new Square(3);
r = s;
double a1 = t.area();
double a2 = r.area();
double a3 = s.area();
System.out.print(a1 + " " + a2 + " " + a3);

5 points   

QUESTION 18

What is output by the following code?

Trapezoid t = new Trapezoid(1, 1, 1);
Rectangle r = new Rectangle(2, 2);
Square s = new Square(3);
t = s;
double a1 = t.area();
double a2 = r.area();
double a3 = s.area();
System.out.print(a1 + " " + a2 + " " + a3);

5 points   

QUESTION 19

What is output by the following code?

Trapezoid t = new Trapezoid(1, 1, 1);
Rectangle r = new Rectangle(2, 2);
Square s = new Square(3);
t = r;
r = s;
double a1 = t.area();
double a2 = r.area();
double a3 = s.area();
System.out.print(a1 + " " + a2 + " " + a3);

5 points   

QUESTION 20

What is output by the following code?

Trapezoid t = new Trapezoid(1, 1, 1);
Rectangle r = new Rectangle(2, 2);
Square s = new Square(3);
r = s;
t = r;
double a1 = t.area();
double a2 = r.area();
double a3 = s.area();
System.out.print(a1 + " " + a2 + " " + a3);

Explanation / Answer

Hi,

Please find the answers:

QUESTION 11
What is output by the following code?
Rectangle r = new Rectangle(4, 6);
r.setBase(8);
double a = r.area();
double p = r.perimeter();
System.out.print(a + " " + p);

Output: 24.0 22.0
  
QUESTION 12
What is output by the following code?
Square s = new Square(6);
s.setBase(8);
double a = s.area();
double p = s.perimeter();
System.out.print(a + " " + p);

Output: 36.0 26.0
  
QUESTION 13
What is output by the following code?
Trapezoid t = new Trapezoid(1, 1, 1);
t.setHeight(6);
t.setWidth(4);
t.setBase(2);
double a = t.area();
double p = t.perimeter();
System.out.print(a + " " + p);

Output: 18.0 18.0
  
QUESTION 14
What is output by the following code?
Trapezoid t = new Rectangle(1, 1);
t.setHeight(6);
t.setWidth(4);
t.setBase(2);
double a = t.area();
double p = t.perimeter();
System.out.print(a + " " + p);

Output: 24.0 18.0

QUESTION 15
What is output by the following code?
Trapezoid t = new Square(1);
t.setHeight(6);
t.setWidth(4);
t.setBase(2);
double a = t.area();
double p = t.perimeter();
System.out.print(a + " " + p);

Output: 16.0 18.0

QUESTION 16
What is output by the following code?
Trapezoid t = new Trapezoid(1, 1, 1);
Rectangle r = new Rectangle(2, 2);
Square s = new Square(3);
double a1 = t.area();
double a2 = r.area();
double a3 = s.area();
System.out.print(a1 + " " + a2 + " " + a3);

Output: 1.0 4.0 9.0

QUESTION 17
What is output by the following code?
Trapezoid t = new Trapezoid(1, 1, 1);
Rectangle r = new Rectangle(2, 2);
Square s = new Square(3);
r = s;
double a1 = t.area();
double a2 = r.area();
double a3 = s.area();
System.out.print(a1 + " " + a2 + " " + a3);

Output:

1.0 9.0 9.0

QUESTION 18
What is output by the following code?
Trapezoid t = new Trapezoid(1, 1, 1);
Rectangle r = new Rectangle(2, 2);
Square s = new Square(3);
t = s;
double a1 = t.area();
double a2 = r.area();
double a3 = s.area();
System.out.print(a1 + " " + a2 + " " + a3);

Output:

9.0 4.0 9.0

QUESTION 19
What is output by the following code?
Trapezoid t = new Trapezoid(1, 1, 1);
Rectangle r = new Rectangle(2, 2);
Square s = new Square(3);
t = r;
r = s;
double a1 = t.area();
double a2 = r.area();
double a3 = s.area();
System.out.print(a1 + " " + a2 + " " + a3);

Output:

4.0 9.0 9.0
5 points   
QUESTION 20
What is output by the following code?
Trapezoid t = new Trapezoid(1, 1, 1);
Rectangle r = new Rectangle(2, 2);
Square s = new Square(3);
r = s;
t = r;
double a1 = t.area();
double a2 = r.area();
double a3 = s.area();
System.out.print(a1 + " " + a2 + " " + a3);

Output:

9.0 9.0 9.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote