Answer to Question #290774 in Java | JSP | JSF for John

Question #290774

1. Create a class named RunQuad. This class shall contain the main method.



2. Add three (3) classes named Quadrilateral, Rectangle, and Square. Rectangle shall inherit from



Quadrilateral while Square shall inherit from Rectangle.



3. Declare a public method named showDescription() in all three (3) classes except in RunSquad.



Customize each method by creating different println() statements.



a. For Quadrilateral: "- is quadrilateral".



b. For Rectangle: "- has 4 right angles". Add a super() statement to call Quadrilateral's



method.



c. For Square: "- has 4 equal sides". Add a super() statement to call Rectangle's method.



4. Code the main method of the RunQuad class. The output shall ask the user to press R or S to



choose between rectangle and square. Display appropriate description(s).



5. Keep a copy of your program. You will be using it next week.




1
Expert's answer
2022-01-26T12:55:18-0500


import java.util.*;


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 Quadrilateral {


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


public class RunQuad  {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);


		System.out.print("Press R or S to choose between rectangle and square: ");
		String choice = keyBoard.nextLine();
		if (choice.compareToIgnoreCase("R") == 0) {
			Rectangle r = new Rectangle();
			r.showDescription();
		}else {
			Square s = new Square();
			s.showDescription();
		}
		keyBoard.close();
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS