Question: 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

Java I need to you write the classes needed so that this

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

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!