import java.util.Scanner;//to read user inputs
public class RunQuad {//start the class
public static void main(String[] args) {//start main method
Scanner input = new Scanner(System.in);//create Scanner object
System.out.print("Press R for Rectangle or S for Square. ");
char inputChoice = input.nextLine().charAt(0);//read character input
if(inputChoice=='R') {//if choice is R
Rectangle r = new Rectangle();//create object of Rectangle
System.out.println("A Rectangle: ");
r.showDescription();//call showDescription of Rectangle from its object r
}
else if(inputChoice=='S') {//if choice is S
Square s = new Square();//create object of Square
System.out.println("A Square: ");
s.showDescription();//call showDescription of Square from its object s
}
else {
System.out.println("Invalid input");
}
}
}
class Quadrilateral {//parent class
public void showDescription() {
System.out.println("- is quadrilateral");
}
}
class Rectangle extends Quadrilateral {//rectangle inherits Quadrilateral
public void showDescription() {
System.out.println("- has 4 right angles");
super.showDescription();//call Quardrilatral's showDescription
}
}
class Square extends Rectangle {//inherits Rectangle
public void showDescription() {
System.out.println("- has 4 equal sides");
super.showDescription();//call Rectangle's showDescription
}
}