diff --git a/BMI.java b/BMI.java new file mode 100644 index 0000000..0cc0ba9 --- /dev/null +++ b/BMI.java @@ -0,0 +1,37 @@ + +public class BMI extends GaddisChallenges { + + private double userWeight; //pounds + private double userHeight; //inches + private double userBmi; + private String weightStatus; + + public void start() { + + collectInfo(); + + userBmi = userWeight * 703/(userHeight * userHeight); + + if (userBmi >= 18.5 && userBmi < 25) { + weightStatus = "optimal"; + } + else if (userBmi < 18.5) { + weightStatus = "underweight"; + } + else if (userBmi > 25) { + weightStatus = "overweight"; + } + + print("Based on your height and weight, your BMI is " + + userBmi + " so your weight is " + weightStatus); + + } + + private void collectInfo() { + print("What is your height? "); + userHeight = scan.nextDouble(); + print("What is your weight? "); + userWeight = scan.nextDouble(); + } + +} \ No newline at end of file diff --git a/GaddisChallenges.java b/GaddisChallenges.java index 9be88ae..e37300f 100644 --- a/GaddisChallenges.java +++ b/GaddisChallenges.java @@ -1,5 +1,11 @@ import java.util.Scanner; +/* +future additions: +- threading +- GUI +*/ + public class GaddisChallenges { private Scanner scan = new Scanner(System.in); @@ -13,7 +19,15 @@ public static void main(String[] args) { print("Question 2: Magic Dates"); MagicDates mc = new MagicDates(); - mc.start() + mc.start(); + + print("Question 3: Body Mass Index"); + BMI bmi = new bmi BMI(); + bmi.start(); + + print("Question 4: Test Scores and Grade"); + LetterGrades lg = new LetterGrades(); + lg.start(); } private void print(String text) { diff --git a/LetterGrades.java b/LetterGrades.java new file mode 100644 index 0000000..b629515 --- /dev/null +++ b/LetterGrades.java @@ -0,0 +1,40 @@ +public class LetterGrades { + + private int numTests = 3; + private double[] testGrades[]; + private double average; + private char letterGrade; + + public void start() { + + collectInfo(); + + calculateAverage(); + + calculateLetterGrade(); + + print(" You average is " + average + "and you letter grade is " + letterGrade); + + } + + private void collectInfo() { + + for (int i = 1; i <= numTests; i++) { + print("What was your grade on Test " + i + "?") + testGrades[i] = scan.nextDouble(); + } + + } + + private void calculateAverage() { + int sumTestGrades = 0; + for (int i = 1; i <= testGrades.length; i ++) { + sumTestGrades += testGrades[i]; + } + average = sumTestGrades / numTests; + } + + private void calculateLetterGrade() { + + } +} \ No newline at end of file