Create a menudriven program that converts a character betwee

Create a menu-driven program that converts a character between its Unicode value and vice versa. The menu should have the following options: Convert Character to Unicode Convert Unicode to Character Exit Program Allow the user to choose a menu choice and enter a character or Unicode value and convert the input respectively. The menu choices must be valid. The menu choices should use characters for the choices, instead of numbers. The Unicode value entered must not be negative.

Solution

MenuTest.java

import java.util.Scanner;


public class MenuTest {

  
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       while(true){
       System.out.println(\"a. Convert Character to Unicode\ b. Convert to Unicode to Character\ c. Exit\ \");
       System.out.println(\"Enter your choice: \");
       char ch = scan.next().charAt(0);
       switch(ch){
       case \'a\':System.out.println(\"Enter the character: \");char c = scan.next().charAt(0);
               System.out.println(\"Unicode is \"+(int)c);break;
       case \'b\':System.out.println(\"Enter the Unicode: \");int i = scan.nextInt();
       System.out.println(\"Character is \"+(char)i);break;
       case \'c\': System.exit(0);
       default: System.out.println(\"Invalid choice.\");
       }
       }
   }

}

Output:

a. Convert Character to Unicode
b. Convert to Unicode to Character
c. Exit

Enter your choice:
a
Enter the character:
b
Unicode is 98
a. Convert Character to Unicode
b. Convert to Unicode to Character
c. Exit

Enter your choice:
b
Enter the Unicode:
98
Character is b
a. Convert Character to Unicode
b. Convert to Unicode to Character
c. Exit

Enter your choice:
c

 Create a menu-driven program that converts a character between its Unicode value and vice versa. The menu should have the following options: Convert Character

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site