Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this is in java, thanks for your help In this assignment, you must code an inter

ID: 2247034 • Letter: T

Question

this is in java, thanks for your help

In this assignment, you must code an interface named Shape with three methods and create a class named Rectangle that implements Shape.

The interface Shape represents a closed geometrical shape. It has three methods.

1. draw: This has no parameters and returns void. The method draws the shape on the screen.

2. getArea: The method has no parameters and returns the area of the shape. The return type is double.

3. getPerimeter: The method has no parameters and returns the perimeter of the shape. The return type is double.

The class Rectangle represents a rectangle and implements the Shape interface. Besides meeting that requirement, the class must satisfy the following criteria.

1. It must have exactly two double fields: width and height. Do not use any other identifiers for these two fields and do not define any other fields in the class.

2. It must have exactly one constructor that accepts the width and height in that order. It must store these values in the respective fields.

3. It must override toString and equals. You must use the standard Eclipse generated code for this.

The draw method must “draw” the rectangle using System.out.println. Simply print width number of asterisks in height number of lines. For example, see the following code and resultant output.

Shape rectangle1 = new Rectangle(4, 5); rectangle1.draw();

****

****

****

****

****

Please submit an Eclipse project as a zip file that opens correctly.

Explanation / Answer

**Shape Interface code: (Shape.java)

public interface Shape {

void draw();

double getArea();

double getPerimeter();

}

**Rectangle class code: (Rectangle.java)

public class Rectangle implements Shape {

public double height, width;

public Rectangle(double width, double height) {

// TODO Auto-generated method stub

this.width = width;

this.height = height;

}

@Override

public void draw() {

// TODO Auto-generated method stub

for(int i = 0; i < height; i++){

for(int j = 0; j < width; j++){

System.out.print("*");

}

System.out.println();

}

}

@Override

public double getArea() {

// TODO Auto-generated method stub

return (height * width);

}

@Override

public double getPerimeter() {

// TODO Auto-generated method stub

return (2 * (height + width));

}

public String toString() {

return "Width = " + this.width + " and Height = " + this.height;

}

@Override

public boolean equals(Object o) {

//Write your code here

return true;

}

}

**Driver Class code: (Driver.java)

import java.io.*;
// Java program to print largest contiguous array sum
import java.util.*;

class Driver
{
public static void main (String[] args)
{
Shape rectangle1 = new Rectangle(4, 5);
rectangle1.draw();
}
}

**Please comment for any furthur clarifications