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

Background: Perry Programmer has decided to decorate his cubicle with shapes mad

ID: 3872531 • Letter: B

Question

Background: Perry Programmer has decided to decorate his cubicle with shapes made of paper with a wire outline. He has decided to start with equilateral triangles of various sizes. will take a list of In order to estimate how much wire and paper he should buy, he has written a program that shapes and compute the total perimeter (i.e. amount of wire needed) and total area (i.e. amount of paper needed) for those shapes. His program consists of the following two classes: public class SupplyEstimator( static Triangle [ ] shapeList = { new Triangle ( 4-0 ) , new Triangle (2.5), new Triangle (2.5), new Triangle (10.0) public static void main(String args) double perrymeter0.0; //Perry loves puns double area 0.0 ; for (int i-0; i

Explanation / Answer

public class SupplyEstimator {
static Shape[] shapeList = {
new Triangle(4.0),
new Triangle(2.5),
new Triangle(2.5),
new Triangle(10.0),
  
new Square(4.0),
new Square(2.5),
new Square(2.5),
new Square(10.0),
  
new Hexagon(4.0),
new Hexagon(2.5),
new Hexagon(2.5),
new Hexagon(10.0)
};
  
public static void main (String[] args) {
double perrymeter = 0.0; //Perry loves puns
double area = 0.0;
for(int i=0; i<shapeList.length; i++) {
System.out.println(shapeList[i].toString());
perrymeter += shapeList[i].getPerimeter();
area += shapeList[i].getArea();
}
System.out.println("For the "+shapeList.length+" shapes given");
System.out.println("the total perimeter is "+perrymeter);
System.out.println("and the total area is "+area);
}
}

// Shape is an abstract class, so as not to be instantiated
abstract class Shape {
double size;
  
public Shape(double s) {
size = s;
}
  
public String toString() {
return "a " + this.getClass() + " of size " + this.size;
}
  
public abstract double getPerimeter();
  
public abstract double getArea();
}

class Triangle extends Shape {
  
public Triangle() {
this(1);
}
  
public Triangle(double s) {
super(s);
}
  
public double getPerimeter() {
return 3*size;   
}
  
public double getArea() {
return size*size*Math.sqrt(3)/4.0;
}
}

class Square extends Shape {
  
public Square() {
this(1);
}
  
public Square(double s) {
super(s);
}
  
public double getPerimeter() {
return 4*size;   
}
  
public double getArea() {
return size*size;
}
}

class Hexagon extends Shape {
  
public Hexagon() {
this(1);
}
  
public Hexagon(double s) {
super(s);
}
  
public double getPerimeter() {
return 6*size;   
}
  
public double getArea() {
return 1.5*Math.sqrt(3)*size*size;
}
}

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