Thisassignmentcontainsfour classes.
undefinedundefined
First class: GeometricObject
undefinedundefined
Attributes:
undefined
private String color;
undefined
private double weight;
undefined
Default constructor
undefined
public GeometricObject( )
{
color = “white”;weight = 1.0; }
undefined
Another constructor
undefined
public GeometricObject(String color, double weight)
undefined
{ this.color = color; this.weight = weight; }
undefined
Getters and setters
undefined
public String getColor( ) { return color; }
undefined
public void setColor( String color ) { this.color = color; }
undefined
public double getWeight() { return weight; }
undefined
public void setWeight( double weight ) { this.weight = weight;}
undefined
Two methods to be overridden
undefined
public double calculateArea();
undefined
public double calculatePerimeter();
undefined
Second class: Circlethat extends the class GeometricObject to represent circles. You are asked to provide the overridden definitions of the two methods.
undefined
public class Circle extends GeometricObject
undefined{undefined
private double radius;
undefined
// Default constructor
undefined
public Circle( ) {}
undefined
// Construct circle with specified radius
undefined
public Circle( double radius ) {}
undefined
// Construct a circle with specified radius, weight, and color
undefined
public Circle( String color, double weight, double radius ) {}
undefined
//Getters and setters
undefined
public double getRadius( ){}
undefined
public void setRadius( double radius ){}
undefined
Two overriding methods
undefined
public double calculateArea() { };
undefined
public double calculatePerimeter() {};
undefined
}
undefined
Third Class: Rectanglethat extends the class GeometricObject to represent rectangles. You are asked to provide the overridden definitions of the two methods.
undefined
public class Rectangleextends GeometricObject
undefined{undefined
private double width;
undefined
private double height;
undefined// Default constructorundefined
public Rectangle ( ) {}
undefined
// Another constructor with given parameters
undefined
public Rectangle ( double width, double height, String color, String weight ) {};
undefined
// Getters and setters for instance variables: width and height
undefined
// Two overriding methods
undefinedpublic double calculateArea() { };undefinedpublic double calculatePerimeter() {};undefined
}
undefined
Fourth class:
undefined
In the main program, use (one) super class reference and subclass objects to do the following:
undefined
- Create two different Circle objects using the two respective constructors, and then let these different objects call the overridden methods to display their areas and perimeters respectively.
undefined
- Create two different Rectangle objects using the two respective constructors, and then let these different objects call the overridden methods to display their areas and perimeters respectively.
This assignment contains four classes.
First class: GeometricObject
Attributes:
private String color;
private double weight;
Default constructor
public GeometricObject( ) { color = “white”; weight = 1.0; }
Another constructor
public GeometricObject(String color, double weight)
{ this.color = color; this.weight = weight; }
Getters and setters
public String getColor( ) { return color; }
public void setColor( String color ) { this.color = color; }
public double getWeight() { return weight; }
public void setWeight( double weight ) { this.weight = weight; }
Two methods to be overridden
public double calculateArea();
public double calculatePerimeter();
Second class: Circle that extends the class GeometricObject to represent circles. You are
asked to provide the overridden definitions of the two methods.
public class Circle extends GeometricObject
{
private double radius;
// Default constructor
public Circle( ) { }
// Construct circle with specified radius
public Circle( double radius ) { }
// Construct a circle with specified radius, weight, and color
public Circle( String color, double weight, double radius ) {
}
// Getters and setters
public double getRadius( ){ }
public void setRadius( double radius ){
Two overriding methods
public double calculateArea() {
};
public double calculatePerimeter() {
}
};
}
Third Class: Rectangle that extends the class GeometricObject to represent rectangles.
You are asked to provide the overridden definitions of the two methods.
public class Rectangle extends GeometricObject
{
private double width;
private double height;
// Default constructor
public Rectangle ( ) {
}
// Another constructor with given parameters
public Rectangle ( double width, double height, String color, String weight ) {
};
// Getters and setters for instance variables: width and height
// Two overriding methods
public double calculateArea() {
};
public double calculatePerimeter() {
};
}
Fourth class:
In the main program, use (one) super class reference and subclass objects to do the
following:
1. Create two different Circle objects using the two respective constructors, and then
let these different objects call the overridden methods to display their areas and
perimeters respectively.
2. Create two different Rectangle objects using the two respective constructors, and
then let these different objects call the overridden methods to display their areas
and perimeters respectively.