Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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");

}

}

image text in transcribed

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 quadrilateral

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

Find the derivative of y= cos cos (x + 2x)

Answered: 1 week ago