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
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started