Overview
The purpose of this lab is to provide students an opportunity to work closely with algorithms for changing number bases.Preparation
- Read Section 1.4 in the textbook.
- Review supplemental videos 2 - 5.
- Write and solve 10 base conversion problems by hand (to make sure you understand the algorithm).
Activity
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 provided starter code. Do not change the class name or method signatures.
- You are not allowed to use
Integer.toString(int i, int radix)
,Integer.parseInt(String s, int radix)
or any other library code that completes a significant portion of the assignment. (You may, use the defaultInteger.toString()
for converting a base-10int
to the base-10String
representation of that integer.)
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.
Testing:
I have provided a few sample JUnit tests in BaseConverterStudentTest.java
. Add more of your own tests.
I have also written a larger suite of tests that I will use when grading your lab. These tests will run automatically when you push your code. If these tests fail, then you have two problems (1) a bug in your code, and (2) a missing test case (since your test suite didn't find the bug). If your code fails my tests, (1) find the missing test case, (2) fix the corresponding bug, then (3) push the fix. I won't grade your lab until it passes all my tests.
Submission and Grading:
Once your code passes my tests, push the code with the string [Grade Me]
in the commit message.
Updated Saturday, 8 August 2020, 12:50 PM