In: Computer Science
In this assignment, students should create five Java classes called Point, Circle, Square, Rectangle, and TestAll, as well as a Java interface called FigureGeometry. The TestAll class should implement the main method which tests all of the other files created in the assignment. After the assignment has been completed, all six files should be submitted for grading into the Dropbox for Assignment 3, which can be found in the Dropbox menu on the course website. Students should note that only the *.java file for each class /interface needs to be submitted; No *.class files need to be submitted into the Dropbox. Please see below specific requirements for the files that must be created and submitted:
Point.java Description:
The Point class should be declared as a public class and should meet all the requirements listed below. Its purpose is to store the Point (width and height) of a two-dimensional, rectangular geometric figure.
Instance Variables:
private int width;//stores the width of a Point object private
private int height;//stores the height of a Point object
Constructor: Point()
Parameters:
int theWidth,
int theHeight
Purpose: initializes the width and height of a Point object in the following manner:
width = theWidth;
height = theHeight;
Methods:
public int getWidth(){//returns the width of a Point object in the following manner
return width;}
public int getHeight(){//returns the height of a Point object in the following manner:
return height;}
public void setWidth(int theWidth){//assigns the width of a Point object as follows:
width = theWidth;}
public void setHeight(int theHeight{//assigns the height of a Point object as follows:
height = theHeight;
}
FigureGeometry.java Description:
The FigureGeometry interface should be declared as a public interface and should meet all the requirements listed below. Its purpose is to declare all the necessary methods that any geometric figure, such as a circle, rectangle, or square, should contain. The FigureGeometry interface should also declare a numeric constant, called PI, which can be used by classes that implement the FigureGeometry interface. Remember that method declarations in an interface should not include modifiers such as public, static, or abstract.
Declaring a method within an interface as static is illegal and will cause a compilation error. Additionally, the declaration of interface methods using public or abstract modifiers is redundant, and soon such declarations will be deprecated. Students should also note that the inclusion of instance variables within an interface declaration is not allowed; only static constants may be defined within an interface declaration, and the use of the static modifier on constants is also redundant. Basically, students should remember one general rule of thumb concerning interface declarations: Only one modifier should be used in an interface declaration--final should be used to declare constants.
public interface FigureGeometry{final float PI = 3.14f;
//Classes that implement the FigureGeometry interface MUST override this method which should return the geometric area of a figure:
//In an interface, methods are always public and abstract. Using these unnecessary modifiers is redundant, and future versions of
//Java may not support them.
float getArea ();
//Classes that implement the FigureGeometry interface MUST also override this method which should return the geometric perimeter of a //figure:
float getPerimeter ();}
Circle.java Description:
The Circle class should be declared as a public class that implements the FigureGeometry interface described above. Its purpose is to store the radius of a circular figure and provide the methods necessary to calculate the area and perimeter of such a figure.
Instance Variables:
private float radius;//stores the radius of a Circle object
Constructor: Circle()
Parameters:
float theRadius;
Purpose:initializes the radius of a Circle in the following manner:
radius = theRadius;
Methods:
1-public float getRadius(){//returns the radius of a Circle object as follows:
return radius;
}
2-public float getArea(){//returns the area of a Circle object as follows:
return getRadius() * getRadius() * PI;
3-public float getPerimeter(){//returns the perimeter of a Circle object as follows:
return getRadius() * 2 * PI;
}
4-public void setRadius(float theRadius){//assigns the radius of a Circle object as follows:
radius = theRadius;
}
The following coding example illustrates a version of the Circle class:
public class Circle implements FigureGeometry{//Stores the radius of this figure:
private float radius;
//Returns the radius of this figure:
public float getRadius (){return radius;}
//Returns the area of this figure:
public float getArea (){
return getRadius() * getRadius() * PI;}
//Returns the perimeter of this figure:
public float getPerimeter (){ return getRadius() * 2 * PI;}
//Assigns the radius of this figure:
public void setRadius (float theRadius){radius = theRadius;
}
}
Square.java Description:
The Square class should be declared as a public class that
implements the FigureGeometry interface and should meet all the
requirements listed below. Its purpose is to store the Point of a
square figure (using the Point class described above and provide
the methods necessary to calculate the area and perimeter of such a
figure.
Instance Variables:
private Point point; //stores the Point of a Square object
Constructor: Square()
Parameters:
Point p;
Purpose:initializes the object point of the Square object in the following manner:
point= p;
Methods:
1-public float getSideLength(){//returns the length of the side of the square as follows:
return point.getWidth();}
2-public float getArea(){//returns the area of a Square object as follows:
return getSideLength() *getSideLength();}
3-public float getPerimeter(){//returns the perimeter of a Square object as follows:
return getSideLength() * 4;}
4-public void setPoint(Point p){//assigns the point of a Square object as follows:
point= p;}
Rectangle.java Description:
The Rectangle class should be declared as a public class that implements the FigureGeometry interface described above. Its purpose is to store the Point of a rectangular figure (using the Point class described above) and provide the methods necessary to calculate the area and perimeter of such a figure.
Instance Variables:
private Point point;//stores the point of the Rectangle object
Constructor: Rectangle()
Parameters:
Point p;
Purpose: initializes the Point of a Rectangle object in the following manner:
point = p;
Methods:
1-public int getWidth()
{//returns the width of a Rectangle object as follows:
return point.getWidth();}
2-public int getHeight()
{//returns the height of a Rectangle object as follows:
return point.getHeight();}
3-public float getArea()
{//returns the area of a Rectangle object as follows:
return getWidth() * getHeight ();}
4-public float getPerimeter()
{//returns the perimeter of a Rectangle object as follows:
return (getWidth+getHeight()) * 2;}
5-public void setPoint(Point p)
{//assigns the point of a Rectangle object as follows:
point = p;}
TestAll.java Description:
The TestAll class should be declared as a public class and should meet all the requirements listed below. Its purpose is to implement a main method which creates three objects--a Circle object, a Square object, and a Rectangle object-- and test each of the files that have been designed above. You should already be familiar with how to instantiate objects and print values to the screen using System.out.println(...). Therefore, the actual implementation code for this assignment will not be provided. You may organize the output of data according to their own specifications. However, the main method must perform the following tasks:
Point.java
public class Point {
private int width;
private int height;
public Point(int width, int height) {
super();
this.width = width;
this.height = height;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
}
/////
FigureGeometry.java
public interface FigureGeometry
{
final float pi=3.14f;
float getArea();
float getParameter();
}
/////
Circle.java
public class Circle implements
FigureGeometry {
private float radius;
public float
getRadius() {
return radius;
}
public void
setRadius(float radius) {
this.radius = radius;
}
public Circle(float
radius) {
super();
this.radius = radius;
}
@Override
public float getArea() {
return
getRadius()*getRadius()*pi;
}
@Override
public float getParameter() {
return getRadius()*2*pi;
}
}
/////
Square.java
public class Square implements
FigureGeometry {
private Point point;
public Square(Point
point) {
super();
this.point = point;
}
public float getSideLength(){
return point.getWidth();
}
@Override
public float getArea(){
return getSideLength() *getSideLength();
}
@Override
public float getParameter() {
return getSideLength() * 4;
}
public void setPoint(Point p){
point= p;
}
}
////
Rectangle.java
public class Rectangle implements
FigureGeometry {
private Point point;
public Rectangle(Point
point) {
super();
this.point = point;
}
public Point
getPoint() {
return point;
}
public void
setPoint(Point point) {
this.point = point;
}
public int getWidth()
{
return point.getWidth();
}
public int getHeight()
{
return
point.getHeight();
}
@Override
public float getArea()
{
return getWidth() *
getHeight ();
}
@Override
public float getParameter() {
// TODO Auto-generated method
stub
return (getWidth()+getHeight()) *
2;
}
}
/////
Testall.java
public class Testall {
public static void main(String[] args) {
Circle c1=new Circle(5);
Point p1=new Point(5,7);
Point p2=new Point(5,7);
Square s1=new Square(p1);
Rectangle r1=new
Rectangle(p2);
System.out.println(c1.getRadius());
System.out.println(c1.getArea());
System.out.println(c1.getParameter());
System.out.println(s1.getSideLength());
System.out.println(s1.getArea());
System.out.println(s1.getParameter());
System.out.println(r1.getWidth());
System.out.println(r1.getHeight());
System.out.println(r1.getParameter());
System.out.println(r1.getArea());
}
}
THank YOU!!!!