1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Please Help Now as soon as you can

  1. Oct 14, 2009 #1
    1. The problem statement, all variables and given/known data

    Hi, this is an Hw need to be submitted in 2 hrs !!
    So, any one helps I would really apppreaitiate it >>

    in this problem I am asking the user to enter some text And I wil convert it into

    Morse Method, I am perfectly fin with that, But the code DOES NOT TYPE out



    2. Relevant equations



    3. The attempt at a solution


    import java.util.Scanner;
    public class CodingTry {

    public static void main (String args [])
    { System.out.println(" Do you want to encode in Morse, or SMS, or exist the program?");

    Scanner scan = new Scanner (System.in);

    String check = scan.next();
    System.out.println(" plese type " + check + " text to be coded >");
    String text = scan.next();

    if (text == "Morse" )


    { String morsetext2 = scan.next();




    // String MorseText = scan.next();


    // String morsetext2 = scan.next();
    while ( morsetext2 != "Done")
    { morsetext2 = scan.next();

    int counter = 0;
    String a = ".- ";
    String b = "-... ";
    String c = "-.-. ";
    String d = "-.. ";
    String e = ". ";
    String f = "..-. ";
    String g = "--. ";
    String h = "....";
    String i = ".. ";
    String j = ".--- '";
    String k = "-.- ";
    String L = ".-.. ";
    String m = "-- ";
    String n = "-. ";
    String o = "--- ";
    String p = ".--- ";
    String q = "--.- ";
    String r = ".-. ";
    String s = "... ";
    String t = "- ";
    String u = "..- ";
    String v = "...- ";
    String w = ".-- ";
    String x = "-..- ";
    String y = "-.-- ";
    String z = "--.. ";
    int morseletter = morsetext2.indexOf(counter);

    if ( morseletter == 'a' || morseletter == 'A')
    System.out.print ( a );

    if ( morseletter == 'b' || morseletter == 'B' )
    System.out.print ( b );

    if ( morseletter == 'c' || morseletter =='C' )
    System.out.print ( c );

    if ( morseletter =='d' || morseletter =='D')
    System.out.print ( d );

    if ( morseletter == 'e' || morseletter == 'E' )
    System.out.print ( e );

    if ( morseletter == 'f' || morseletter == 'F' )
    System.out.print ( f );

    if ( morseletter == 'G' || morseletter == 'g' )
    System.out.print ( g );

    if ( morseletter == 'h' || morseletter == 'H' )
    System.out.print ( h );

    if ( morseletter == 'i' || morseletter == 'I' )
    System.out.print ( i );

    if ( morseletter == 'J' || morseletter == 'j' )
    System.out.print ( j );

    if ( morseletter =='k' || morseletter == 'K' )
    System.out.print ( k );

    if ( morseletter == 'l' || morseletter == 'L' )
    System.out.print ( L );

    if ( morseletter == 'M' || morseletter == 'm' )
    System.out.print ( m );

    if ( morseletter =='n'|| morseletter == 'N' )
    System.out.print ( n );

    if ( morseletter == 'o' || morseletter == 'O' )
    System.out.print ( o );

    if ( morseletter == 'p' || morseletter == 'P' )
    System.out.print ( p );

    if ( morseletter =='Q'|| morseletter == 'q' )
    System.out.print ( q );

    if ( morseletter == 'R' || morseletter == 'r' )
    System.out.print ( r );

    if ( morseletter == 'S' || morseletter == 's' )
    System.out.print ( s );

    if ( morseletter == 't' || morseletter == 'T' )
    System.out.print ( t );

    if ( morseletter == 'u' || morseletter == 'U' )
    System.out.print ( u );

    if ( morseletter == 'v' || morseletter =='V' )
    System.out.print ( v );

    if ( morseletter == 'w' || morseletter == 'W' )
    System.out.print ( w );

    if ( morseletter == 'x' || morseletter == 'X' )
    System.out.print ( x );

    if ( morseletter == 'y' || morseletter == 'y' )
    System.out.print ( y );

    if ( morseletter == 'z' || morseletter == 'Z' )
    System.out.print ( z );
    if (morseletter == ' ')
    System.out.print( " ");

    counter ++;
    }

    }


    if ( check == "exist")
    System.exit(0);



    }

    }
     
  2. jcsd
  3. Oct 16, 2009 #2
    Maybe it's because you seplled exit wrong.
     
  4. Oct 16, 2009 #3
    So far all I've found

    Code (Text):
    int morseletter = morsetext2.indexOf(counter);
    -indexOf takes in a string type.
    -counter, as far as I know, is int type.
    -you put in int type where a string belongs.
    -(btw indexOf gives the index in which counter first shows up in morsetext2 given proper conversions).

    Code (Text):
    if ( morseletter == 'a' || morseletter == 'A')
    System.out.print ( a );

    if ( morseletter == 'b' || morseletter == 'B' )
    System.out.print ( b );
    //and so on...
    -you are checking morseletter (an int type) against a String.

    Code (Text):
    if ( check == "exist")
    I'm guessing you want to type "exit"


    Your code will not work even if these bits are fixed. You will want to pick out letter by letter. I suggest a for loop and String.charAt or String.subString.
     
    Last edited: Oct 16, 2009
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Please Help Now as soon as you can
  1. Help now (Replies: 1)

  2. Can you guys help me e (Replies: 0)

Loading...