Created
September 17, 2017 12:52
-
-
Save naijab/3004cde1ed61a6d1af4df56df8c412ca to your computer and use it in GitHub Desktop.
Bmi Calculator
This file contains 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
import java.text.DecimalFormat; | |
import java.util.Scanner; | |
public class Bmi { | |
private static Scanner scanner; | |
public static void main(String[] args) { | |
scanner = new Scanner(System.in); | |
System.out.print("Enter National [TH, JP]: "); | |
String national = scanner.next(); | |
System.out.print("Enter weight[kg]: "); | |
double weight = scanner.nextDouble(); | |
System.out.print("Enter height[cm]: "); | |
double height = scanner.nextDouble(); | |
double bmi = bmiCal(height, weight); | |
System.out.print(checkNation(national, bmi)); | |
} | |
private static String checkNation(String national, double bmi) { | |
DecimalFormat dc = new DecimalFormat("0.00"); | |
if (national.equalsIgnoreCase("TH")) { | |
return national = "You are Thai: " + dc.format(bmi) + " is " + rateThai(bmi); | |
} else if (national.equalsIgnoreCase("JP")) { | |
return national = "You are Japan:" + dc.format(bmi) + " is " + rateJapan(bmi); | |
} else { | |
return national = "Not found nation"; | |
} | |
} | |
private static double bmiCal(double height, double weight) { | |
return weight / ((height / 100) * (height / 100)); | |
} | |
private static String rateThai(double bmi) { | |
if (bmi > 30.0) { | |
return "Obese"; | |
} else if (bmi >= 23.0 && bmi <= 29.9) { | |
return "Overweight"; | |
} else if (bmi >= 18.5 && bmi <= 22.9) { | |
return "Normal"; | |
} else { | |
return "lowerweight"; | |
} | |
} | |
private static String rateJapan(double bmi) { | |
if (bmi > 25.0) { | |
return "Obese"; | |
} else if (bmi >= 23.0 && bmi <= 24.9) { | |
return "Overweight"; | |
} else if (bmi >= 18.5 && bmi <= 22.9) { | |
return "Normal"; | |
} else { | |
return "lowerweight"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment