I Don't Understand my Java Class At All, And I Dont Understand What This Assignment Is Asking. We Are Working With Turtle For Java.
Assignment
[SPOIL]
Add another method to the Turtle class you updated in Assignment #4. Called draws,
this method will receive an array of Strings. Each string contains the same two-word
information sent into the draw method you created for Assignment 4. Your new method
will read each String and call draw to display the specified shape in the specified color.
[/SPOIL]
This Was My Assignment #4 Draw Method he wants to get the information sent to
Code:
public void draw(String input) {
String[] parsedInput = input.split(" ");//Splits with space
String color = parsedInput[0].toLowerCase();//Puts strings into all lower case to avoid errors
String shape = parsedInput[1].toLowerCase();
switch(color) {
case "black" :
this.setPenColor(java.awt.Color.BLACK);
break;
case "blue" :
this.setPenColor(java.awt.Color.BLUE);
break;
case "green" :
this.setPenColor(java.awt.Color.GREEN);
break;
case "red" :
this.setPenColor(java.awt.Color.RED);
break;
case "orange" :
this.setPenColor(java.awt.Color.ORANGE);
break;
case "yellow" :
this.setPenColor(java.awt.Color.YELLOW);
break;
case "white" :
this.setPenColor(java.awt.Color.WHITE);
break;
case "gray" :
this.setPenColor(java.awt.Color.GRAY);
break;
default://If invalid input
System.out.println("This Color Is Not Supported");
break;
}
switch(shape) {
case "rectangle" :
this.drawRectangle();
break;
case "triangle" :
this.drawTriangle();
break;
case "square" :
this.drawSquare();
break;
default://If invalid input
System.out.println("This Shape Is Not Supported");
break;
}
}
I came up with this but he said its wrong
Code:
public void draws(String selection) {
String[] selection2 = selection.split(" ");
this.draw(selection2[0] + " " + selection2[1]);
}
He Responded With This
[SPOIL]draws() does not receive a SINGLE String as parameter, but receives an ARRAY of Strings. That's how the array comes into the method.[/SPOIL]
Can Someone Please Help Me?