The purpose of this assignment is to reinforce testing concepts, string concepts
ID: 3623815 • Letter: T
Question
The purpose of this assignment is to reinforce testing concepts, string concepts, and text file concepts. Specifically, the assignment is in 2 parts:
Construct a method that will create the hexadecimal representation of a non-negative integer. Use TestAssn5.java as the test program. The method signature should be the following:
public static String createHexString (int n)
// precondition: n is non-negative
// hexadecimal representation of n is returned
Construct a program that will convert a document into pig latin. The program should read the document from a file and create a new file that contains the "translated" document. The file names need to be given by command line arguments.
TestAssn5.java Test Program:
Explanation / Answer
public static String createHexString(int n)
{
String str = Integer.toString(n);
String[] remain = new String[str.length()];
int i = 0,remainder = 0,value = n;
do {
if(value % 16 != 0)
{
remainder = value % 16;
}
remainder = value;
}
if(remainder >= 0 && remainder <= 9)
{
remain[i] = Integer.toString(remainder);
}
else
{
switch(remainder)
{
case 10: remain[i] = "A";
break;
case 11: remain[i] = "B";
break;
case 12: remain[i] = "C";
break;
case 13: remain[i] = "D";
break;
case 14: remain[i] = "E";
break;
case 15: remain[i] = "F";
break;
default: remain[i] = Integer.toString(remainder);
break;
}
}
value /= 16;
i++;
} while(value % 16 != 0);
String values = remain[remain.length - 1];
if(remain.length > 1)
for(int a = remain.length - 2; a >= 0; a--)
{
values += remain[a];
}
}
return values;
}
public static void LatinWord( String token, int count )
{
char letters[] = token.toCharArray();
StringBuffer translation = new StringBuffer();
translation.append(letters,1,letters.length - 1 ) ;
translation.append( Character.toLowerCase( letters[ 0 ] ) );
translation.append( "ay" );
System.out.print( translation.toString() + " " );
if ( count == 0 )
System.out.print( " " );
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.