- Where Developers Learn, Share, & Build Careers


OK I know there is an answer to other Morse code, but I've seen many people, but none of them Does not even work. Give me a file for my assignment, Morse. The test was to be read in parallel eras. Instead I have two files, Morsi Texty and alphabet. One is created with code and second number and alphabet. I should use a class designed for the translated part and in the main it should translate the user input. I have not been able to do this work. I have tried to do a lot of things by using the classroom or the use of the storking, but when I put it in the loop, which I think is to be there (if it makes sense Is not back). Anyway here my code is main:

  import java.util. *; Import java.util.Scanner; Import java.io * *; Public class again throws IOException {Stable [] arguments {String Line], file 2 = "Morse test"; String line, file = "alphabet.txt"; File open file = new file (file); File open file 2 = new file (file2); Scanner infix = new scanner (openfile); Scanner Inphil 2 = New Scanner (OpenFile2); Int index = 36; Four [] charArray = new four [index]; String [] code = new string [index]; For (index = 0; index & lt; 36; index ++) {while (inFile.hasNext ()) {line = inFile.nextLine (); CharArray = line.toCharArray (); //System.out.println(charArray[Inx]]; }} For (index = 0; index <->; index ++) {while (inFile2.hasNext ()) {code [index] = inFile2.nextLine (); //System.out.println(code[index]); }} Scanner Keyboard = New Scanner (System.in); String user input; System.out.println ("Write something to translate:"); UserInput = keyboard.nextLine (); Translate input translation = new translation (userInput); InputTranslate.setInput (userInput); InputTranslate.setAlph (charArray); InputTranslate.setCode (code); InFile.close (); }}   

And here is my class translation (some things are commented):

  Translation of the public class {string input; String code []; Four letters []; Public translation (string input) {this.input = input; } Public Zero Set Input (string input) {this.input = input; } Public Zero Set LF (four [] alpha) {this.alph = alpha; } Public Zero Setcode (string [] code) {this.code = code; } Public string getInput () {return input; } // public string getTranslate () // {// (for (ii) I   

Morse.txt:

.---- ..--- ...-- ....-.... -... -... --- ..

----.

.- -... -.-. - .. ..- -. .... .. ..---- -.-

.- ..

-.

.--. - --.-.-

...

..- ...- .-- -..- -... - .. .. .. ..

Alphabet.txt: 1 2 3 4 5 6 7 8 9 ABCDEFGHIJLMNOPQRTUVWYcZ

What is the problem Your return can not reach "output", you need to declare "output" over the loop and start it in output = null;

Even then it only sends a string, so I did it;

  public string getTranslate () {string output = zero; String [] translated = new string [input.length ()]; For (int i = 0; i & lt; input.length (); i ++) {for (int index = 0; index & lt; alph.length; index ++) {if (input.charAt ( I) == alpha [index]) {output = code [index]; Translated [i] = output; }}} For (int j = 1; j & lt; translated; length; j ++) {output = translated [0] .concat (translation [ja]); } Return output; }   

It basically sticks all the code together so that you get your desired result.

Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

c# - NameSpace Manager or XsltContent to parse aspx page -