-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Letter Grade converter functionality
- Loading branch information
Showing
3 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
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
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(); | ||
} | ||
|
||
} |
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
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
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() { | ||
|
||
} | ||
} |