So in my main client method, I have :
IPAddress a1 = new IPAddress("153.0012.60.02");
Then in my IPAddress class, I have:
public class IPAddress {
private int[] parts;
public void reset() {
parts = new int[4];
}
above is supposed to instantiates the instance variable array parts to an array of size 4
public static boolean isValidElement(String token) {
String[] validString = token.split("\\.");
if (validString.length != 4)
return false;
for (String str: validString ) {
int i = Integer.parseInt(str);
if ((i < 0) || (i > 255)) {
return false;
}
}
return true;
}
above is supposed to return true if parameter is the String representation of an integer
- between 0 and 255 (including 0 and 255), false otherwise.
- Strings "0", "1", "2" .... "254", "255" are valid.
Padded Strings (such as "00000000153") are also valid
public void setParts(String ip) { //to be completed }
If the ip address from the String passed is valid,
- sets the instance variable parts to store it as 4 integer values.
- For example, if ip = "192.000168.0.0000001", parts should become {192,168,0,1}.
- If the ip address passed is invalid, parts should become {0,0,0,0}
Is
public void reset();
and
public static boolean isValidElement(String token)
correct?
Any help appreciated, thanks