hello can you please help correct this, it is not running. i cant figure out what i did wrong  // Shape class public abstract class Shape { Stringname;   public Shape(Stringname) { this.name = name; }   publicabstractdouble getArea(); publicabstractdouble getPerimeter();   publicString getName() { returnthis.name; }     //Circle.java   publicclass Circle extends Shape { doublediameter;   public Circle(doublediameter) { super("Circle"); this.diameter = diameter; }   @Override publicdouble getArea() { // A = π r^2 return Math.PI * Math.pow(diameter/2, 2); }   @Override publicdouble getPerimeter() { // P = πd return Math.PI * diameter; }   //Square.java   publicclass Square extends Shape { doublelength;   public Square(doublelength) { super("Square"); this.length = length; }   @Override publicdouble getArea() { // A = l*l returnlength * length; }   @Override publicdouble getPerimeter() { // P = 4(l) return 4 * length; }   //Triangle.java   publicclass Triangle extends Shape { doublelength; // side   public Triangle(doublelength) { super("Triangle"); this.length = length; }   @Override publicdouble getArea() { // Heron's formula: // A = (SquareRoot(3)/4) * side * side   return (Math.sqrt(3)/4)*length*length; }   @Override publicdouble getPerimeter() { // P = 3 * side return 3*length; }   }   import java.text.DecimalFormat;   public class TestShapes { publicstaticvoid main(String[] args) {   Shape[] shapes = new Shape[3];   shapes[0] = newCircle(10); shapes[1] = newSquare(5); shapes[2] = newTriangle(8);   DecimalFormat dec = new DecimalFormat("#0.00");   for (inti = 0; i < shapes.length; i++) { System.out.println("The Shape's Name: "+ shapes[i].getName()); System.out.printf("The Shape's Area: "+ dec.format(shapes[i].getArea())+"\n"); System.out.println("The Shape's Perimeter: "+dec.format(shapes[i].getPerimeter())+"\n\n"); System.out.println(); } } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

hello can you please help correct this, it is not running. i cant figure out what i did wrong 

// Shape class

public abstract class Shape {

Stringname;

 

public Shape(Stringname) {

this.name = name;

}

 

publicabstractdouble getArea();

publicabstractdouble getPerimeter();

 

publicString getName()

{

returnthis.name;

}

 

 

//Circle.java

 

publicclass Circle extends Shape {

doublediameter;

 

public Circle(doublediameter) {

super("Circle");

this.diameter = diameter;

}

 

@Override

publicdouble getArea() {

// A = π r^2

return Math.PI * Math.pow(diameter/2, 2);

}

 

@Override

publicdouble getPerimeter() {

// P = πd

return Math.PI * diameter;

}

 

//Square.java

 

publicclass Square extends Shape {

doublelength;

 

public Square(doublelength) {

super("Square");

this.length = length;

}

 

@Override

publicdouble getArea() {

// A = l*l

returnlength * length;

}

 

@Override

publicdouble getPerimeter() {

// P = 4(l)

return 4 * length;

}

 

//Triangle.java

 

publicclass Triangle extends Shape {

doublelength; // side

 

public Triangle(doublelength) {

super("Triangle");

this.length = length;

}

 

@Override

publicdouble getArea() {

// Heron's formula:

// A = (SquareRoot(3)/4) * side * side

 

return (Math.sqrt(3)/4)*length*length;

}

 

@Override

publicdouble getPerimeter() {

// P = 3 * side

return 3*length;

}

 

}

 

import java.text.DecimalFormat;

 

public class TestShapes {

publicstaticvoid main(String[] args) {

 

Shape[] shapes = new Shape[3];

 

shapes[0] = newCircle(10);

shapes[1] = newSquare(5);

shapes[2] = newTriangle(8);

 

DecimalFormat dec = new DecimalFormat("#0.00");

 

for (inti = 0; i < shapes.length; i++)

{

System.out.println("The Shape's Name: "+ shapes[i].getName());

System.out.printf("The Shape's Area: "+ dec.format(shapes[i].getArea())+"\n");

System.out.println("The Shape's Perimeter: "+dec.format(shapes[i].getPerimeter())+"\n\n");

System.out.println();

}

}

}

Expert Solution
steps

Step by step

Solved in 5 steps with 6 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education