EDIT (CODE IN TEXT): public static void wain(String0 args) { Shape tri1 = new Tr
ID: 3869093 • Letter: E
Question
EDIT (CODE IN TEXT):
public static void wain(String0 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);
drawingLadd(tri1);
drawingZ.add(drawing3);
drawing1.add(cir1);
drawing1.add(drawing2);
drawing1.setColour("Green");
drawing2.setColour('White");
drawing3.setColour("Gold");
drawing1.print();
}
Explanation / Answer
Answer for this Question:
See the below method to add try catch block in setColour method, It will handle the excepton.
public void setColour(String color)
{
try
{
if(color.equals("Green") || color.equals("green") || color.equals("White") || color.equals("white") || color.equals("Gold") ||color.equals("gold")) throw "Error"
// Try block to handle code that may cause exception
} catch (String e) {
// This block is to catch divide-by-zero error
System.out.println("Error: Set Color is not accept "+e);
}
System.out.println("I'm out of try-catch block in Java.");
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.