Question: Create a public class BaseConverter with static methods convertToBinary and convertToHexadecimal: public static String convertToBinary( long decimal ) // base 2 public static String convertToHexadecimal(

Create a public class BaseConverter with static methods convertToBinary and convertToHexadecimal:

public static String convertToBinary( long decimal ) // base 2

public static String convertToHexadecimal( long decimal ) // base 16

Each method has a long parameter and returns a String that contains the converted number.

Note that the methods should only convert non-negative numbers (>= 0). If the parameter is negative the method should return an empty String.

You will need to do String concatenation using + when converting to other bases. Hint: place the remainder in front of the current String using +.

NO INPUT OR OUTPUT SHOULD BE DONE IN THESE METHODS.

Create a program BaseConverterTest that prompts the user for a non-negative number and then converts the number to binary and hexadecimal by calling the methods.

Do the following in the BaseConverterTest program: Use a while loop to prompt for a number. Use nextLong to read in the number. Call the methods and then display the converted numbers (Strings) returned by the methods. Call each static method through the class name. For example: BaseConverter.convertToBinary(number) The loop must keep executing until the user enters a negative number. Use the command prompt window (terminal) for ALL input and output.

use java to program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!