Last active
October 7, 2016 21:12
-
-
Save amanuel2/bd7cfeb8432adebce742dbea23739945 to your computer and use it in GitHub Desktop.
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 java.util.Scanner; | |
| /**************************************** | |
| * Amanuel Bogale | |
| * 9/28/16 | |
| * GradeCalc | |
| * Inputs 4 grades and as a result | |
| * finds the average of all grades | |
| ****************************************/ | |
| public class GradeCalc { | |
| static Scanner default_scan = new Scanner(System.in); // Scanner | |
| /* | |
| * Function to do all the | |
| * calculation and return | |
| * the average of all the | |
| * grades | |
| */ | |
| private static double getGrades(double[] grades, int times) { | |
| /* | |
| * User Inputs For | |
| * Grades | |
| */ | |
| int total = 0; | |
| for (int i = 0; i < times; i++) { | |
| System.out.println("Enter your #" + (i + 1) + " Grade"); | |
| grades[i] = default_scan.nextDouble(); | |
| total += grades[i]; | |
| } | |
| /* | |
| * Return the average | |
| * of all the grades | |
| */ | |
| return (total / times); | |
| } | |
| public static void main(String[] args) { | |
| String choice = new String("y"); // String object if user wants to continue | |
| while (choice.equals("y") || choice.equals("Y")) { | |
| START_CALC: | |
| /* | |
| * Ask User How Much Grades | |
| * To Count the average for | |
| */ | |
| System.out.println("Number of Grades : "); | |
| final int NUM_GRADES = default_scan.nextInt(); | |
| /* | |
| * Declare Array Where | |
| * Grades will be kept | |
| */ | |
| double grades[] = new double[NUM_GRADES]; | |
| /* | |
| * Print the average | |
| * of all the grades! | |
| */ | |
| System.out.println("The Average Grade is = " + getGrades(grades, NUM_GRADES)); | |
| /* | |
| * Ask User If he wants | |
| * To Continue | |
| */ | |
| System.out.println("Want to enter another grade? (y/n)"); | |
| choice = default_scan.next(); | |
| } | |
| System.out.println("Thanks for using the grade average calculator!"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment