Question: classes -------------------------------------------- public class Circle { private final int radius; /** * * @param radius This is the class constructor which takes in 1 param


classes --------------------------------------------
public class Circle {
private final int radius; /** * * @param radius This is the class constructor which takes in 1 param radius */ Circle(int radius) { this.radius = radius; } /** * * @return method of diameter */ public double diameter() { double diamater = radius * radius; return diamater; } /** * * @return getRadius method */ public double getRadius() { return radius; } /** * * @return Circumference method */ public double circumference() { double circumference1 = (2 * 3.14); double answer = circumference1 * radius; return answer; } /** * * @return this returns the toString method, which allows values stored as objects to be printed */ @Override public String toString() { String s; s = String.format("Circle (%d) ", radius); return s; }
---------------------------------------------------------------------------------------
public class IsoscelesRightTriangle {
private final double leg; /** * * @param leg Constructor class which takes in an argument of leg */ IsoscelesRightTriangle(double leg) { this.leg = leg; } /** * * @return returns the hypotenuse method */ public double hypotenuse() { double answer = (leg * 2) + (leg * 2); return answer; } /** * * @return the getLeg method */ public double getLeg() { return leg; }
@Override /** * returns the toString method */ public String toString() { String s; s = String.format("IsoscelesRightTriangle (%f)", leg); return s; }
----------------------------------------------------------------------------
public class Rectangle {
private final int length; private final int width; /** * * @param length Constructor which takes in 2 arguments length and width * @param width */ Rectangle(int length, int width) { this.length = length; this.width = width; } /** * * @return getLength method */ public int getLength() { return length; } /** * * @return getWidth method */ public int getWidth() { return width; } /** * * @return toString method which has an @Override */ @Override
public String toString() { String s; s = String.format("Rectangle(%dx%d)", length, width); return s;
}
------------------------------------------------------------------------------
public class Square extends Rectangle {
Square(int side1) { super(side1, side1); }
public int getSide() { return super.getLength(); }
@Override
public String toString() { String myString; myString = String.format("Square (%d)", getSide()); return myString; }
Description: This assignment demonstrates the use of interfaces and how they can be used in combination with inheritance Use the four shapes that you implemented in Assignment Inheritance as a starting point I recommend creating a copy before you implement any changes. In this assignment you will create 2 interfaces: Shape and Printable and you will modify the classes Rectangle, Square, IsoscelesRightTriangle, and Circle so that they implement one or both of the interfaces In addition you will create a class called InterfaceApp (different from InheritanceApp). This class includes the main method and demonstrates the polymorphic behavior of interfaces. Declare the interfaces according to the UML diagrams: Interface Shape: Interface Shape perimeter(): double area(): double perimeter .. returns the perimeter of the shape area.. returns the area of the shape Interface Printable: print... prints the outline of the shape with small circles (see output) Interface Printable within a line the stars are always separated by a single space (blank) The rectangle is printed with the length on the x-axis (more wide than high) In case of the triangle the right angle is on the bottom left (see output) The output produced by the print method needs to reflect the actual field values print() Modify the four shape classes Rectangle, Square, IsoscelesRightTriangle, and Circle so that . all of them are a Shape . all except Circle are a Printable
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
