Created
August 7, 2013 08:31
-
-
Save andy-polhill/6172271 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class StringUtils { | |
public String cropAndConcat(String toCrop, int index, String toConcat) { | |
return toCrop.substring(index) + toConcat; | |
} | |
public String removeFromAndConcatToEnd(String containing, String concat) { | |
if (containing.contains(concat)) { | |
return containing; | |
} | |
return concat + containing; | |
} | |
public int getDriverAge(int months) { | |
return months / 12; | |
} | |
} | |
public class Car extends StringUtils { | |
private String model; | |
private String make; | |
private String driverName; | |
private int driverAge; | |
Car() { | |
super(); | |
} | |
public String getModel() { | |
return removeFromAndConcatToEnd(model, "mark 2"); | |
} | |
public String getMake() { | |
return make; | |
} | |
public String getDriverName() { | |
return driverName; | |
} | |
public int getDriverAge() { | |
return getDriverAge(); | |
} | |
@Override | |
public boolean equals(Object that) { | |
if (that == null) { | |
throw new NullPointerException("that cannot be null"); | |
} | |
if (!(that instanceof String)) { | |
return false; | |
} | |
String other = (String) that; | |
if (other.equals(model)) { | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment