Due date: See Class Webpage
1. "Nano" Numbers
Digit # ! % @ ( ) [ ] $ Value of the digit = 0 1 2 3 4 5 6 7 8 |
Their number system is positional, meaning that when a number contains multiple digits, then the value of a digit is equal to 9 times the successor digit.
It happens that Neptunians use the minus sign '−' to denote negative values
Examples:
Nano number Value represent (in human decimal system) -------------- ------------------------------------------- ! 1 !# 9 !! 10 !% 11 !@ 12 !## 81 !#! 82 !#% 83 % 2 %# 18 %! 19 %% 20 (@ 39 (( 40 [[ 60 -[[ -60 And so on.... |
2. Preparation
mkdir ~/cs255/pj3 cp /home/cs255001/Handouts/pj3/* ~/cs255/pj3 |
If you do work from home on your PC:
|
I do not accept email turnins !
pj3.java: The main program that is used to test the 2 methods that you need to write for this assignment Do NOT change this file Nano.java: The Java class file that implements the 2 conversion methods specified in this assignment |
3. Assignment
|
which allows you to convert between:
|
The Nano class definition looks like this:
public class Nano { /* ========================================================== Return the 2's complement binary representation for the Nano number given in String s ========================================================== */ public static int parseNano(String s) { ... } /* ========================================================== Return the String of Nano 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:
parseNano("#") returns the 2s compl representation for value 0 parseNano("!") returns the 2s compl representation for value 1 parseNano("-!") returns the 2s compl representation for value -1 parseNano("%") returns the 2s compl representation for value 2 parseNano("-%") returns the 2s compl representation for value -2 parseNano("!#") returns the 2s compl representation for value 9 parseNano("!!") returns the 2s compl representation for value 10 |
(Recall that int uses the 2's complement number encoding scheme)
Examples:
toString(0) returns the String: "#" toString(1) returns the String: "!" toString(2) returns the String: "%" toString(9) returns the String: "!#" toString(10) returns the String: "!!" |
Note to students:
|
4. Test programs
|
5. Compile and run pj3.java
javac pj3.java |
java pj3 |
The program will ask you to enter 2 Nano numbers and then:
|
Example 1: (my inputs are in red)
For your convenience, here are the Nano digits: Nano digit: # ! % @ ( ) [ ] $ Value of digit: 0 1 2 3 4 5 6 7 8 Enter first Nano number x = @ The value of this Nano number in decimal system = 3 Enter second Nano number y = ) The value of this Nano number in decimal system = 5 The sum in decimal number system = 8 The sum in Nano number system = $ |
Example 2: (my inputs are in red)
For your convenience, here are the Nano digits: Nano digit: # ! % @ ( ) [ ] $ Value of digit: 0 1 2 3 4 5 6 7 8 Enter first Nano number x = !%@ The value of this Nano number in decimal system = 102 Enter second Nano number y = )() The value of this Nano number in decimal system = 446 The sum in decimal number system = 548 The sum in Nano number system = [[$ |
Example 3: your program must handle negative values !!!
For your convenience, here are the Nano digits: Nano digit: # ! % @ ( ) [ ] $ Value of digit: 0 1 2 3 4 5 6 7 8 Enter first Nano number x = !%(]($ The value of this Nano number in decimal system = 75698 Enter second Nano number y = -$$@)#( (Negative value !!!!) The value of this Nano number in decimal system = -527476 The sum in decimal number system = -451778 The sum in Nano number system = -])][() |
6. Turn in ********************************** You must do this !!!
cd ~/cs255/pj3 /home/cs255001/turnin Nano.java pj3 // IF you're in section 1 or: /home/cs255002/turnin Nano.java pj3 // IF you're in section 2 |
/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
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.