The primary focus of this assignment is the use of interfaces. In programming, an interface is a public avenue by which data can be accessed and/or manipulated. 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 Point.java Description: 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: 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: 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: 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: 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 main method must perform the following tasks: an instance of Circle, called c1, with a radius of 5. an instance of a Point, called p1, with a side length of 5. an instance of a Point, called p2, with a side length of 5 and a side height of 7. an instance of a Square, called s1, with a parameter p1. an instance of Rectangle, called r1, with a parameter p2. Print the radius of c1. Print the area of c1. Print the perimeter of c1. Print the side length of s1. Print the area of s1. Print the perimeter of s1, Print the width of r1. Print the height of r1. Print the area of r1. Print the perimeter of r1.
The primary focus of this assignment is the use of interfaces. In programming, an interface is a public avenue by which data can be accessed and/or manipulated.
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
Point.java Description:
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:
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:
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:
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:
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 main method must perform the following tasks:
- an instance of Circle, called c1, with a radius of 5.
- an instance of a Point, called p1, with a side length of 5.
- an instance of a Point, called p2, with a side length of 5 and a side height of 7.
- an instance of a Square, called s1, with a parameter p1.
- an instance of Rectangle, called r1, with a parameter p2.
- Print the radius of c1.
- Print the area of c1.
- Print the perimeter of c1.
- Print the side length of s1.
- Print the area of s1.
- Print the perimeter of s1,
- Print the width of r1.
- Print the height of r1.
- Print the area of r1.
- Print the perimeter of r1.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 6 images