Results 1 to 2 of 2

Thread: output error

  1. #1
    mentoes178 is offline Member
    Join Date
    Jun 2013
    Rep Power

    Default output error

    No output :(

    i am trying to get the program to out put the translated to morsecode text. it should reade from the file and translate to morse and output the code...

    Java Code:
    import javax.swing.JOptionPane;
    public class Morse
        public static void main(String[] args)throws IOException
            String userInput;
            final String SENTINEL = "0";//for exiting program when entered
            //object creation
            Translate text = new Translate();
            //getting user input to be translated
                userInput = JOptionPane.showInputDialog("Please enter what you wish to translte to Morse code (no punctuation).");
                String compare = userInput.toUpperCase();
                String[] codedText = new String[compare.length()];
                codedText = text.translateHere(compare);
                text.toString(userInput, codedText);
        }//end main
    }//end class
    Java Code:
    import java.util.Scanner;
    public class Translate {
     public Translate()
        }//end default constructor
        public String[] translateHere(String s)throws IOException
            String compare = s, codedLine = "";  //userInput toUpperCase
            int length = compare.length();  //length of userInput
            String line, file = "Morse.txt";// variable holding file name and variable for each letter/number
            char code;
            final int MAX = 36;
            char[] morseLetter = new char[MAX];
            String[] morseCode = new String[MAX];
            String[] newMessage = new String[length];
            //putting user input in a character array;
            char[] userLetters = compare.toCharArray();
            //object creation
            File openFile = new File(file);
            Scanner inFile = new Scanner(openFile);
            int  counter = 0;
                    line =;
                    code = (char)line.charAt(0);
                    morseLetter[counter] = code;
                    morseCode[counter] =;
                }//end nested while loop
            for(int j = 0; j < length; j++)
                for(int k = 0; k < MAX; k++)
                    if(userLetters[j] == morseLetter[k])
                        newMessage[j] = morseCode[k];
                }//end nested for loop
            }//end for loop
            return newMessage;
        }//end method that completes translateion
        public String toString(String a, String[] b)
       System.out.println("Input: " + a);
       String output = "";
       for(int i = 0; i < b.length; i++)
          output = output + b[i];
       return output;
     }//end toString method
    }//end Translate Class

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: output error

    Please don't create multiple threads for one and the same problem; I'm closing this thread.

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Error output
    By Kartright in forum New To Java
    Replies: 5
    Last Post: 05-30-2013, 05:28 AM
  2. Replies: 2
    Last Post: 05-03-2012, 11:39 AM
  3. Need help with input/output program error
    By stefan2892 in forum New To Java
    Replies: 2
    Last Post: 02-07-2011, 07:57 PM
  4. OutPut Error :/
    By socboy6579 in forum New To Java
    Replies: 2
    Last Post: 12-12-2010, 09:03 PM
  5. Two Class Program but No Output or Error
    By H0AX in forum New To Java
    Replies: 2
    Last Post: 12-09-2010, 06:27 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