Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

from the below o Main.java o Shape.java o Colored.java Create the following classes which implements Shape and Colored: o Square.java o Circle.java o Rectangle.java import

from the below o Main.java o Shape.java o Colored.java

Create the following classes which implements Shape and Colored:

o Square.java o Circle.java o Rectangle.java

import java.security.SecureRandom;

/* * * DO NOT CHANGE THIS CODE * * */ public class Main { public static void main(String[] args) { SecureRandom random = new SecureRandom(); double squareEdge = random.nextInt(10)+1; double radius = random.nextInt(10)+1; double rectangleWidth = random.nextInt(10)+1; double rectangleHeight = random.nextInt(10)+1; System.out.println("squareEdge = " + squareEdge); System.out.println("radius = " + radius); System.out.println("rectangleWidth = " + rectangleWidth); System.out.println("rectangleHeight = " + rectangleHeight); Square square = new Square(squareEdge, "blue"); Circle circle = new Circle(radius, "red"); Rectangle rectangle = new Rectangle(rectangleWidth, rectangleHeight, "yellow"); System.out.println(" Checking shapes..."); checkShape(square, squareEdge*4, squareEdge*squareEdge); checkShape(circle, Math.PI * radius * 2, Math.PI * Math.pow(radius, 2)); checkShape(rectangle, (rectangleWidth+rectangleHeight)*2, rectangleWidth*rectangleHeight); System.out.println(" Checking colors..."); checkColor(square, "blue"); checkColor(circle, "red"); checkColor(rectangle, "yellow"); } public static void checkShape(Shape shape, double expectedCircumference, double expectedArea) { if(shape.getCircumference() != expectedCircumference) { System.out.println("[X] - "+shape.getClass().getName()+" circumference " + shape.getCircumference() + " but expected " + expectedCircumference); } else { System.out.println("[OK] - "+shape.getClass().getName()+" circumference = " + shape.getCircumference()); } if(shape.getArea() != expectedArea) { System.out.println("[X] - "+shape.getClass().getName()+" area " + shape.getArea() + " but expected " + expectedArea); } else { System.out.println("[OK] - "+shape.getClass().getName()+" area = " + shape.getArea()); } } public static void checkColor(Colored colored, String expectedColor) { if(! colored.getColor().equals(expectedColor)) { System.out.println("[X] - "+colored.getClass().getName()+" color " + colored.getColor() + " but expected " + expectedColor); } else { System.out.println("[OK] - "+colored.getClass().getName()+" color = " + colored.getColor()); } } }

---------------------------------------------------------------------------------------------

/* * * DO NOT CHANGE THIS CODE * * */ public interface Colored { /** * * @return the color of */ public String getColor();

---------------------------------------------------------------------------------------------

/* * * DO NOT CHANGE THIS CODE * * */ public interface Shape { /** * * @return - the circumference of the shape */ public double getCircumference(); /** * * @return - the area of the shape */ public double getArea(); } }

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_2

Step: 3

blur-text-image_3

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

To find out what an organisation's strategy can understand from:

Answered: 1 week ago