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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!