• Home
  • Blog
  • University of South Carolina Aiken GeometricObject Programming Questions

University of South Carolina Aiken GeometricObject Programming Questions

0 comments

This assignment contains four classes.

undefined

undefined

First class: GeometricObject

undefined

undefined

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: Circle that 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: Rectangle that extends the class GeometricObject to represent rectangles. You are asked to provide the overridden definitions of the two methods.

undefined

public class Rectangle extends GeometricObject

undefined

{

undefined

private double width;

undefined

private double height;

undefined

// Default constructor

undefined

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

undefined

public double calculateArea() { };

undefined

public double calculatePerimeter() {};

undefined

}

undefined

Fourth class:

undefined

In the main program, use (one) super class reference and subclass objects to do the following:

undefined

  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.

undefined

  1. 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.

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}