Guest User

Untitled

a guest
Jan 19th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. public class MorseCode
  4. {
  5. public static String[] getChart() throws IOException
  6. {
  7. int i = 0;
  8. String[] chart = new String[72];
  9. File fileName = new File("morsecode.txt");
  10. Scanner inFile = new Scanner(fileName);
  11.  
  12. while(inFile.hasNext())
  13. {
  14. chart[i] = inFile.next();
  15. i++;
  16. }
  17. inFile.close();
  18. return chart;
  19. }
  20.  
  21. public static String toCode(String m, String[] chart)
  22. {
  23. String message = m;
  24. message = message.toLowerCase();
  25. message = message.replace(" ", "\n");
  26. for(int i = 0; i<72; i+=2)
  27. {
  28. message = message.replace(chart[i], (chart[i+1] +" "));
  29. }
  30. return message;
  31. }
  32. }
Add Comment
Please, Sign In to add comment