Skip to content

Commit

Permalink
added Letter Grade converter functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
fine-code committed Oct 19, 2020
1 parent f3ba5bd commit c090f7f
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
37 changes: 37 additions & 0 deletions BMI.java
Original file line number Diff line number Diff line change
@@ -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();
}

}
16 changes: 15 additions & 1 deletion GaddisChallenges.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import java.util.Scanner;

/*
future additions:
- threading
- GUI
*/

public class GaddisChallenges {

private Scanner scan = new Scanner(System.in);
Expand All @@ -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) {
Expand Down
40 changes: 40 additions & 0 deletions LetterGrades.java
Original file line number Diff line number Diff line change
@@ -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() {

}
}

0 comments on commit c090f7f

Please sign in to comment.