Question: Please use JAVA! Problem Shapes First, add Relatable interface to your project. Code for the interface is provided and can be found in Relatable.java /**
Please use JAVA!
Problem Shapes
First, add Relatable interface to your project. Code for the interface is provided and can be found in Relatable.java
/** Relatable interface */ public interface Relatable { boolean equals(Object s); boolean isGreater(Object s); boolean isLess(Object s); }
Basic Shape Class
Define an abstract base class called BasicShape that implements Relatable interface.
Class must have the following:
Protected field:
- color, an array of 3 integers that are representing Red, Green, and Blue components in a color.
Public methods:
- Non-argument constructor that sets color to white all three values 255
- Constructor that takes 3 parameters (in order red, green, blue), and sets the array values in this same order. Constructor throws IllegalArgumantException when any one of three given values are not in the range [0, 255]
- int[] getColor()accessor - returns an array of 3 integers. A deep copy of the field must be returned.
- void setColor (int[]) throws IllegalArgumantException - mutator method for color field. The array must be validated and exception must be thrown in case the values passed are not valid
- the array must be exactly 3 elements long
- all values in the array must be in the range 0 255 as they represent colors.
- Deep copy of the array must be made
- double getArea(), abstract method.
- Implement all interface methods. Shapes must be compared by comparing the areas of shapes. Although getArea() is defined as abstract, it can be used without limitations to implement the calculations needed to compare shapes.
Circle Class
Define a class named Circle. It should be derived from the BasicShape class. It should have the following:
Private fields:
- centerX, integer to hold x coordinate of the circles center.
- centerY, integer to hold y coordinate of the circles center.
- radius, integer to hold the radius of the circle.
Public methods:
- Non-argument constructor that sets all variables to 1 and color to white. Call on parent constructor to set the color field.
- Constructor accepts values for centerX, centerY, radius, and color as an array of 3 integers. Call on parent constructor to set the color field. Constructor throws IllegalArgumentException when
- radius is not a positive number or
- the array is not exactly 3 elements long or
- not all values in the array in the range 0 255
Make sure to call parent constructor first. This will take care of colors array validation
- Accessor and mutator methods for all non-inherited fields.
- Mutator for radius field must throw IllegalArgumentException when an argument passed to method is not positive
- getArea calculates and returns the area of the circle
- Override of toString().
- Override clone() method. Use clone() method examples we worked on in class. When adding clone() method make sure to add implements Cloneable statement to the class header. Otherwise the override will not compile.
Dont forget to create deep copies whenever working with field of type Color.
Rectangle Class
Define a class named Rectangle. It should be derived from the BasicShape class. It should have the following fields and methods:
Private fields:
- cornerX integer to hold x coordinate of the rectangles left upper corner.
- cornerY integer to hold y coordinate of the rectangles left upper corner.
- width, integer to hold the width of the rectangle.
- length, integer to hold the length of the rectangle.
Public methods:
- Non-argument constructor that sets all variables to 1 and color to white.
- Constructor accepts values for length, width, and color and sets fields. Throws IllegalArgumentException when
- width or length are not positive numbers
- the array is not exactly 3 elements long or
- not all values in the array must be in the range 0 255
Make sure to call parent constructor first. This will take care of colors array validation
- Accessor and mutator methods for all non-inherited fields.
- Mutators for length and width fields must throw IllegalArgumentException when an argument passed to method is not positive
- getArea calculates and returns the area of the rectangle
- Override of toString() that represents all the fields as strings
- Override clone() method
Testing
BasicShape class cannot be instantiated. Because of that it cannot be directly tested. I will be carefully reading your code to make sure all the fields and methods are written according to the specs. All methods will be tested later in the derived classes. BasicShape class implementation constitutes 10 pts. of the total assignment grade.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
