0% found this document useful (0 votes)
18 views2 pages

Activity

code
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Activity

code
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

*;
public class RunQuad {

public static void main(String[] args) {


Scanner scan = new Scanner(System.in);
System.out.println("Select from the following:");
System.out.println("R - Rectangle");
System.out.println("S - Square");
System.out.println("P - Parallelogram");
System.out.println("H - Rhombus");
System.out.println("T - Trapezoid");

Scanner input = new java.util.Scanner(System.in);


String shape = scan.next();

if(shape.equalsIgnoreCase("R")){
Rectangle rec = new Rectangle();
System.out.println("____________________________");
System.out.println("A rectangle: ");
rec.showDescription();
}
else if(shape.equalsIgnoreCase("S")){
Square sq = new Square();
System.out.println("____________________________");
System.out.println("A square: ");
sq.showDescription();
}
else if(shape.equalsIgnoreCase("P")){
Parallelogram par = new Parallelogram();
System.out.println("____________________________");
System.out.println("A parallelogram:");
par.showDescription();
}
else if(shape.equalsIgnoreCase("H")){
Rhombus rhom = new Rhombus();
System.out.println("____________________________");
System.out.println("A rhombus: ");
rhom.showDescription();
}
else if(shape.equalsIgnoreCase("T")){
Trapezoid trap = new Trapezoid();
System.out.println("____________________________");
System.out.println("A trapezoid: ");
trap.showDescription();
}
else{
System.out.println("Invalid Input!!");
}

}
}

class Quadrilateral {
public void showDescription() {
System.out.println("- is quadrilateral");
}
}
class Rectangle extends Quadrilateral {
public void showDescription() {
super.showDescription();
System.out.println("- has 4 right angles");
}
}

class Square extends Rectangle {

public void showDescription() {


super.showDescription();
System.out.println("- has 4 equal sides");
}
}

class Parallelogram extends Quadrilateral {

public void showDescription() {


super.showDescription();
System.out.println("- has 2 pairs of parallel sides");
}
}

class Rhombus extends Parallelogram {

public void showDescription() {


super.showDescription();
System.out.println("- has 4 congruent sides");
}
}

class Trapezoid extends Quadrilateral {

public void showDescription() {


super.showDescription();
System.out.println("- has 1 pair of parellel sides");
}
}

You might also like