Last active
September 5, 2020 23:25
-
-
Save Zelakolase/89de6fbf31b771b8a23934b662d6c500 to your computer and use it in GitHub Desktop.
B.M.I Calculator in java
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
import javax.swing.JOptionPane; | |
public class main { | |
public static void main(String[] args) { | |
// B.M.I = Mass (kg) / (Height (M))^2 | |
String Mass = JOptionPane.showInputDialog("Input your mass in kilograms"); | |
String Height = JOptionPane.showInputDialog("Input your height in Centimeters"); | |
double MassD = Double.valueOf(Mass); | |
double HeightD = Double.valueOf(Height); | |
HeightD = HeightD/100.0; | |
double BMI = MassD / Math.pow(HeightD, 2); | |
double MinNormalMass = 18.5 * Math.pow(HeightD, 2); | |
double MaxNormalMass = 24.9 * Math.pow(HeightD, 2); | |
boolean IsFat = MassD > MaxNormalMass; | |
boolean IsSkinny = MassD < MinNormalMass; | |
boolean IsFit = MassD >= MinNormalMass && MassD <= MaxNormalMass; | |
Integer PerfectWeight = (int) Math.round((MaxNormalMass+MinNormalMass)/2); | |
if(IsFat) { | |
JOptionPane.showMessageDialog(null, "You're fat, Your weight shouldn't exceed "+Math.round(MaxNormalMass)+" Kilograms.\nPerfect Weight is: "+PerfectWeight+" Kilograms.\n You should lose "+Math.round((MassD-MaxNormalMass))+" Kilograms."); | |
}else if(IsSkinny) { | |
JOptionPane.showMessageDialog(null, "You're skinny, Your weight should be "+Math.round(MinNormalMass)+" Kilograms.\nPerfect Weight is: "+PerfectWeight+" Kilograms.\n You should gain "+Math.round((MinNormalMass-MassD))+" Kilograms"); | |
}else if(IsFit) { | |
JOptionPane.showMessageDialog(null, "You're fit !"+"\nPerfect Weight is: "+PerfectWeight); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment