Define a Polygon interface that has methods area() and perimeter(). Then implement classes for Triangle, Quadrilateral, Pentagon, Hexagon, and Octagon, which implement this interface, with the obvious meanings for the area() and perimeter() methods. Also implement classes, IsoscelesTriangle, Equilateral-Triangle, Rectangle, and Square, which have the appropriate inheritance relationships. Finally, write a simple user interface, which allows users to create polygons of the various types, input their geometric dimensions, and then output their area and perimeter. For extra effort, allow users to input polygons by specifying their vertex coordinates and be able to test if two such polygons are similar.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Data Structures and Algorithms in Java
Additional Engineering Textbook Solutions
Starting Out with Python (4th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Programming in C
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with Programming Logic and Design (4th Edition)
- Write an interface and then modify classes to implement the interface. Write an interface, GeometricSolid, which has one method, volume. The volume method takes no arguments and returns a double. You are provided with three classes: Cylinder, Sphere, and RightCircularCone Modify the classes so that they implement the GeometricSolid interface. Supply the appropriate method for each class. Make sure that you use Math.PI in your calculations. Notice in InterfaceRunner that the objects are added to an ArrayList of GeometricSolids. Cylinder.java /*** Models a Cylinder*/public class Cylinder {private double radius;private double height; /*** Constructor for objects of class Cylinder* @param radius the radius of the Cylinder* @param height the height of this Cylinder*/public Cylinder(double radius, double height){this.radius = radius;this.height = height;}/*** Gets the radius of this Cylinder* @return the radius of the Cylinder*/public double getRadius(){return radius;}/*** Sets the radius of…arrow_forwardWrite the constructor method for class Circle which is a subclass of Shape class. Class Shape has one attribute (color) and one constructor (with one parameter). Class circle has attribute for radius.arrow_forwardCreate a Visible interface with two methods: makeVisible and makeInvisible. Both methods should accept no parameters and return a boolean value. Explain how a class may implement this interface.arrow_forward
- add a class to package that represents your new drivable type. That type should be something that is capable of being driven (speeding up and slowing down) and therefore a perfect candidate for a class that implements the actions in the Drivable interface.arrow_forwardIn this problem you will first write an interface and then modify classes to implement the interface. Write an interface, GeometricSolid, which has one method, volume. The volume method takes no arguments and returns a double. You are provided with three classes: Cylinder, Sphere, and RightCircularCone Modify the classes so that they implement the GeometricSolid interface. Supply the appropriate method for each class. You can use Google search to find the formula for the volume. Make sure that you use Math.PI in your calculations. Notice in InterfaceRunner that the objects are added to an ArrayList of GeometricSolids. Provide Javadoc. Cylinder.java /*** Models a Cylinder*/public class Cylinder {private double radius;private double height; /*** Constructor for objects of class Cylinder* @param radius the radius of the Cylinder* @param height the height of this Cylinder*/public Cylinder(double radius, double height){this.radius = radius;this.height = height;}/*** Gets the radius of this…arrow_forwardPlease solve this questions based on Java program. Please soon.arrow_forward
- Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent class to TwoDimensionalShape and ThreeDimensionalShape. The classes Circle, Square, and Triangle should inherit from TwoDimensionalShape, while Sphere, Cube, and Tetrahedron should inherit from ThreeDimensionalShape.Each TwoDimensionalShape should have the methods getArea() and getPerimeter(), which calculate the area and perimeter of the shape, respectively. Every ThreeDimensionalShape should have the methods getArea() and getVolume(), which respectively calculate the surface area and volume of the shape. Every class should have a member variable containing its dimensions -- for example, the Circle class should have a member variable describing its radius, while the Triangle class should have three member variables describing the length of each side. Note that the Tetrahedron cass should describe a regular tetrahedron, and as such, should only have one member variable.Create a Driver class…arrow_forwardJava Problem A shop sells beverages. A beverage has a brand, the ingredients, a codebar number, price, production date and expiration date. A beverage belongs to a company that has a name, an address, a phone number and an email. The shop employees want to check automatically the stock of beverages. All expired or sold beverages need to be eliminated. Implement the Shop, Beverage and Company classes. Implement the needed interfaces and methods for the classes. The shop has a method which specifies how many times does each ingredient appear in the whole collection of beverages. Create a main method which tests the program with relevant data based on data which is read from a file and output the beverages which are out of stock in a file.arrow_forwardImagine you have two classes: Employee (which represents being an employee) and Ninja (which represents being a Ninja). An Employee has both state and behaviour; a Ninja has only behaviour. You need to represent an employee who is also a ninja (a common problem in the real world). By creating only one interface and only one class (NinjaEmployee), show how you can do this without having to copy method implementation code from either of the original classes.arrow_forward
- In order to implement different ways of discount strategies for an object oriented parking system, we have a DiscountStrategy interface and CompactWeekendDiscounts class. The CompactWeekendDiscounts class class checks if the date is a weekend and the car we are about to park is compact and makes a discount. Based on the class diagram implement the two - a DiscountStrategy interface and CompactWeekendDiscounts class using java. (no need to implement ParkingLot class )arrow_forwardWrite an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram, Rectangle and Square. Use Quadrilateral as the superclass of the hierarchy. Create and use a Point class to represent the points in each shape. Make the hierarchy as deep (i.e., as many levels) as possible. Specify the instance variables and methods for each class. The private instance variables of Quadrilateral should be the x- y coordinate pairs for the four endpoints of the Quadrilateral. Write a program that instantiates objects of your classes and outputs each object’s area (except Quadrilateral). I need a detailed explanation about the output please help me thank you so much!arrow_forwardImplement a superclass Person. Make two classes, Student and Instructor, that inherit from Person. A person has a name and a year of birth. A student has a major, and an instructor has a salary. Write the class declarations, the constructors, and the Supply a methods toString for all classes. test program for these classes and methods.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education