Due date: See Class Webpage
1. Preparation
Use the project code pj3 to get the files for Project 3.
ParseDuoDecTest.java: This program is used to test the parseDuoDec( ) method Do NOT change this file ToStringTest.java: This program is used to test the toString( ) method Do NOT change this file pj3.java: This program lets you experiment further with Base 12 numbers Do NOT change this file DuoDec.java: The Java class file that implements 2 conversion methods (called: parseDuoDec( ) and toString( )) specified in this assignment You must edit this file for pj3 |
You can work on project 3 in the following ways:
|
Important note: No matter how to decide to work on project 3, you must turn in the DuoDec.java program file for project 3 using the TURNIN procedure given at the end of this handout - click here to see the turnin instructions.
I do not accept email turnins (there are too many students in CS255, I can't handle that many emails !)
2. Introduction: Duodecimal Numbers (See: Wikipedia page)
Digit @ ! ? & % $ = ^ ( ) [ ] Value of the digit = 0 1 2 3 4 5 6 7 8 9 10 11 |
Their number system is positional, meaning that when a number contains multiple digits, then the value of a digit is equal to 12 times the successor digit.
It happens that Marsians use the minus sign '−' to denote negative values
Here are some examples of how the Marsians write their Duodeciaml numbers and the corresponding value:
DuoDec number Value represent (in human decimal system) -------------- ------------------------------------------- @ 0 ! 1 ? 2 ) 9 ] 11 !@ 12 !! 13 != 18 ?! 25 [[ 130 -[[ -130 [[[ 1570 -[[[ -1570 And so on.... |
In this project, you will write 2 conversion methods for DuoDec numbers in Java. The parseDuoDec( ) method will convert a string input in DuoDec numbers into 2s complement (binary) representation (for calculation purpose) and the toString( ) method will convert a 2s complement (binary) representation into a string of DuoDec digits (for output purpose)
These 2 methods will enable a Java program to read in Duodec numbers from the keyboard, then perform computations (in 2s complement) and then print results of computations in the Duodec number system representation.
3. Assignment
|
I have provided the skeleton function code of these methods in the handout file DuoDec.java (you would have made a copy of this file using the above instructions). Take a look in the file DuoDec.java and you will see that the DuoDec class definition looks like this:
public class DuoDec { /* ========================================================== Return the 2's complement binary representation for the DuoDec number given in String s ========================================================== */ public static int parseDuoDec(String s) { ... } /* ========================================================== Return the String of DuoDec digit that represent the value of the 2's complement binary number given in the input parameter 'value' ========================================================== */ public static String toString(int value) { ... } } |
Examples:
parseDuoDec("@") returns the 2s compl representation for value 0 parseDuoDec("!") returns the 2s compl representation for value 1 parseDuoDec("-!") returns the 2s compl representation for value -1 parseDuoDec("?") returns the 2s compl representation for value 2 parseDuoDec("-?") returns the 2s compl representation for value -2 parseDuoDec("!@") returns the 2s compl representation for value 12 parseDuoDec("!!") returns the 2s compl representation for value 13 |
(You should know that int data type uses the 2's complement number code to represent the value !)
Examples:
toString(0) returns the String: "@" toString(1) returns the String: "!" toString(2) returns the String: "?" toString(12) returns the String: "!@" toString(13) returns the String: "!!" toString(-13) returns the String: "-!!" |
Note to students:
|
4. Test programs
|
5. Explore the strange world of base-12 numbers using pj3.java
This program allow you to enter two arbitrary DuoDec numbers and it will add them and print the result out as a DuoDec number. You can see for yourself that the addition works in this strange number system.
javac pj3.java |
java pj3 |
The program will ask you to enter 2 DuoDec numbers and then:
|
Example 1: (my inputs are in red)
Here are the DuoDec digits: DuoDec digit: @ ! ? & % $ = ^ ( ) [ ] Value of digit: 0 1 2 3 4 5 6 7 8 9 10 11 Enter first DuoDec number x = & Debug: x = 00000000000000000000000000000011 Debug: the decimal value = 3 Enter second DuoDec number y = ^ Debug: y = 00000000000000000000000000000111 Debug: the decimal value = 7 Debug: x + y = 00000000000000000000000000001010 Debug: x + y = 10 (in decimal) x + y = [ (in DuoDec) (Check the DuoDec string for correctness !) |
Example 2: (my inputs are in red)
Here are the DuoDec digits: DuoDec digit: @ ! ? & % $ = ^ ( ) [ ] Value of digit: 0 1 2 3 4 5 6 7 8 9 10 11 Enter first DuoDec number x = () Debug: x = 00000000000000000000000001101001 Debug: the decimal value = 105 Enter second DuoDec number y = -] Debug: y = 11111111111111111111111111110101 Debug: the decimal value = -11 Debug: x + y = 00000000000000000000000001011110 Debug: x + y = 94 (in decimal) x + y = ^[ (in DuoDec) (Check the DuoDec string for correctness !) |
6. Extension request
However, you need to use pj3 as homework code to make extension for this homework/project.
/home/cs255001/req-ext pj3 // IF you're in section 1 or: /home/cs255002/req-ext pj3 // IF you're in section 2 |
You request will be successful if you have not exceeded the maximum number of "free" (no-questions-asked) requests allowed
7. How to turnin your project
|
1. Click on File Browser in EGTAPI 2. Select the file that you want to turn in In this case, select the file "DuoDec.java" inside your pj3 folder 3. After selecting the file (in this case: "DuoDec.java"), click Turnin in the File Browser menu The "Egtapi Turn-in" window will pop up 4. In the "Section Number" drop down tab: Select "1" if you are in Section 1 Select "2" if you are in Section 2 5. Enter "Project Code": pj3 6. Click the "Turn in" button 7. You will see the turn in result in the right most panel. Make sure that your see the message: "Program ... has been successfully turned in..." |
Alternately, you can turn in your file using the EGTAPI Terminal:
1. Open the EGTAPI Terminal (click on "Terminal") 2. Enter these command in the lower input area of the Terminal panel: (a) cd ~/cs255/pj3 (go to your pj3 folder) (b) /home/cs255001/turnin DuoDec.java pj3 // If you're in section 1 or (b) /home/cs255002/turnin DuoDec.java pj3 // If you're in section 2 |
If you want to see what you have turned in, then
1. Open the EGTAPI Terminal (click on "Terminal") 2. Enter this command in the lower input area of the Terminal panel: /home/cs255001/turnin // If you're in section 1 or /home/cs255002/turnin // If you're in section 2 |
Students will be graded partially on the basis of their homework assignments. These homework assignments are to be treated as examinations, and are expected to be your individual work. While discussions with other students in the course may be permitted or encouraged by your instructor, you should write your program yourself. Your instructor (and any teaching assistants assigned to the course) will be glad to help you to the extent that he or she feels reasonable. Submissions based on other students solutions in prior offerings of the course specifically violate these guidelines, as do submissions prepared with the help of an outside "tutor". You should take precautions to protect the confidentiality of your work, do not collaborate on questions that you turn in for a grade, do not show your solution to a fellow student, not even after the due date for some students may have receive extension. All submissions should include a comment statement near the top of the program of the form:
THIS CODE IS MY OWN WORK, IT WAS WRITTEN WITHOUT CONSULTING A TUTOR OR CODE WRITTEN BY OTHER STUDENTS - your name |
Cases of apparent plagiarism or collusion will be referred to the Honor Council.