Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java I need to you write the classes needed so that this code works (i.e. write the drawing class, shape classes etc). I'm particularly having

Java

image text in transcribed

I need to you write the classes needed so that this code works (i.e. write the drawing class, shape classes etc). I'm particularly having trouble with the print method. I also need you write the setColour method so that it produces an error if the parameter values other than "Green", "White", or "Gold" are used. It should not be case sensitive so "green", "white" and "gold" must be fine as well. Here is what I have so far:

public abstract class Shape {

}

import java.util.ArrayList; public class Drawing extends Shape { Shape shape; String colour; ArrayList shapes = new ArrayList(); public Drawing() { super(); } public void setColour(String colour) { this.colour=colour; } public boolean add(Shape shapeObject) { return shapes.add(shapeObject); } public void print() { } }

public class Triangle extends Shape { public Triangle() { } }

public class Circle extends Shape { public Circle() { } }

public class Test { public static void main(String[] args) { Shape tri1 = new Triangle(); Shape tri2 = new Triangle(); Shape cir1 = new Circle(); Drawing drawing1 = new Drawing(); Drawing drawing2 = new Drawing(); Drawing drawing3 = new Drawing(); drawing3.add(tri2); drawing2.add(tri1); drawing2.add(drawing3); drawing1.add(cir1); drawing1.add(drawing2); drawing1.setColour("Green"); drawing1.setColour("White"); drawing1.setColour("Gold"); drawing1.print(); } }

public static void main(String] args) Shape tri1- new TriangleO Shape tri2 = new Triangle(); Shape cir = new Circle(); Drawing drawing = new Drawing(); Drawing drawing2 = new Drawing(); Drawing drawing3 new Drawing(); drawing3.add(tri2); drawing2.add(tri1); drawing2.add drawing3); drawing1.add(cirl); drawing1.add(drawing2); drawing1.setColourC" Green"); drawing2.setColourC" White"); drawing3.setColour " Gold"): drawing1.print; Output: Drawing Circle with color Green Drawing Triangle with color White Drawing Triangle with color Gold

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

7. Where Do We Begin?

Answered: 1 week ago

Question

a. What is the purpose of the team?

Answered: 1 week ago

Question

b. What are its goals and objectives?

Answered: 1 week ago