Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 3.
- import java.util.Scanner;
- public class Main {
- static final double QUIZ_WEIGHT = .10; // Counts for 10% of the final grade
- static final double HW_WEIGHT = .15; // Counts for 15% of the final grade
- static final double TEST_WEIGHT = .75; // Counts for 75% of the final grade
- private static Scanner in;
- public static void main(String[] args) {
- double test1, test2, test3, quizAvg, hwAvg;
- in = new Scanner(System.in);
- System.out.println("This program will compute your GPA");
- System.out.print("Enter your Quiz average: ");
- quizAvg = in.nextDouble();
- System.out.print("Enter your Homework average: ");
- hwAvg = in.nextDouble();
- System.out.print("Enter your score for Test 1: ");
- test1 = in.nextDouble();
- System.out.print("Enter your score for Test 2: ");
- test2 = in.nextDouble();
- System.out.print("Enter your score for Test 3: ");
- test3 = in.nextDouble();
- //Displays Tests
- System.out.println("High Test: " + highestTest(test1, test2, test3));
- System.out.println("Low Test: " + lowestTest(test1, test2, test3));
- System.out.println("Average Test: " + averageTest(test1, test2,test3));
- //Displays GPA
- System.out.println("GPA: " + getGPA(test1, test2, test3, quizAvg, hwAvg));
- }
- //Method : Returns GPA
- public static double getGPA(double t1, double t2, double t3, double q, double h) {
- double weightTest = (t1 + t2 + t3)/3.0 * TEST_WEIGHT;
- double weightQuiz = q * QUIZ_WEIGHT;
- double weightHW = h * HW_WEIGHT;
- return weightTest + weightQuiz + weightHW;
- }
- //Method: Returns The Average Test Score
- public static double averageTest(double test1, double test2, double test3) {
- return (test1 + test2 + test3)/3.0;
- }
- //Method: Returns The Highest Test Score
- public static double highestTest(double test1, double test2, double test3) {
- if (test1 >= test2 && test1 >= test3)
- return test1;
- else if (test2 >= test1 && test2 >= test3)
- return test2;
- else
- return test3;
- }
- //Method: Returns The Lowest Test Score
- public static double lowestTest(double test1, double test2, double test3) {
- if (test1 <= test2 && test1 <= test3)
- return test1;
- else if (test2 <= test1 && test2 <= test3)
- return test2;
- else
- return test3;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement