I'm working on a code where it converts shoe sizes and distance.
I require help making it "nicer" because I feel like it is a little messy. I was thinking about maybe making an enum to hold the distances and then using that enum to figure out how to convert it, but I'm looking for someone to just look at my code and tell me what I can do with it.
public class ConvertValuesAndCalculate {
final String BASE_UNIT = "centimetres";
double distance, shoeSize;
String distanceType, shoeRegion, gender;
public int convertAndCalculate(String dType, double distance,
String region, double size, String g) {
this.distanceType = dType;
this.distance = distance;
this.shoeRegion = region;
this.shoeSize = size;
this.gender = g;
distance = convertDistance(distance, distanceType);
Log.i("Distance Value (inches) ", "" + distance);
shoeSize = convertShoeSize(shoeSize, shoeRegion, gender);
Log.i("Shoe Size (inches) ", "" + shoeSize);
return (int) (distance / shoeSize);
}
private double convertShoeSize(double size, String region,
String g) {
double s = size;
s = convertRegionGender(s, region, g);
s = shoeSizeToCent(s);
return s;
}
private double shoeSizeToCent(double s) {
double sSize = s;
if (sSize == 3.5) {
sSize = 22.8;
} else if (sSize == 4) {
sSize = 23.1;
} else if (sSize == 4.5) {
sSize = 23.5;
} else if (sSize == 5) {
sSize = 23.8;
} else if (sSize == 5.5) {
sSize = 24.1;
} else if (sSize == 6) {
sSize = 24.5;
} else if (sSize == 6.5) {
sSize = 24.8;
} else if (sSize == 7) {
sSize = 25.1;
} else if (sSize == 7.5) {
sSize = 25.4;
} else if (sSize == 8) {
sSize = 25.7;
} else if (sSize == 8.5) {
sSize = 26;
} else if (sSize == 9) {
sSize = 26.35;
} else if (sSize == 9.5) {
sSize = 23.67;
} else if (sSize == 10) {
sSize = 26.99;
} else if (sSize == 10.5) {
sSize = 27.31;
} else if (sSize == 11) {
sSize = 27.62;
} else if (sSize == 11.5) {
sSize = 27.94;
} else if (sSize == 12) {
sSize = 28.26;
} else if (sSize == 12.5) {
sSize = 28.58;
} else if (sSize == 13) {
sSize = 28.89;
} else if (sSize == 13.5) {
sSize = 29.21;
} else if (sSize == 14) {
sSize = 29.53;
}
return sSize;
}
private double convertRegionGender(double s, String region,
String g) {
double size = s;
if (g.equals("Male")) {
switch (region) {
case "UK":
size += .5;
case "AUS":
size += .5;
case "JAPAN":
size -= 18;
}
}
return size;
}
private double convertDistance(double d, String dType) {
double dist;
switch (dType) {
case "Metres":
dist = metresToCent(d);
case "Inches":
dist = inchToCent(d);
case "Millimetres":
dist = millimetresToCent(d);
case "Kilometres":
dist = kilometresToCent(d);
case "Mile":
dist = mileToCent(d);
case "Yard":
dist = yardToCent(d);
case "Foot":
dist = footToCent(d);
case "Nautical Mile":
dist = nMileToCent(d);
default:
dist = d;
}
return dist;
}
private double mileToCent(double d) {
d *= 160934;
return d;
}
private double yardToCent(double d) {
d *= 91.44;
return d;
}
private double footToCent(double d) {
d *= 30.48;
return d;
}
private double nMileToCent(double d) {
d *= 185200;
return d;
}
private double inchToCent(double d) {
d *= 2.54;
return d;
}
private double kilometresToCent(double d) {
d *= 100000;
return d;
}
private double millimetresToCent(double d) {
d *= 0.1;
return d;
}
private double metresToCent(double d) {
d *= 100;
return d;
}
}
convertDistance
. \$\endgroup\$