Java --- Please help me understand further the code below. Thank you!| --- Circle.java public class Circle implements Shape     {         final float PI = 3.14f;         int radius;                           public Circle(int radius)             {                 this.radius = radius;             }                           @Override         public double getPerimeter()              {                 return(2 * PI * radius);             }                       @Override         public double getArea()              {                 return(PI * radius*radius);             }                       @Override         public void getDetails()              {                 System.out.println("Type: Circle");                 System.out.println("Radius: " + radius);                 System.out.printf("Perimeter: %.1f\n", getPerimeter());                 System.out.printf("Area: %.1f\n", getArea());             }              } Rectangle.java public class Rectangle implements Shape     {         int length, width;                           public Rectangle(int a, int b)             {                 this.length = b;                 this.width = a;             }                           @Override         public double getPerimeter()              {                 return(2 * (length + width));             }              @Override         public double getArea()              {                              return(length * width);             }             @Override         public void getDetails()              {                 System.out.println("Type: Rectangle");                 System.out.println("Lengh: "+ length);                 System.out.println("Width: "+ width);                 System.out.printf("Perimeter: %.1f\n", getPerimeter());                 System.out.printf("Area: %.1f\n", getArea());             }             } Square.java public class Square implements Shape     {         int side;                      public Square(int a)             {                 this.side = a;             }                        @Override         public double getPerimeter()              {                 return(4 * side);             }                           @Override         public double getArea()              {                                 return(side * side);             }                    @Override         public void getDetails()              {                 System.out.println("Type: Square");                 System.out.println("Side: " + side);                 System.out.printf("Perimeter: %.1f\n", getPerimeter());                 System.out.printf("Area: %.1f\n", getArea());             }             } Triangle.java public class Triangle implements Shape     {         int sideA, sideB, sideC;                  public Triangle(int a, int b, int c)             {                 this.sideA = a;                 this.sideB = b;                 this.sideC = c;             }                        @Override         public double getPerimeter()              {                 return(sideA + sideB + sideC);            }                    @Override         public double getArea()              {                 float s = (sideA+sideB+sideC)/2;                                 return(Math.sqrt(s * (s - sideA) * (s - sideB) * (s - sideC)));             }                        @Override         public void getDetails()              {                 System.out.println("Type: Triangle");                 System.out.printf("Sides: %d, %d, %d \n", sideA, sideB, sideC);                 System.out.printf("Perimeter: %.1f\n", getPerimeter());                 System.out.printf("Area: %.1f\n", getArea());             }             } Shape.java public interface Shape     {         double getPerimeter();         double getArea();         void getDetails();     }

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
100%

Java
---
Please help me understand further the code below. Thank you!|
---
Circle.java

public class Circle implements Shape
    {
        final float PI = 3.14f;
        int radius;
        
        
        public Circle(int radius)
            {
                this.radius = radius;
            }
        
        
        @Override
        public double getPerimeter() 
            {
                return(2 * PI * radius);
            }
    
        
        @Override
        public double getArea() 
            {
                return(PI * radius*radius);
            }
    
        
        @Override
        public void getDetails() 
            {
                System.out.println("Type: Circle");
                System.out.println("Radius: " + radius);
                System.out.printf("Perimeter: %.1f\n", getPerimeter());
                System.out.printf("Area: %.1f\n", getArea());
            }
        
    }

Rectangle.java

public class Rectangle implements Shape
    {
        int length, width;
        
        
        public Rectangle(int a, int b)
            {
                this.length = b;
                this.width = a;
            }
        
        
        @Override
        public double getPerimeter() 
            {
                return(2 * (length + width));
            }
    
        @Override
        public double getArea() 
            {             
                return(length * width);
            }    
        @Override
        public void getDetails() 
            {
                System.out.println("Type: Rectangle");
                System.out.println("Lengh: "+ length);
                System.out.println("Width: "+ width);
                System.out.printf("Perimeter: %.1f\n", getPerimeter());
                System.out.printf("Area: %.1f\n", getArea());
            }        
    }

Square.java

public class Square implements Shape
    {
        int side;             
        public Square(int a)
            {
                this.side = a;
            }               
        @Override
        public double getPerimeter() 
            {
                return(4 * side);
            }
        
        
        @Override
        public double getArea() 
            {                
                return(side * side);
            }           
        @Override
        public void getDetails() 
            {
                System.out.println("Type: Square");
                System.out.println("Side: " + side);
                System.out.printf("Perimeter: %.1f\n", getPerimeter());
                System.out.printf("Area: %.1f\n", getArea());
            }        
    }

Triangle.java

public class Triangle implements Shape
    {
        int sideA, sideB, sideC;
        
        public Triangle(int a, int b, int c)
            {
                this.sideA = a;
                this.sideB = b;
                this.sideC = c;
            }               
        @Override
        public double getPerimeter() 
            {
                return(sideA + sideB + sideC);            }           
        @Override
        public double getArea() 
            {
                float s = (sideA+sideB+sideC)/2;                
                return(Math.sqrt(s * (s - sideA) * (s - sideB) * (s - sideC)));
            }               
        @Override
        public void getDetails() 
            {
                System.out.println("Type: Triangle");
                System.out.printf("Sides: %d, %d, %d \n", sideA, sideB, sideC);
                System.out.printf("Perimeter: %.1f\n", getPerimeter());
                System.out.printf("Area: %.1f\n", getArea());
            }        
    }

Shape.java

public interface Shape
    {
        double getPerimeter();
        double getArea();
        void getDetails();
    }

D TestShape.java x
1 public class TestShape
{
public static void main(String[] args)
{
2
30
4
5
int a, b, c;
7
if (args.length < 1 || args.length > 3)
System.out.printin("Invalid input");
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
else
{
switch(args.length)
{
case 1:
{
a = Integer.parseInt(args[0]);
Circle circle = new Circle(a);
circle.getDetails();
break;
}
case 2:
{
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[1]);
// OF BOTH ARGS ARE EQUAL THEN SQUARE
if (a == b)
{
Square square = new Square(a);
square.getDetails();
}
else
{
Rectangle rect = new Rectangle(a, b);
rect.getDetails();
}
break;
}
// IF ARGS LENGTH IS THREE THEN TRIANGLE
case 3:
{
a = Integer.parseInt(args[0]);
b = Integer.parseInt (args[1]);
c = Integer.parseInt (args[2]);
Triangle t = new Triangle(a, b, c);
t.getDetails();
break;
}
}
}
}
55
}
Transcribed Image Text:D TestShape.java x 1 public class TestShape { public static void main(String[] args) { 2 30 4 5 int a, b, c; 7 if (args.length < 1 || args.length > 3) System.out.printin("Invalid input"); 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 else { switch(args.length) { case 1: { a = Integer.parseInt(args[0]); Circle circle = new Circle(a); circle.getDetails(); break; } case 2: { a = Integer.parseInt(args[0]); b = Integer.parseInt(args[1]); // OF BOTH ARGS ARE EQUAL THEN SQUARE if (a == b) { Square square = new Square(a); square.getDetails(); } else { Rectangle rect = new Rectangle(a, b); rect.getDetails(); } break; } // IF ARGS LENGTH IS THREE THEN TRIANGLE case 3: { a = Integer.parseInt(args[0]); b = Integer.parseInt (args[1]); c = Integer.parseInt (args[2]); Triangle t = new Triangle(a, b, c); t.getDetails(); break; } } } } 55 }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 9 steps with 9 images

Blurred answer
Knowledge Booster
Random Class and its operations
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