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

import geometry205.*; public class Project2TestDriver { public static void main(

ID: 3870549 • Letter: I

Question

import

geometry205.*;

public

class

Project2TestDriver

{

public

static

void

main(String[]

args)

{

// Create

rectangle

with

l=3,

w=4

Rectangle

r1 = new

Rectangle(3,4);

// Create

square

wtih

s=4

Square

s1 = new

Square(4);

System.out.println("Project

2 Test

Driver");

System.out.println(r1);

System.out.println(s1);

}

}

Programming Project - Inheritance Review the material about inheritance Create a package in Eclipse called "geometry205". Add all the shape classes you create for part 3 to this package. Your driver class should- be in the default package. Complete the following programming assignment: » Design and implement a set of classes that define a series of 2D geometric shapes For each shape, store information about its dimensions and any other attributes you think are 1. 2. 3. necessary. Provide methods to access and modify this data where appropriate. Provide an perimeter() and area() method for each shape. In your design, consider how shapes are related and thus where inheritance can be implemented Create a driver class to instantiate several shapes of differing types and exercise the behavior you provided. 4) You should implement classes for at least three shapes, including a circle, a rectangle and a square. You should have at least one abstract class 5) The toString method should print the type of shape, its perimeter, and its area 6) A sample test driver class will be provided for you to test your project. Your code should work with the provided driver without modification. Think carefully about your design and use good object oriented principles in your implementation. Submission requirements: · Include your name as a comment at the top of each source code file ° Make good use of whitespace/comments to make your implementation clear. In a well-formatted .doc, .pdf, or txt file, briefly describe your implementation & class hierarchy, give sample output, and include your abstract class and one of your shape classes. Upload a zip file with your code. The easiest thing is to zip your entire project directory. Do not use .rar. . Include your first and last name in the .zip filename ° Submit a hard copy of the implementation document.

Explanation / Answer

//abstract base class Shape

abstract class Shape
{
//abstract methods
public abstract double perimeter();

public abstract double area();

  
}

class Circle extends Shape //inheritance
{
  
private int radius;
  
public Circle(int radius) //constructor
{
this.radius = radius;
}
public double perimeter()
{
return 2*3.14*radius;
}

public double area()
{
return 3.14*radius*radius;
}
public String toString()
{
return " Circle : Area :"+ area() +" Perimeter : "+perimeter();
}
  
}
class Rectangle extends Shape
{
private int length,width;
public Rectangle(int length,int width)
{
this.length = length;
this.width = width;
}
public double perimeter()
{
return 2*(length+width);
}

public double area()
{
return length*width;
}
public String toString()
{
return " Rectangle : Area :"+ area() +" Perimeter : "+perimeter();
}
  
}
class Square extends Shape
{
  
private int side;
public Square(int side)
{
this.side = side;
}
public double perimeter()
{
return 4*side;
}

public double area()
{
return side*side;
}
public String toString()
{
return " Square : Area :"+ area() +" Perimeter : "+perimeter();
}
  
  
}
class Project2TestDriver
{
public static void main(String[]args)
{
// Create rectangle with l=3, w=4
Rectangle r1 = new Rectangle(3,4);
// Create square wtih s=4
Square s1 = new Square(4);
System.out.println("Project 2 Test Driver");
System.out.println(r1);
System.out.println(s1);
}
}

Output:

Project 2 Test Driver

Rectangle : Area :12.0 Perimeter : 14.0

Square : Area :16.0 Perimeter : 16.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote