Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
- 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.
- 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started