Overview
The purpose of this lab is to provide students an opportunity to work closely with algorithms for changing number bases.Activities
- Read Section 1.4 in the textbook.
- Review supplemental videos 2 - 5.
- Write and solve 10 base conversion problems.
- Write a number conversion program
Practice Problems
Write and solve 10 (or more) different number conversion problems.
- Five of the problems should have you convert from base 10 to another base.
- The remaining five should have you convert to base 10.
- Each base may be used at most once.
- You may use a web site like
www.geogebra.org/m/ZEdZjfxm
to check your answers. (Show enough work to convince me that you did more than simply copy answers from the web page.)
Practice Problems
Use the provided Java starter code to write a conversion method that will take in a string representing a number in a specified base and convert it to another base. Do not worry so much about catching error conditions; for this lab it is more important to learn the number conversion process and implement the algorithm.
Restrictions:
- Use the names provided in the starter code. Do not change the class name or method signatures.
- You are not allowed to use
Integer.parseInt(String, int)
any other library code that completes a significant portion of the assignment.
The provided starter code contains a class in the default package named NumberBase
with the method
public static String convert(String input, int base_in, int base_out)
. This method takes the
number represented by the input
and converts it from base_in
to base_out
. For
example, NumberBase.convert('ff',16,10)
returns "255
".
Assumptions:
input
will be a string representing a number in the range of 0 to 231-1base_in
andbase_out
fall between 2 and 36 (inclusive)- For bases over 10, use lowercase letters (Tests will fail and credit not given for uppercase!)
- The return should be a string containing the answer with no leading zeroes.
- Do not worry about illegal input.
Files:
- The start code:
NumberBase_Stub.java
. (Please change the name of this file to something withoutStub
in it.) - Sample test class:
NumberBaseTest_Sample.java
. You can use this as a starting point for tests; but, you must add tests of your own. (Please change the name of this file and class to something withoutSample
in it.) - Necessary
.jar
files:
Testing:
I will use a JUnit test similar to NumberBaseTest_Sample.java
to test your
code. Be sure to thoroughly test your code using JUnit or other automated test framework. (The sample JUnit test is
designed to ensure you named your classes and methods properly. It is up to you to extend it to thoroughly test your
code.)
The test will not run unless you follow the directions above. If a class or method name is misspelled, the method signature (arguments, return value) changed, or visibility of the class and method are changed, the tests will not run and I will deduct points.
You may write, compile, and run your code using any IDE you prefer. However, there is a good chance I won't be able to help you if you have configuration problems. I will run and test your code from the EOS command line using commands similar to these:
javac NumberBase.java
javac -cp junit-4.12.jar:hamcrest-core-1.3.jar NumberBaseTest.java
java -cp hamcrest-core-1.3.jar:junit-4.12.jar:. org.junit.runner.JUnitCore NumberBaseTest
(I'm a command line nerd; so, I'm happy to explain how/why these commands work.)
Submission and Grading:
- You must demonstrate your code to me before you submit it.
- If you finish during the lab session, please raise your hand and call me over to check the functionality of your program.
- If you do not finish during the lab session, you must stop by my office and demonstrate your code before the due date.
- Once I have approved your code, please submit your code and tests on Blackboard (only one submission per group). Make sure all Java files contain both group members' names in a comment. Note: Code should also be well formatted and legible so that I can evaluate it.