Question

In Java write a program for a “calculator” that performs any conversion between decimal / binary...

In Java write a program for a “calculator” that performs any conversion between decimal / binary / hexadecimal values that are provided as inputs by the user.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

import java.util.Scanner;
class Main
{
   public static void main (String[] args)
   {
   Scanner sc= new Scanner(System.in);
  
   //Menu
   System.out.println("1. Decimal To Binary ");
   System.out.println("2. Decimal To Hexadecimal ");
   System.out.println("3. Binary To Decimal ");
   System.out.println("4. Binary To Hexadecimal ");
   System.out.println("5. Hexadecimal To Decimal ");
   System.out.println("6. Hexadecimal To Binary ");
   System.out.println("7. Exit ");
  
   //LOOP through the user choice
   while(true)
   {
   System.out.print("Choose the option: ");
   int choice = sc.nextInt();
   if(choice==7)
   break;
   System.out.print("Enter Number: ");
   String num;
   int n;
   switch(choice)
   {
   case 1: num=sc.next();
   n=Integer.parseInt(num,10);
   System.out.println("The Binary Form is : "+Integer.toBinaryString(n));
   break;
   case 2: num=sc.next();
   n=Integer.parseInt(num,10);
   System.out.println("The Hexadecimal Form is : "+Integer.toHexString(n));
   break;
  
   case 3: num=sc.next();
   n=Integer.parseInt(num,2);
   System.out.println("The Decimal Form is : "+n);
   break;
  
   case 4: num=sc.next();
   n=Integer.parseInt(num,2);
   System.out.println("The Hexadecimal Form is : "+Integer.toHexString(n));
   break;
  
   case 5: num=sc.next();
   n=Integer.parseInt(num,16);
   System.out.println("The Decimal Form is : "+n);
   break;
  
   case 6: num=sc.next();
   n=Integer.parseInt(num,16);
   System.out.println("The Binary Form is : "+Integer.toBinaryString(n));
   break;
   default: break;
   }
   }
   }
}

====================

SCREENSHOT:

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
In Java write a program for a “calculator” that performs any conversion between decimal / binary...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need this in java please Write a program that converts between decimal, hex, and binary numbers,...

    Need this in java please Write a program that converts between decimal, hex, and binary numbers, as shown in Figure. When you enter a decimal value in the decimalvalue text field and press the Enter key, its corresponding hex and binary numbers are displayed in the other two text fields. Likewise, you can enter values in the other fields and convert them accordingly. (c) The program converts between decimal, hex, and binary numbers.

  • need help with writing a program that converts i.e. binary to decimal or decimal to hexadecimal...

    need help with writing a program that converts i.e. binary to decimal or decimal to hexadecimal but cannot use the conversion tool built-in Java and please use the switch and write comments to understand.

  • In java Write a program that asks the user to choose a selection (Enter 1 to...

    In java Write a program that asks the user to choose a selection (Enter 1 to convert from binary to decimal, 2 to convert from decimal to binary, 3 to convert binary to hexadecimal, 4 to convert hexadecimal to binary, 5 to convert decimal to hexadecimal, 6 to convert hexadecimal to decimal. Pls do it by creating classes and objects with get and set method.

  • Java: can also use “if else” statements Write a program that can convert an integer between...

    Java: can also use “if else” statements Write a program that can convert an integer between 0 and 15 into hex number (including 0 and 15). The user enters an integer from the console and the program displays the corresponding hex number. If the user enters an integer out of range, the program displays a warning message about the invalid input. Table. Conversion between Decimal and Hexadecimal Decimal Hexadecimal 0 0 1 1 2 2 3 3 4 4 5...

  • Write a java program to convert a decimal number to binary number. Provide the Big O...

    Write a java program to convert a decimal number to binary number. Provide the Big O analysis

  • In this assignment, you will write a Java program(s) to print the binary representation of a...

    In this assignment, you will write a Java program(s) to print the binary representation of a positive integer inserted from command line.  You must finish your assignment in 2 different ways: Using a recursive method Using an iterative method     Your main method must be: public static void main(String[] args) {      int input;         input = Integer.parseInt(args[0]);     print_recursion(input);     print_binary(input); }     You must implement a class and test your program by different input values, including 0. Comment your program properly Example of test...

  • Write a JAVA application allowing user to input a Decimal number and output a Binary number.

    Write a JAVA application allowing user to input a Decimal number and output a Binary number.

  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for list of operations that can be calculated and get the input from user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations must be...

  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for the list of operations that can be calculated and get the input from the user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations...

  • Binary and hexadecimal numbers and ASCII code: Write the binary and hexadecimal equivalent of the decimal...

    Binary and hexadecimal numbers and ASCII code: Write the binary and hexadecimal equivalent of the decimal numbers below: Decimal Binary Hexadecimal 6 __________                __________ __________ 15   __________                __________ __________ 39   __________                __________ __________ 170   __________                __________ __________ Write the binary and decimal equivalent of the following hexadecimal numbers:    Hexadecimal                Binary             Decimal 08                    __________                        __________ 0B                   __________                        __________ 15                    __________                        __________ F3                    __________                        __________ Write the two digit hexadecimal sequence of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT