Purchase Solution

Constructing Shapes Through Inheritance and Aggregation

Not what you're looking for?

Ask Custom Question

****This is to be written in Java****

Using the attached files modify the code to use inheritance, an interface, and aggregation by completing the following steps:

1. In the Shape class, eliminate the concrete methods, area() and perimeter(); create an instance variable of type String called name; and make a constructor that requires a String, shapeName, as the name of the new Shape object. Keep the method getLocation(), and keep the Shape class abstract.

2. Create an interface, Shape2D, which will require the methods, area() and perimeter(), which were elimated from Shape.

3. Create a new class, Point, which inherits from Shape and contains two private instance variables of type int, x and y, which store the coordinates for the Point. Point should have both a default constructor and a constructor that takes two int values for the coordinates x and y. For the default constructor, set both x and y to zero.

4. Modify the class, Circle, to inherit from Shape as well as use the interface, Shape2D. Circle should have only two private instance variables: a double named, radius, and a Point object reference named, center. Circle should have two constructors, a default constructor and a constructor that takes a double as a new radius value and two ints as the x and y coordinates of the center. Circle does not store the x and y values as ints, but instead creates a Point object with these coordinates. The location of a Circle is the location of its center, Point.

5. Use the TestCircle.java program to test your classes until they are error-free .

Attached files:

TestCircle.java
Circle.java
Shape.java

****This is to be written in Java****

Purchase this Solution

Solution Summary

Using the attached files modify the code to use inheritance, an interface, and aggregation by completing the following steps.

Purchase this Solution


Free BrainMass Quizzes
Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Basic Networking Questions

This quiz consists of some basic networking questions.

Javscript Basics

Quiz on basics of javascript programming language.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.