I'm doing a program for a course in school (intro software development) and I'm looking for some general feedback as well as any ways this bit of code could be cleaner. I'm also wondering if it is bad practice to use %=
as I've talked with some people and have been told it's not good to use any operators like that, other than +=
and -=
to keep code readable, although maybe that is specific to this particular course.
private int heightInInches;
private final int VALUE_OF_ONE_FOOT = 12;
public String getHeightInFeetAndInches() {
String includeInches = "";
int leftOver = (heightInInches %= VALUE_OF_ONE_FOOT);
int newHeight = (heightInInches % VALUE_OF_ONE_FOOT);
if(leftOver < 0) {
includeInches = "";
}else if(leftOver <= 1) {
includeInches = "Inch";
}else {
includeInches = "Inches";
}
return newHeight + " feet " + leftOver + " " + includeInches;
}
This method should return a person's height in the form of (for example): 6 feet 1 inch(es) (if the inch amount exceeds 1).