Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop menu-driven Java program that will solve the following problem. The prog

ID: 3543977 • Letter: D

Question

Develop menu-driven Java program that will solve the following problem. The program uses recursive method to accomplish the tasks specified below. The menu is shown below.

1) Convert Decimal to binary

2) Convert Binary to Decimal

3) Convert Decimal to Hexadecimal

4) Convert Hexadecimal to decimal

5) Convert Decimal OctalDecimal

6) Convert Octal to decimal

7) Clear Screen

8) Help

9) Exit

1. Comment on your program

2. Use meaningful prompts

3. Provide a brief description of the problem being solved.

4. Illegal menu selection to be handled properly without terminating the program

5 Illegal input numbers for any of the above option must be handled properly without terminating the program.

Explanation / Answer

Perfect code and output as expected :


import java.util.Scanner;

import java.lang.*;

class Decimal_Binary {

Scanner scan;

int num;

void getVal() {

System.out.println("Decimal to Binary");

scan = new Scanner(System.in);

System.out.println(" Enter the number :");

num = Integer.parseInt(scan.nextLine());

}

void convert() {

String binary = Integer.toBinaryString(num);

System.out.println("Binary Value is : " + binary);

}

}

class Binary_Decimal {

Scanner scan;

int num;

void getVal() {

System.out.println("Binary to Decimal");

scan = new Scanner(System.in);

System.out.println(" Enter the number :");

num = Integer.parseInt(scan.nextLine(), 2);

}

void convert() {

String decimal = Integer.toString(num);

System.out.println("Decimal Value is : " + decimal);

}

}

class Decimal_Hexa {

Scanner scan;

int num;

void getVal() {

System.out.println("Decimal to HexaDecimal");

scan = new Scanner(System.in);

System.out.println(" Enter the number :");

num = Integer.parseInt(scan.nextLine());

}

void convert() {

String hexa = Integer.toHexString(num);

System.out.println("HexaDecimal Value is : " + hexa);

}

}


class Hexa_Decimal {

Scanner scan;

int num;

void getVal() {

System.out.println("HexaDecimal to Decimal");

scan = new Scanner(System.in);

System.out.println(" Enter the number :");

num = Integer.parseInt(scan.nextLine(), 16);

}

void convert() {

String decimal = Integer.toString(num);

System.out.println("Decimal Value is : " + decimal);

}

}

class Decimal_Octal {

Scanner scan;

int num;

void getVal() {

System.out.println("Decimal to Octal");

scan = new Scanner(System.in);

System.out.println(" Enter the number :");

num = Integer.parseInt(scan.nextLine());

}

void convert() {

String octal = Integer.toOctalString(num);

System.out.println("Octal Value is : " + octal);

}

}

class Octal_Decimal {

Scanner scan;

int num;

void getVal() {

System.out.println("Octal to Decimal");

scan = new Scanner(System.in);

System.out.println(" Enter the number :");

num = Integer.parseInt(scan.nextLine(), 8);

}

void convert() {

String decimal = Integer.toString(num);

System.out.println("Decimal Value is : " + decimal);

}

}

class conv {

public static void main(String args[])

{

do{

System.out.println("1) Convert Decimal to binary 2) Convert Binary to Decimal 3) Convert Decimal to Hexadecimal 4) Convert Hexadecimal to decimal 5) Convert Decimal OctalDecimal 6) Convert Octal to decimal 7) Clear Screen 8) Help 9) Exit ");

System.out.println("Choice : ");

Scanner sc=new Scanner(System.in);

int choice=sc.nextInt();

switch(choice)

{

case 1: Decimal_Binary obj = new Decimal_Binary();

obj.getVal();

obj.convert();

break;

case 2: Binary_Decimal obj1 = new Binary_Decimal();

obj1.getVal();

obj1.convert();

break;

case 3: Decimal_Hexa obj2 = new Decimal_Hexa();

obj2.getVal();

obj2.convert();

break;

case 4: Hexa_Decimal obj3 = new Hexa_Decimal();

obj3.getVal();

obj3.convert();

break;

case 5: Decimal_Octal obj4 = new Decimal_Octal();

obj4.getVal();

obj4.convert();

break;

case 6: Octal_Decimal obj5 = new Octal_Decimal();

obj5.getVal();

obj5.convert();

break;

case 7: //System("clear"); //in linux

break;

case 8: System.out.println("Follow the index and enter appropriate option ");

break;

case 9: System.exit(0);

break;

default: System.out.println("Sorry ! Try again :)");

}

}

while(true);


}

}