Create a Java program based on geometric shapes using ClassesSquare, Triangle, Rectangle, and Circle to help describeinheritance
Fantastic news! We've Found the answer you've been seeking!
Question:
- 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().
Related Book For
Fundamentals of Financial Accounting
ISBN: 978-0078025914
5th edition
Authors: Fred Phillips, Robert Libby, Patricia Libby
Posted Date: