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

nment 5 PDF file

  1. 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.
  • If you are rusty with algebra you can review binary (base 2) and hexadecimal (base 16) numbers here: https://www.khanacademy.org/math/algebra-home/alg-intro-to-algebra/algebra-alternate-number-bases/v/number-systems-introduction (Links to an external site.)Links to an external site.
  • More help: http://www.wikihow.com/Convert-from-Decimal-to-Binary (Links to an external site.)Links to an external site. http://www.wikihow.com/Convert-from-Decimal-to-Hexadecimal (Links to an external site.)Links to an external site.

  • 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.

  1. 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.

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!