Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Shapes First, define interface Relatable (borrowed from the text book code) /** Relatable interface */ public interface Relatable { boolean equals( Basic Shape s );

Shapes First, define interface Relatable (borrowed from the text book code)

/**

Relatable interface

*/

public interface Relatable

{

boolean equals(

Basic

Shape s

);

boolean isGreater(

Basic

Shape s

);

boolean isLess(

Basic

Shape s

);

}

Next, define a pure abstract base class called BasicShapethat implements Relatableinterface.Class must have the following:Protectedfield:?color, an array of 3 integers that are representing Red, Green,and Blue components in the color.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Implement all interface methods . Shapes must be compared by comparing the areas of shapes . Although calcAreal ) is defined as abstract , it can be used without limitations to implement the calculations needed to compare shapes . Next , define a class named Circle . It should be derived from the Basic shape class. It should have the following :" Private fields :` CENTERX , integer to hold* coordinate of the circle's center . CENTER { . integer to hold * coordinate of the circle's center . radius , integer to hold the radius of the circle . Public methods :` Non - argument constructor that sets all variables to I and color to black Constructor - accepts values for centers , center Y , radius , and color as an array of 3 integers . Constructor throws I 1 1 E Ja ] Argument EX CEP tion when radius is not a positive number or O the array must is not exactly 3 elements long or not all values in the array must be in the range 0 - 255 . Accessor and mutator methods for all non - inherited fields . Mutator for radius field must throw I 1 1 { q = ] A r qume n t E X C E F t. 1 On when all argument passed to method is not positive* . CalcArea - calculates and returns the area of the circle ( area - Math . PT* radius* radius ) Override of tostring ! ! . Override clone ( ) method . Use clone ( ) method examples we worked on . When adding clone ( ) method make sure to add implements Clone able statement to the class header . Otherwise the override will not compile . Don't forget to create deep copies whenever working with field of type ColorAccessor and mutator methods for all non - inherited fields. ` MIutators for length and width fields must throw* I 1 1 Eg & L Argument EX CEP tion when an argument passed to method is not positive* CALCATEE - calculates and returns the area of the rectangle (area = length* width ) ` Override of Lost ring ! ! that represents all the fields as strings Override cloner ; method I'd illustrate the concept of polymorphism :` I'm a file next to main! ! create a method public Static Void OrderSHADES ( BASICSHAPE ONE , EAGLESHAVE TWO. BasicShape three ; that prints out three shapes ordered by the size of the area from smallest to largest . ITse methods of Relatable interface to compare areas of the shapes . Test the method in mainly by creating a couple of Circles and a Rectangle object and passing all 3 into the order Shapes !" method .* Test all the classes and their methods you wrote in main . Place the mainD in a file* separate from all the classes . name the file Shapes Demo. java .Next. define a class named Rectangle . It should be derived from the BasicShape class . It should have the following fields and methods :" Private fields : CORRIERE integer to hold & coordinate of the rectangle's left upper collier . COTTLE T'T integer to hold & coordinate of the rectangle's left upper collier . 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 I and color to black . Constructor - accepts values for length , width , and color and sets fields . ` Throws I 1 1 E J a LA F JumEn t. EXCEPT ion when width or length are not positive numbers or color is nullShapes First , define interface Relatable ( borrowed from the text book code ) RELATEDLE interFace* public interface RELAtable boolean Equals ( BasicShape } ) ; boo ] E all 1 5 GreatEr ( BaEl [ Shape 5 )` BOOLEAN IS LESS ( BASICSHAPE } ) ; Next , define a pure abstract base class called Basic Shape that implements* Relatable interface . Class must have the following : Protected field : Color ; all array of } integers that are representing Red , Green , and Blue Components in the color . Public methods :" int [ ] get Co ] or ! ) accessor - returns an array of 3 integers . A deep copy of the field must be returned . void set Color ( int [ ] ] throws Illegal Argument Exception - 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* O all values in the array must be in the range 0 - 255 as they represent* colors . double calcArea ! ! , abstract method

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions