You will, using object-oriented principles, design a class from a problem description, document that design with a UML diagram, and implement it as a working Java program. Solving it will help you find the answer to life, the universe, and everything! (It's BQ, of course.)
Specifically, you are tasked with implementing a class that will convert numbers to and from base-26 (Hexaicosadecimal).
The Problem You'll all be familiar with our normal base-10 (decimal) number system:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
You should also be familiar with base-2 (binary), in which there are only two values:
0,1
There are several other number systems that are important to computer scientists, including base-8 (octal):
0, 1, 2, 3, 4, 5, 6, 7
And base-16 (hexadecimal):
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f
I've got a typewriter on which, unfortunately, all the number keys are broken. But I still want to do maths! Luckily, all the letter keys work, so I've got a handy set of 26 symbols laying around. So I'm in luck: All I have to do is write out my numbers in base-26 (hexaicosadecimal)!
Now, I've gotten pretty good at thinking in hexaicosadecimal, but I keep getting bad grades in maths because nobody else can understand it! Your job is to help me out by writing a Java program that can convert numbers from base-10 to base-26 and vice versa.
Part I: Create your "test harness"
We'll get to maths in a minute. First, you should create the main() function that you can use to ram. Create a new class called HexiacosadecimalNumber. Within that class, create your main() function. The main function should behave as follows:
First, it should ask the user to indicate what mode it should be in. If the user types 'h' or 'H', the program should ask them to input a hexaicosadecimal number (that is, a String). The program should then read that number into a variable, and print it back to the command line (for now). If the user types 'd' or 'D', the program should ask them to input a decimal number (that is, a double). The program should then read that number into a variable, and print it back to the command line (for now). If the user types 'q' or 'Q', the program should exit. If the user types anything else, the program should display the message “INVALID INPUT”, and then prompt the user again. The program should then ask the user again what mode it should be in, and repeat the process until the user types 'q' or 'Q' at the prompt.
To accomplish this, you will need to use a Scanner object in combination with a loop containing an if-else block.
Students succeed in their courses by connecting and communicating with an expert until they receive help on their questions
Consult our trusted tutors.