Java Program for Course Grade Calculation

Hey folks, I’m stuck on a Java assignment. I missed class and need help creating a program that figures out grades for multiple courses. Here’s what I’ve got so far:

import java.util.Scanner;

public class ScoreAnalyzer {
    public static void main(String[] args) {
        Scanner userInput = new Scanner(System.in);
        System.out.print("How many courses do you want to analyze? ");
        int courseCount = userInput.nextInt();
        
        // Not sure what to do next...
        // Need to use Math.min() and Math.max() somehow
    }
}

The program should ask for course names and scores, then show the average, lowest, and highest scores for each course. I’m lost on how to continue. Any tips on using Math.min() and Math.max() would be great. Thanks!

yo Mia, sounds like a tricky assignment! here’s a tip: use arrays to store course names and scores. for each course, loop through scores to find min/max:

while (inputting scores) {
minScore = Math.min(minScore, score);
maxScore = Math.max(maxScore, score);
}

hope that helps! lmk if u need more help

Hey Mia_79Dance! No worries about missing class, it happens to the best of us. :blush: Your program’s off to a good start! Here’s a friendly nudge in the right direction:

Have you thought about using arrays to store the course names and scores? That could make things easier to manage. You could create two arrays: one for course names (String) and another for scores (double).

As for using Math.min() and Math.max(), they’re super handy for finding the lowest and highest scores. You could keep track of these while inputting scores for each course. Something like:

double minScore = Double.MAX_VALUE;
double maxScore = Double.MIN_VALUE;

// In your input loop
minScore = Math.min(minScore, currentScore);
maxScore = Math.max(maxScore, currentScore);

What do you think about this approach? Do you have any ideas on how you might calculate the average score for each course? I’m curious to see what you come up with!

Let me know if you need any more hints or explanations. We’re all here to learn and help each other out! :rocket:

I’ve tackled similar assignments before, and here’s what worked for me:

Create separate arrays for course names and scores. Then, implement nested loops - an outer one for each course and an inner one for inputting scores. As you input scores, update running totals for sum, min, and max.

Here’s a rough outline:

String[] courseNames = new String[courseCount];
double[][] scores = new double[courseCount][];

for (int i = 0; i < courseCount; i++) {
    // Input course name and number of scores
    // Initialize scores[i] with correct length
    
    double sum = 0, min = Double.MAX_VALUE, max = Double.MIN_VALUE;
    for (int j = 0; j < scores[i].length; j++) {
        // Input score
        sum += scores[i][j];
        min = Math.min(min, scores[i][j]);
        max = Math.max(max, scores[i][j]);
    }
    // Calculate and store average, min, max for this course
}

// Display results

This approach efficiently uses Math.min() and Math.max() while keeping your code organized. Good luck with your assignment!