Results 1 to 6 of 6
  1. #1
    ghjk is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Homework Help please!

    So I have been able to achieve the problems before this one.

    Here is the directions to which I have to do.


    The class, DotDashLetters2, is also an extension of the Java code found in the DotDash class of Exercise 1. It contains header comments and method headers for one additional user-defined void method. This method takes a single parameter (char letter) and displays its corresponding dot-dash pattern followed by a space.

    a. Add code to the method, doLetter(), to produce the associated dot-dash patterns as given in the table found in Exercise 2. Your logic must invoke only the methods dot(), dash() and space() to produce each required pattern.

    b. Add logic as indicated by comments in the main method to produce patterns corresponding to the words, “to”, “ate” and “tattoo”. Each pattern must be displayed on a single line. Your logic must use only the methods doLetter() and end() to produce each pattern. The required output is the same as for Exercise 2.

    Here is my code
    Java Code:
    public class DotDashLetters2 {
    
    	public static void dot() {
    		System.out.print(".");
    	}
    
    	public static void dash() {
    		System.out.print("-");
    	}
    
    	public static void space() {
    		System.out.print(' ');
    	}
    
    	public static void end() {
    		System.out.println();
    	}
    
    	public static void doLetter(char letter) {
    		
    		
    	}
    	
    
    	public static void main(String[] args) {
    
    		// 1. ADD logic to display the word, "to", on the console
    		
    		// 2. ADD logic to display the word, "ate", on the console
    		
    		// 3. ADD logic to display the word, "tattoo", on the console
    	}
    
    	}
    I need my output to be look like this.
    Java Code:
    - --- 
    .- - . 
    - .- - - --- ---
    I basically have to add something into the Void doLetter part, but I really dont know what. I missed my class that day. Can anyone help me out?
    Last edited by Fubarable; 03-18-2012 at 09:01 PM.

  2. #2
    rokit boy is offline Member
    Join Date
    Feb 2012
    Posts
    35
    Rep Power
    0

    Default Re: Homework Help please!

    Is it like decoding morse code?

  3. #3
    rokit boy is offline Member
    Join Date
    Feb 2012
    Posts
    35
    Rep Power
    0

    Default Re: Homework Help please!

    It is definitely morse code.
    I'll start off.
    Java Code:
    public static void doLetter(char letter) {
    if letter.equals(t) {
        dash();
        space();
    }       
    }
    For morse code goto: http://www.google.co.uk/imgres?q=mor...:0&tx=85&ty=23

  4. #4
    ghjk is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Homework Help please!

    I receive an error when I do this. Something about how cannot compare..and it needs to be a string.

    It might be morse code, im not sure, but In the end, i have to type in the word "to" and it does the dashes and periods. Any more help? ):

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Homework Help please!

    char are primitives, and you cannot call methods on primitives. Instead check if the letter == 't', not if letter.equals(t) (which makes no sense any way since t is then thought to be an undeclared variable.

  6. #6
    ghjk is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Homework Help please!

    That worked, setting it to ==. Now I just need to get the pattern set (: Thanks for the help. If i need more help ill post back!

Similar Threads

  1. Homework help
    By lackingunderstanding4now in forum New To Java
    Replies: 4
    Last Post: 11-08-2010, 03:18 AM
  2. Help me pls It is my homework:(
    By pinar in forum New To Java
    Replies: 3
    Last Post: 10-19-2010, 10:11 PM
  3. Please Help with Homework
    By theuser in forum Advanced Java
    Replies: 2
    Last Post: 07-30-2009, 03:37 PM
  4. Homework help...
    By robrobrob in forum New To Java
    Replies: 4
    Last Post: 10-17-2008, 04:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •