Question
This is my Java code. import java.util.Scanner; class RunQuad { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println(Press R for Rectangle,
This is my Java code.
import java.util.Scanner;
class RunQuad {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Press R for Rectangle, S for Square, P for Parallelogram, H for Rhombus, or T for Trapezoid.");
char choice = input.nextLine().toUpperCase().charAt(0);
Quadrilateral quadrilateral;
switch (choice) {
case 'R':
quadrilateral = new Rectangle();
break;
case 'S':
quadrilateral = new Square();
break;
case 'P':
quadrilateral = new Parallelogram();
break;
case 'H':
quadrilateral = new Rhombus();
break;
case 'T':
quadrilateral = new Trapezoid();
break;
default:
System.out.println("Invalid input.");
return;
}
quadrilateral.showDescription();
}
}
abstract 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 parallel sides");
}
}
Please put the part where if you inputted a letter, it says what shape like on the sample output. "A square:" if it's a square, "A Rhombus:" if it's a rhombus... and so on.
Thank you so much in advance.
Sample Output: Press R for Rectangle or S for Square. S A square: - has 4 equal sides - has 4 right angles - is quadrilateralStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started