Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA ( USE OF BUILT-IN BASE CONVERSION FUNCTIONS ARE NOT ALLOWED) Write a program that performs the following tasks: Display a friendly greeting to the

JAVA (USE OF BUILT-IN BASE CONVERSION FUNCTIONS ARE NOT ALLOWED)

Write a program that performs the following tasks:

Display a friendly greeting to the user Prompt the user for the value to convert (a String) Accept that String Prompt the user for the value of the initial base (an integer) Accept that integer Prompt the user for the desired base of the output (an integer) Accept that integer If the String is not a legal expression of a number in the initial base, display an error message and exit the program. Convert the value represented by the String in the initial base to the desired base. Display the result. The program should also accept all three parameters from the command line if provided. Command-line parameters are accepted in the same order as the input prompts. For example:

C:> java BaseConversions ABCDE 25 8

will convert the input string ABCDE from base 25 into base 8 and display the result. We will accept any base from 2 to 36. Base 36 uses the integers 0-9 and the twenty-six letters A-Z / a-z.

The validator and the actual conversion routine should be contained in methods:

public static boolean isValidInteger(String theValue, int theBase){ // contract: returns true if theValue is a valid expression in theBase; // false otherwise.

public static String convertInteger(String theValue, int initialBase, int finalBase){ // contract: converts theValue from initialBase to finalBase and returns the // result as a String. // precondition: theValue must be a valid expression in initialBase.

You will need to use the BigInteger class, which allows arbitrary-length integers. You may not use the built-in base conversion functions in Integer or BigInteger. The only operations allowed are add, subtract, multiply, divide, and mod. Your conversion algorithm is:

Check the validity of the input String Convert the input String from the initial base into a BigInteger (in base 10). Convert that base-10 BigInteger into a String representation of that value in the desired target bas

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

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

4. Explain the strengths and weaknesses of each approach.

Answered: 1 week ago