- #1
remaan
- 132
- 0
Homework Statement
Hi, this is an Hw need to be submitted in 2 hrs !
So, anyone 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
Homework Equations
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);
}
}