Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Java program based on geometric shapes using ClassesSquare, Triangle, Rectangle, and Circle to help describeinheritance and polymorphism using the circumference() method. Theprogram will

  • Create a Java program based on geometric shapes using ClassesSquare, Triangle, Rectangle, and Circle to help describeinheritance and polymorphism using the circumference() method. Theprogram will calculate the circumference of a designatedshape.
  • The program should begin by prompting you for the shape youwant to calculate the circumference for – square, rectangle,circle, or triangle. You can designate 1-square, 2-rectangle,3-circle, 4-triangle, and 5-Exit.
  • Once you select your shape, then the program should prompt youfor enough information to calculate the circumference of the chosenshape. For example, if you select square then the program shouldprompt you for the length of one side of the square. If you selectcircle, then the program will prompt you for either the radius ordiameter of the circle. With the information for calculating thecircumference, have the program complete the calculation and printthe information to the screen, using one of the JOptionPane outputclasses (methods) or any other graphical output method.

Your output should look something like this:

  • You selected Square
    Length of each side=XX.X cm (centimeters -- do all measurements inmetric)
    Area=XX.X cm
    • Make sure you create the program in a loop and have the programprompt you for another shape and calculation. Enter 5 forexit.
    • You should first create a Square superclass, and then from itcreate Rectangle, Circle, and Triangle subclasses. In the Squareclass create a circumference() method (e.g., circumf()) and thenre-define that method in each subclass to calculate the area of theappropriate shape.
    • You should also create a color() method (e.g.,color()) and have the Square superclassreturn the color as white. Have eachsubclass also return color, but redefine the color method in theCircle subclass to return the color asblue.
    • Also, you should now be using theJOptionPane.showMessageDialog() method for displaying your outputinstead of System.out.println().

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

Fundamentals of Financial Accounting

Authors: Fred Phillips, Robert Libby, Patricia Libby

5th edition

78025915, 978-1259115400, 1259115402, 978-0078025914

More Books

Students also viewed these Databases questions