Question
OTHER TIMES I POSTED THIS ON CHEGG THEY DID THIS WRONG! Please do this yourself and not copy other code because it has not worked.
OTHER TIMES I POSTED THIS ON CHEGG THEY DID THIS WRONG! Please do this yourself and not copy other code because it has not worked. Please follow along Carefully. What is the finished code in Java? Some code to Start is provided. Do not copy and paste code from my previous similar question because it was done very wrong, please follow along and paste the finished code.
public class Circle { private final int radius; /** * @param radius */ public Circle(int radius) { this.radius = radius; } /** * calculates and return the diameter of the circle * Diameter is equal to two times the radius */ public int diameter() { return 2 * radius; } /** * calculates and returns the circumference of the circle * Circumference is equal to PI times diameter */ public double circumference() { return Math.PI * diameter(); } /** * getter for radius */ public int getRadius() { return this.radius; } @Override public String toString() { return "Circle" + "(" + radius + ")"; } }
-------------------------------------------------------------------------
public class IsoscelesRightTriangle { private final int leg; /** * @param leg */ public IsoscelesRightTriangle(int leg) { this.leg = leg; } /** * @return calculate and return the hypotenuse * The Hypotenuse of an Isosceles Right Triangle is equal to the Square root of two times leg */ public double hypotenuse() { return Math.sqrt(2) * leg; } /** * @return leg */ public int getLeg() { return leg; } @Override public String toString() { return "IsoscelesRightTriangle" + "(" + leg + ")"; } }
---------------------------------------------------------
public class Rectangle { private final int length; // Field to store length of Rectangle private final int width; // Field to store width of Rectangle /** * @param length * @param width */ public Rectangle(int length, int width) { this.length = length; this.width = width; }
/** * @return length */ public int getLength() { return length; } /** * @return width */ public int getWidth() { return width; } @Override public String toString() { return "Rectangle" + "(" + length + "x" + width + ")"; } }
----------------------------------------------------------
public class Square extends Rectangle { /** * @param side * calls the super class constructor */ public Square(int side) { super(side, side); } /** * gets side will return the length of the Square */ public int getSide() { return this.getLength(); } @Override public String toString() { return "Square" + "(" + getSide() + ")"; } }
------------------------------------------------------------
//I dont think you will need or use this class
public class InheritanceApp { public static void main(String[] args) { Rectangle myRectangle = new Rectangle(5, 4); Square mySquare = new Square(4); IsoscelesRightTriangle myIsoscelesRightTriangle = new IsoscelesRightTriangle(5); Circle myCircle = new Circle(4); System.out.println(myRectangle); System.out.println("Length: " + myRectangle.getLength() + " Width: " + myRectangle.getWidth() + " "); System.out.println(mySquare); System.out.println("Side: " + mySquare.getSide() + " "); System.out.println(myIsoscelesRightTriangle); System.out.println("Leg: " + myIsoscelesRightTriangle.getLeg() + " Hypotenuse: " + myIsoscelesRightTriangle.hypotenuse() + " "); System.out.println(myCircle); System.out.println("Diameter: " + myCircle.diameter() + " Circumference: " + myCircle.circumference() + " Radius: " + myCircle.getRadius() + " ");
Rectangle rectangle2 = mySquare; System.out.println("rectangle2: -----------"); System.out.println(rectangle2); System.out.println("Length: " + rectangle2.getLength() + "Width: " + rectangle2.getWidth() + " "); Rectangle[] rectangles = new Rectangle[] {rectangle2, mySquare, myRectangle}; System.out.println("Rectangle Array: ----------------"); for (Rectangle rectangle : rectangles) { System.out.println(rectangle); System.out.println("Length: " + rectangle.getLength() + " Width: " + rectangle.getWidth() + " "); } } }
Assignment Interface CSIS-1410 Learning Objectives: Create an interface Implement an interface Demonstrate polymorphic behavior of interfaces Use the instanceof operator Develop algorithms (print methods) 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 Sha 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) 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 Interface Printable print) Modify the four shape classes Rectangle, Square, IsoscelesRightTriangle, and Circle so that all of them are a Shape all except Circle are a PrintableStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started