Results 1 to 6 of 6
  1. #1
    playtodie is offline Member
    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0

    Default Assistance with my coding project? (Morse Code)


    So basically I need help creating a program to convert 10 numbers into Morse Codes. I don't know how to declare the morse codes into an array, and I don;t really know the next step from here. I am also using BlueJ to write my Java codes.



    The number system in Morse code follows a predictable pattern of a series of dots followed by a series of dashes; Or a series of dashes followed by a series of dots. Your assignment is to develop a "translator" that will convert the dots and dashes given to you as an input string into an actual readable number. For the dots, you will use the period ('.'). For the dashes, you will use the minus symbol (-).

    Your program should prompt the user to enter a Morse Code string. Then, your program should return the corresponding numbers to the entered Morse Code string following the pattern described in the table below.

    For any five dot and dash sequence that does not correspond to a number, the message "NaN" (e.g.,Not a Number) should be displayed.


    Your program needs to be able to accept any length of string as input.
    Example:
    Please enter the Morse Code: .....-----..
    Output: 50NaN


    Codes

    Numbers

    1 .----
    2 ..---
    3 ...--
    4 ....-
    5 .....
    6 -....
    7 --...
    8 ---..
    9 ----.
    0 -----

    Note that there is NO space between each of the entered characters.

    My code:



    import acm.program.*;
    import java.util.*;

    public class MorseConverter extends ConsoleProgram
    {

    /**
    * Creates Morse Code.
    */
    public void run()
    {

    println("This program will translant Morse Codes into numbers.");
    String sentence = readLine("Please enter the Morse Code: ");
    println("Output: " + translateLine(sentence));
    }

    int x = 0;
    /**
    * Translates the Morse Code.
    */
    public String translateLine(String sentence)
    {
    String result = "";
    for (int i = 0; i < sentence.length(); i++)
    {
    char code = sentence.charAt(x);
    result = result + x;
    x++;
    }
    int stuff;
    if (results == 1)
    {

    }
    }
    }


    I suck at coding, so any input would be greatly appreciated. Thank you!
    Last edited by playtodie; 04-04-2013 at 05:32 AM.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Assistance with my coding project? (Morse Code)

    Start small and build up your program incrementally. First start by reading in user input and displaying it to the screen. Once you have this then add the functionality of splitting the input string into 5 char substrings and print each of them to the screen. Then move onto converting each substring into an int value. Look at the table, do you see a pattern? It has to do with how many dots or dashes each substring begins with. Any substring (ie the last one) that is less than 5 chars long is NaN.

  3. #3
    playtodie is offline Member
    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0

    Default Re: Assistance with my coding project? (Morse Code)

    What do you mean by splitting the input string into 5 char substrings and print each of them to the screen?

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Assistance with my coding project? (Morse Code)

    What don't you understand, why split the String into 5 char substrings or how to do it?

  5. #5
    playtodie is offline Member
    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0

    Default Re: Assistance with my coding project? (Morse Code)

    How to split the String into 5 char?

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Assistance with my coding project? (Morse Code)

    The String class has a substring method that allows you to specify where to begin and end the substring. Repeat this in a loop until you can split the entire String. The tricky part will be if the length of the String input is not a multiple of 5.

Similar Threads

  1. [HELP] morse code java program
    By g_who in forum New To Java
    Replies: 14
    Last Post: 10-24-2012, 06:15 PM
  2. Morse Code Help Please!!
    By javaa in forum New To Java
    Replies: 25
    Last Post: 09-28-2012, 04:28 AM
  3. Battleship Program Coding Assistance
    By nekaneka19 in forum New To Java
    Replies: 7
    Last Post: 03-21-2012, 07:26 PM
  4. Morse code translation?
    By Koba in forum New To Java
    Replies: 6
    Last Post: 10-10-2011, 12:48 AM
  5. Morse Code
    By Jamison5213 in forum New To Java
    Replies: 6
    Last Post: 04-14-2010, 05:56 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
  •