Thread: Java Homework Help

Results 1 to 7 of 7
  1. #1 Java Homework Help 
    Registered Member #Butthole's Avatar
    Join Date
    Apr 2012
    Posts
    88
    Thanks given
    3
    Thanks received
    14
    Rep Power
    37
    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?
    Regards -
    #Butthole
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Nov 2013
    Posts
    270
    Thanks given
    107
    Thanks received
    76
    Rep Power
    0
    String[] selection
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    q.q


    Join Date
    Dec 2010
    Posts
    6,519
    Thanks given
    1,072
    Thanks received
    3,535
    Rep Power
    4752
    Code:
    input[0] = readString();
    input[1] = readString();
    draw(input);
    Reply With Quote  
     

  5. #4  
    Ignorance is always an excuse

    Mikee's Avatar
    Join Date
    Nov 2009
    Posts
    2,370
    Thanks given
    732
    Thanks received
    490
    Rep Power
    656
    Quote Originally Posted by #Butthole View Post
    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.
    Code:
    public void draws(String[] arrayOfStrings) {
    	if (arrayOfStrings != null) {
    		for (int i = 0; i < arrayOfStrings.length; i++) {
    			if (arrayOfStrings[i] != null) {
    				draw(arrayOfStrings[i]);
    			}
    		}
    	}
    }



    The day Aj repped me, my life changed forever
    Quote Originally Posted by Aj View Post
    Rep++ for you
    Reply With Quote  
     

  6. #5  
    Registered Member #Butthole's Avatar
    Join Date
    Apr 2012
    Posts
    88
    Thanks given
    3
    Thanks received
    14
    Rep Power
    37
    Quote Originally Posted by Mikee View Post
    Code:
    public void draws(String[] arrayOfStrings) {
    	if (arrayOfStrings != null) {
    		for (int i = 0; i < arrayOfStrings.length; i++) {
    			if (arrayOfStrings[i] != null) {
    				draw(arrayOfStrings[i]);
    			}
    		}
    	}
    }
    Im getting this error when i try to call the method :
    Code:
    Static Error: No method in Turtle with name 'draws' matches this invocation
        Arguments: (String)
        Candidate signatures: void draws(String[])
    Regards -
    #Butthole
    Reply With Quote  
     

  7. #6  
    Registered Member
    Join Date
    May 2009
    Posts
    502
    Thanks given
    4
    Thanks received
    42
    Rep Power
    22
    Quote Originally Posted by #Butthole View Post
    Im getting this error when i try to call the method :
    Code:
    Static Error: No method in Turtle with name 'draws' matches this invocation
        Arguments: (String)
        Candidate signatures: void draws(String[])
    Show the line where you're calling it.

    What the error in your quote is simply saying is you're passing in a regular string as a parameter when you call the draws method, it requires a string array.
    Reply With Quote  
     

  8. #7  
    Ignorance is always an excuse

    Mikee's Avatar
    Join Date
    Nov 2009
    Posts
    2,370
    Thanks given
    732
    Thanks received
    490
    Rep Power
    656
    Quote Originally Posted by Ike View Post
    What the error in your quote is simply saying is you're passing in a regular string as a parameter when you call the draws method, it requires a string array.
    Yeah basically you're trying to call the method "draws" with a String argument instead of an Array of Strings as the argument.

    So basically you can't do this:

    Code:
    draws("red triangle");
    but you can do this:

    Code:
    draws(new String[] {
    	"red triangle",
    	"blue square",
    	"green circle",
    });
    or even if you only need to enter one string, you can have an array with only one value inside like this:

    Code:
    draws(new String[] { "red triangle" });



    The day Aj repped me, my life changed forever
    Quote Originally Posted by Aj View Post
    Rep++ for you
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Simple Java Homework, HELP!!
    By #Butthole in forum Homework
    Replies: 2
    Last Post: 03-13-2014, 01:48 AM
  2. Java homework help.
    By FoReal in forum Homework
    Replies: 12
    Last Post: 01-05-2014, 06:54 AM
  3. Java Application help plz!
    By T9X in forum Help
    Replies: 3
    Last Post: 04-09-2009, 01:38 AM
  4. [508] server.java compile help
    By 1kk4 in forum Help
    Replies: 10
    Last Post: 02-22-2009, 08:14 PM
  5. Replies: 6
    Last Post: 01-16-2009, 10:26 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •