Answered step by step
Verified Expert Solution
Link Copied!

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

  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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

What are HR ethics?

Answered: 1 week ago