Anda di halaman 1dari 2

/* Assignment 9

* Aim: To accept a name from user and use a menu driven program to reverse the words of
* name,code it or replace each vowel with #
*/
import java.io.*;
class Assignment_9
{
public static void main() throws IOException
{
int choice,i;
char c = '\0';
String wd = "", rev = "" ;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the name ");
String s = br.readLine()+" " ; s = s.toUpperCase();
System.out.println("Menu:");
System.out.println(" 1. Name of the person in reverse order of words ");
System.out.println(" 2. Generate a code for the name ");
System.out.println(" 3. Name of the person with each vowel replaced by #");
System.out.println(" 4. Exit ");
System.out.println();
do{ System.out.println("Enter choice");
choice =Integer.parseInt(br.readLine());
switch(choice)
{
case 1:
for ( i = 0 ; i < s.length() ; i++ )//displaying name in reverse order of words
{
c = s.charAt(i);
if ( c != ' ' )
wd += c ;
else
{ rev = wd + " " + rev ; wd = "";}
}//end of for loop
System.out.println(rev);
break;
case 2:for ( i = 0 ; i < s.length(); i++)//generating the code
{
c = s.charAt(i);
if(c !=' '){
if ( c >= 'A' && c<= 'Z')
{ c += 3;
if ( c > 'Z')
c -= 26;
if ( c < 'A')
c += 26;
}//end of inner if
}//end of outer if
System.out.print(c);
} //end of for loop
System.out.println();break;
case 3: for ( i = 0; i < s.length(); i++)//replacing vowels with #
{
c = s.charAt(i);
if ( c != ' ' )
{ if ( c == 'A' || c == 'E' || c=='I' || c=='O' || c=='U')
c = '#';
}//end of outer if
System.out.print(c);
} //end of for loop
System.out.println();break;
case 4: System.out.println("Exiting") ;break;
default: System.out.println("Wrong Choice");
}//end of switch
}while(choice!=4);//end of do while loop
}//end of main
}//end of class

Anda mungkin juga menyukai