Assignment #6

Your max grade for this assignment is 20, and you get points from the following parts: 
  • 10 pts for requirements [#1 on the assignment sheet]
  • 10 pts for coding and documentation [#3 on the assignment sheet]
The Grading Base is going to be like "20 [10 10]" for a max grade on the Grades page for this assignment. 
  
In addition to these, I would like to give you some other ways to do conversions. This type of conversion is called type casting. 

For example, 
 
int digitvalue = 48; 
char charvalue; 
charvalue = (char)digitvalue;    // force the compiler for conversion 
System.out.println(charvalue);   // prints '0' instead of number 48. 

// Similarly 
charvalue = '9'; 
digitvalue = (int)charvalue;     //  
System.out.println(digitvalue);  // prints integer 57 instead of '9'. 

Notice that type casting does not convert an integer 48 to a string of 4 and 8, "48". It rather converts it to its ASCII code, char '0'. 

For this assignment, another way would be the following: 

int ASCII_value, integer_value; 
ASCIIvalue = System.in.read(); 

integer_value = ASCII_value - 48;
System.out.println("Number you typed in:" + integer_value); 

This way you get the same thing you do by doing the following: 

if(ASCII_value == 48)  
  integer_value = 0; 
else if(ASCII_value == 49) 
  integer_value = 1; 
... 
 
 

Ozgur Balsoy 
balsoy@npac.syr.edu 

Northeast Parallel Architectures Center