
This is a question from a past paper, i’m not really sure what to do. i have done this so far, any help is appreciated. My code may be confusing as i try to comment what i need to do then try to do it
public class NumberConvert {
public NumberConvert(int from, int to) {
}
public String convert(String input) {
if(input==null){
return "";
}else{
return "FF";//Not sure what to do here
}
}
public static Integer valueOf(String s, int radix)
throws NumberFormatException {
try {//if radix is out of range (not sure what the range is)
}catch(NumberFormatException e){
System.out.println(e.getMessage());
}
return 0;// to complete
}
public static String toString(int i, int radix) {
return "";//need to complete
}
public static void main (String[] args){
}
}
The
Integerclass provides a version ofparseInt()that allows you to specify the radix, and similarly thetoString()method also allows you to specify the radix.The whole conversion can be done in one line:
The other two methods just use parts of this one line, or you may call your methods as thin wrappers around the Integer methods.
You’ll need to create instance fields to store
fromandtoand set these in your constructor.