My first successful (ish) program!

:smiley: hello peoples, i have made my first program that is over 50 lines of code and i would like to share it! WARNING: you must create and configure morsecode.txt to run the program correctly :-\

[code]/**

  • This programs translates into morse code.
    /
    import java.util.ArrayList;
    import java.util.Scanner;
    import java.awt.
    ;
    import java.io.File;
    import java.io.PrintWriter;
    import java.io.IOException;
    public class MorseCode {

    public static void main(String[] args) throws IOException
    {
    Scanner in2 = new Scanner(new File(“morsecode.txt”));
    ArrayList morse = new ArrayList();

     while(in2.hasNext()) {
       morse.add(in2.next());
     }
      in2.close();  
    
     
     String [] letters = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}; 
     
     System.out.print("Type a sentence with no punctuation... ");
      Scanner in = new Scanner(System.in);   
     
             String user = in.next();
             ArrayList<String> userLetters = new ArrayList<String>();
             
       for (int i = 0; i < user.length(); i++)
         { 
               userLetters.add("" + user.charAt(i));
                   }
                   System.out.println();
                   System.out.println();
                   
         for (int i = 0; i <user.length(); i++)
         {
          if (user.charAt(i) == 'a')
          {
           System.out.print(morse.get(0) + ", ");
          }
          if (user.charAt(i) == 'b')
          {
           System.out.print(morse.get(1) + ", ");
          }
                       if (user.charAt(i) == 'c')
          {
           System.out.print(morse.get(2) + ", ");
          }
                       if (user.charAt(i) == 'd')
          {
           System.out.print(morse.get(3) + ", ");
          }
                       if (user.charAt(i) == 'e')
          {
           System.out.print(morse.get(4) + ", ");
          }
                       if (user.charAt(i) == 'f')
          {
           System.out.print(morse.get(5) + ", ");
          }
                       if (user.charAt(i) == 'g')
          {
           System.out.print(morse.get(6) + ", ");
          }
                       if (user.charAt(i) == 'h')
          {
           System.out.print(morse.get(7) + ", ");
          }
                       if (user.charAt(i) == 'i')
          {
           System.out.print(morse.get(8) + ", ");
          }
                       if (user.charAt(i) == 'j')
          {
           System.out.print(morse.get(9) + ", ");
          }
                       if (user.charAt(i) == 'k')
          {
           System.out.print(morse.get(10) + ", ");
          }
                       if (user.charAt(i) == 'l')
          {
           System.out.print(morse.get(11) + ", ");
          }
                       if (user.charAt(i) == 'm')
          {
           System.out.print(morse.get(12) + ", ");
          }
                       if (user.charAt(i) == 'n')
          {
           System.out.print(morse.get(13) + ", ");
          }
                       if (user.charAt(i) == 'o')
          {
           System.out.print(morse.get(14) + ", ");
          }
                       if (user.charAt(i) == 'p')
          {
           System.out.print(morse.get(15) + ", ");
          }
                       if (user.charAt(i) == 'q')
          {
           System.out.print(morse.get(16) + ", ");
          }
                       if (user.charAt(i) == 'r')
          {
           System.out.print(morse.get(17) + ", ");
          }
          if (user.charAt(i) == 's')
          {
           System.out.print(morse.get(18) + ", ");
          }
          if (user.charAt(i) == 't')
          {
           System.out.print(morse.get(19) + ", ");
          }
          if (user.charAt(i) == 'u')
          {
           System.out.print(morse.get(20) + ", ");
          }
          if (user.charAt(i) == 'v')
          {
           System.out.print(morse.get(21) + ", ");
          }
          if (user.charAt(i) == 'w')
          {
           System.out.print(morse.get(22) + ", ");
          }
          if (user.charAt(i) == 'x')
          {
           System.out.print(morse.get(23) + ", ");
          }
          if (user.charAt(i) == 'y')
          {
           System.out.print(morse.get(24) + ", ");
          }
          if (user.charAt(i) == 'z')
          {
           System.out.print(morse.get(25) + ", ");
          }
                       if (user.charAt(i) == '1')
          {
           System.out.print(morse.get(26) + ", ");
          }
                       if (user.charAt(i) == '2')
          {
           System.out.print(morse.get(27) + ", ");
          }
                       if (user.charAt(i) == '3')
          {
           System.out.print(morse.get(28) + ", ");
          }
                       if (user.charAt(i) == '4')
          {
           System.out.print(morse.get(29) + ", ");
          }
                       if (user.charAt(i) == '5')
          {
           System.out.print(morse.get(30) + ", ");
          }
                       if (user.charAt(i) == '6')
          {
           System.out.print(morse.get(31) + ", ");
          }
                       if (user.charAt(i) == '7')
          {
           System.out.print(morse.get(32) + ", ");
          }
                       if (user.charAt(i) == '8')
          {
           System.out.print(morse.get(33) + ", ");
          }
                       if (user.charAt(i) == '9')
          {
           System.out.print(morse.get(34) + ", ");
          }
                       if (user.charAt(i) == '0')
          {
           System.out.print(morse.get(35) + ", ");
          }
              if (user.charAt(i) == ' ')
              {
               System.out.print("");
              }
         }          
    
    
    
    
     
     
      in.close(); 
    

    }
    }[/code]

and here is what i WANTED to make :’( http://www.lagmonster.org/utilities/morse/

Also, i have no clue how to config the txt file so don’t ask :-X
Here is what i have to say for myself: -.-- . … / - … .- - / .-- .- … / …- . .-. -.-- / -… …- – -… / — …-. / – . / … — / .-- … .- -

.-- . .-… .-… --…-- / … — / .-- … .- - / -.-- — …- / … .- -.-- …–… / … / … .- -.-- / - … .- - .-.-.- .-.-.- .-.-.- / .-- . .-… .-… --…-- / … -… -.- / .-. . .- .-… .-… -.-- --…-- / -… …- - / -.-- .- -.–

Translation WELL, SO WHAT YOU SAY? I SAY THAT... WELL, IDK REALLY, BUT YAYWELL, SO WHAT YOU SAY? I SAY THAT... WELL, IDK REALLY, BUT YAY

LOL I did it twice? xD

Nice!

You may want to replace all those stacked If conditional statements with either Case or Elseif. Probably just a bit of my OCD shining through :P. It also makes sure those other If statements definitely do not execute since you only want one to.

— …- / … .- … / - … .- .-. / – -.-- / -. .- – . / … … / .— --- … -. .- - … .- -. / .- -. -… / … /
.-… — …- . / .–. .-. — .— . -.-. - / -.-. … - -.-- / -… …- … .-… -… -.-.–

(Translation)

i played around with elseif’s for a bit, but i decided to take the “easy way” out lol

Stop putting everything in morse codez!

-. . …- . .-. / … / .-- … .-… .-… / -. . …- . .-. / … - — .–.

Also to any new people on the server:
… … / … / .- – / -… .-. — -… …- .-. / … .- …- . / .- / -. … -.-. . / -… .- -.-- / — -. / .–. / -.-. / -… / … / - … … -. -.- / - … .- - / … …-. / -.-- — …- / --. .-. … . …-. / … / .-- … .-… .-… / -… .- -. --… / -.-- — …- / … — / … .- …- . / …-. …- -. / .-… … … - . -. … -. --. / - — / .-. .- -. -… — – / -… . . .–. … / - … . -. / --. .-. . … …-. … -. --. / .- -. -… / -… . … -. --. / -… .- -. -. . -…

I would also like to say sometimes taking the easy way out becomes a chance for learning from mistakes, because there is a fair chance it may be buggy or slow, like on of my apps it takes nearly a second (a whole second) to start, why because it is initiating ALL of the phones sensors immediately and that causes the viewable app to seem to have a delay. I am rewriting it so it launches the view first with no data filing in then the sensors coming on or a start stop. So when you are just beginning mistakes are good just like in life, just don’t go crazy and start eating CD’s (hard to explain lol)

Doesn’t that cause Force Closes? :S

use code and /code :stuck_out_tongue: with the [] ofc

No it does not because it is just starting and initiating all of the sensors then it launches, kinda hard to explain, because im not exactly an expert yet, but it doesn’t force close, I don’t remember exactly the amount of time that would cause a force close but its definitely under.