Hey everyone! I’m in a bit of a pickle with my Java homework. I missed a class and now I’m trying to create a program that figures out grades for different courses. Here’s what I’ve got so far:
import java.util.Scanner;
public class ScoreCalculator {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
System.out.print("How many courses do you want to calculate scores for? ");
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 really stuck on how to continue. Any tips on using Math.min() and Math.max() would be super helpful. Thanks!
I’ve been in your shoes before, and I can help you out with this. Here’s how you can continue your program:
After getting the courseCount, create arrays to store course names and scores. Then, use a loop to input data for each course. Inside the loop, get the course name and scores, calculating the average as you go.
For Math.min() and Math.max(), initialize variables with the first score, then compare with subsequent scores in the loop. This way, you’ll track the lowest and highest scores.
After the loop, display results for each course. Remember to close your Scanner when you’re done.
Don’t forget to handle potential errors, like invalid inputs. It’s a good practice to add some error checking to make your program more robust.
Hope this helps you get unstuck! Let me know if you need more clarification.