Answer:
Shapes.java
public abstract class Shapes {
}
Triangle.java
public abstract class Triangle extends Shapes {
}
IsoscelesTriangle.java
public class IsoscelesTriangle extends Triangle {
double side1;
double side2;
public double getSide1() {
return side1;
}
public void setSide1(double side1) {
this.side1 = side1;
}
public double getSide2() {
return side2;
}
public void setSide2(double side2) {
this.side2 = side2;
}
public IsoscelesTriangle(double side1, double side2) {
super();
this.side1 = side1;
this.side2 = side2;
}
public double perimeter()
{
return 2*side1+side2;
}
public double area()
{
return side1*side2/2;
}
}
EquilateralTriangle.java
public class EquilateralTriangle extends Triangle {
double side;
public EquilateralTriangle(double side) {
super();
this.side = side;
}
public double getSide() {
return side;
}
public void setSide(double side) {
this.side = side;
}
public double perimeter()
{
return 3*side;
}
public double area()
{
return 1.73205*side*side/4;
}
}
Quadrilateral.java
public abstract class Quadrilateral extends Shapes {
}
Rectangle.java
public class Rectangle extends Quadrilateral {
double length;
double breadth;
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getBreadth() {
return breadth;
}
public void setBreadth(double breadth) {
this.breadth = breadth;
}
public Rectangle(double length, double breadth) {
super();
this.length = length;
this.breadth = breadth;
}
public double perimeter()
{
return 2*(length+breadth);
}
public double area()
{
return length*breadth;
}
}
Square.java
public class Square extends Quadrilateral {
double side;
public Square(double side) {
super();
this.side = side;
}
public double getSide() {
return side;
}
public void setSide(double side) {
this.side = side;
}
public double perimeter()
{
return 4*side;
}
public double area()
{
return side*side;
}
}
Rhombus.java
public class Rhombus extends Quadrilateral {
double length;
double breadth;
public Rhombus(double length, double breadth) {
super();
this.length = length;
this.breadth = breadth;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getBreadth() {
return breadth;
}
public void setBreadth(double breadth) {
this.breadth = breadth;
}
public double perimeter()
{
return 2*(length+breadth);
}
public double area()
{
return length*breadth/2;
}
}
Test.java
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("Enter your choice");
System.out.println("1. Create IsoscelesTriangle ");
System.out.println("2. Create EquilateralTriangle");
System.out.println("3. Create Rectangle");
System.out.println("4. Create Square");
System.out.println("5. Create Rhombus");
System.out.println("6. Create Circle");
int choice=sc.nextInt();
switch(choice)
{
case 1:
System.out.println("Enter two sides of triangle");
double side1=sc.nextDouble();
double side2=sc.nextDouble();
IsoscelesTriangle isosceles=new IsoscelesTriangle(side1, side2);
System.out.println("Area of the triangle is "+isosceles.area());
System.out.println("Perimeter of the triangle is "+ isosceles.perimeter());
break;
case 2:
System.out.println("Enter side of the triangle");
double side=sc.nextDouble();
EquilateralTriangle equilateralTriangle=new EquilateralTriangle(side);
System.out.println("Area of the triangle is "+equilateralTriangle.area());
System.out.println("Perimeter of the triangle is "+ equilateralTriangle.perimeter());
break;
case 3:
System.out.println("Enter length and breadth");
double length=sc.nextDouble();
double breadth=sc.nextDouble();
Rectangle rectangle =new Rectangle(length, breadth);
System.out.println("Area of rectangle is "+rectangle.area());
System.out.println("Perimeter of the rectangle is "+rectangle.perimeter());
break;
case 4:
System.out.println("Enter side of the square");
double squareside=sc.nextDouble();
Square square=new Square(squareside);
System.out.println("area of the square is "+square.area());
System.out.println("Perimeter of the square is "+square.perimeter());
break;
case 5:
System.out.println("Enter length and breadth of rhombus");
double rlength=sc.nextDouble();
double rbreadth=sc.nextDouble();
Rhombus rhombus=new Rhombus(rlength, rbreadth);
System.out.println("area of the rhombus is "+rhombus.area());
System.out.println("Perimeter of the rhombus is "+rhombus.perimeter());
break;
case 6:
System.out.println("Enter radius of circle");
double radius=sc.nextDouble();
Circle circle=new Circle(radius);
System.out.println("area of the circle is "+circle.area());
System.out.println("Perimeter of the circle is "+circle.perimeter());
break;
}
}
}