Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE USE JAVA Create a new package in assignment called shapes. All work for this part should be done in the shapespackage. Create a new

PLEASE USE JAVA

  • Create a new package in assignment called shapes.
  • All work for this part should be done in the shapespackage.
  • Create a new interface called Shape.
  • Add double area() and double perimter()methods to the Shape interface.
  • Create two classes called Circle and Rectanglewhich implement Shape.
  • Add reasonable fields to the Circle and Rectangle classes which will allow you to calculate the area and perimeter of each shape.
  • Add constructors to Circle and Rectangle so you can initialize your fields.
  • Implement the area() and perimeter() methods for Circle and Rectangle.
  • Create an interface called Shape3D.
  • Add double volume() method to Shape3D.
  • Create a class called Cyclinder which extends Circle and implements Shape3D.
  • Add and initialize any required fields that you may need to calculate a cylinder's volume.
  • Keep in mind that the Cylinder class will have access to its parent (Circle) class' methods. Use this to your advantage to implement the volume()method.
  • Create a class named ShapeRunner with the following main method:
  • public static void main(String[] args) {
  • Shape circle = new Circle(2.0);
  • Shape rectangle = new Rectangle(4.0, 2.0);
  • Shape3D cylinder = new Cylinder(4.0, 1.0);
  • System.out.println("Circle:");
  • System.out.println("Area: " + circle.area() + ". Perimeter: " + circle.perimeter());
  • System.out.println(" Rectangle:");
  • System.out.println("Area: " + rectangle.area() + ". Perimeter: " + rectangle.perimeter());
  • System.out.println(" Cylinder:");
  • System.out.println("Volume: " + cylinder.volume());
  • }
  • Notice how the shapes are declared with their interfaces instead of their concrete types. This allows for more flexibility when trying to extend an application, but also makes sure that you are able to only access methods on the interface's contract. Feel free to play around with different values to test your implementations, but when submitting your final assignment, make sure to leave this main() method as written here.

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

DB2 9 For Linux UNIX And Windows Advanced Database Administration Certification Certification Study Guide

Authors: Roger E. Sanders, Dwaine R Snow

1st Edition

1583470808, 978-1583470800

More Books

Students also viewed these Databases questions