Question
Java Basic Shape Class Start with BasicShape.java provided with assignment files. Class already has the field written in. It also extends HasState class, please do
Java
Basic Shape Class
Start with BasicShape.java provided with assignment files. Class already has the field written in. It also extends HasState class, please do not change this hierarchy. HasState is provided with the assignment files.
In addition, BasicShape must be defined as an abstract that implements Relatable interface.
Class must have the following fields and methods:
Protected field - already there:
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. IMPORTANT note:
two shapes cannot be equal when they belong to different types even if their areas are equal.
isLess() and isGreater() can be used for two shapes of different types.
HasState.java
import java.util.*;
public class HasState {
private int state;
public HasState()
{
Random rand = new Random();
state = rand.nextInt(1000)+1; // range [1, 1000]
}
public int getState()
{
return state;
}
public void changeState()
{
Random rand = new Random();
state = rand.nextInt(1000)+1; // range [1, 1000]
}
}
Relatable.java
public interface Relatable
{
public boolean equals(Object s);
public boolean isGreater(Object s);
public boolean isLess(Object s);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started