1

thank you for your help.

Here is the assignment:

Computer Technology Instructor has a small class of 10 students. The instructor evaluates the performance of students in the class by administering 2 midterm tests and a Final Exam. Write a program that prompts the instructor to enter the 10 grades of midterm 1 and store these numbers in an array. Next prompt for the 10 grades of midterm 2 and store these numbers in a different array. Next prompt for the 10 grades of the Final Exam and store these in a different array. Next add midterm1 to midterm2 to Final and store the totals in a different array. Next, scan the array that has the totals and identify the minimum grade and maximum grade. Inform the instructor of the minimum grade and maximum grade.

The two bold phrases are where I am having problems. Everything works except for the minimum grade and maximum grade. Here is what it tells me, after I've only entered numbers between 65 and 100:

The highest test score is: 276 The lowest test score is: 249

Here is my code:

import java.util.Scanner;

public class Arrays {
    public static void main(String[] args) {
        // Create a scanner
        Scanner input = new Scanner(System.in);
// Prompt for the 1st mid term
    int [] midTerm1 = new int[10];
    int [] midTerm2 = new int[10];
    int [] finalExam = new int[10];
    int [] grades = new int[10];

    for (int i = 0; i < midTerm1.length; i++){
        System.out.println("Enter the 10 Mid Term 1 grades: ");
        midTerm1[i] = input.nextInt();
    }

    // Prompt for the 2nd mid term


    for (int i = 0; i < midTerm2.length; i++){
        System.out.println("Enter the 10 Mid Term 2 grades: ");
        midTerm2[i] = input.nextInt();
    }


    // Prompt for Final grades


    for (int i = 0; i < finalExam.length; i++){
        System.out.println("Please enter a Final Exam grade: ");
        finalExam[i] = input.nextInt();
    }



    for (int i = 0; i < grades.length; i++){
        grades[i] = (midTerm1[i] + midTerm2[i] + finalExam[i]);
    }

    int minGrade = grades[0];
    int maxGrade = grades[0];

    for (int i = 0; i < grades.length; i++)

    {
    if (minGrade > grades[i])
      minGrade = grades[i];
    if (maxGrade < grades[i])
      maxGrade = grades[i];

    }


    System.out.print("The highest test score is: " + maxGrade);
    System.out.print("The lowest test score is: " + minGrade);

}
}

1 Answer 1

4

Edit:

grades[i] = (midTerm1[i] + midTerm2[i] + finalExam[i]);

Your code may in fact be correct. Since you're adding your three test scores together, expect that the grade will be not between 65 and 100 but rather between 195 and 300.

If you want a number between 65 and 100, this needs to be divided by 3:

grades[i] = (midTerm1[i] + midTerm2[i] + finalExam[i]) / 3;

or else find some other way to normalize the grades. For instance, if the final is 50% of the grade then you could have:

grades[i] = (25 * midTerm1[i] + 25 * midTerm2[i] + 50 * finalExam[i]) / 100;

But again your current solution may in fact be the correct one.

Sign up to request clarification or add additional context in comments.

4 Comments

Based on the instructions, it doesn't seem like the min and max should be between 65 and 100. It doesn't seem like it wanted them to be averaged or weighted in any way it just wanted the total.
@AlliK: thanks and yep, I agree, that's why I edited my answer and added the last current line.
I think @Christf doesn't realize the code is correct though based on the instructions so I was just trying to point that out. The code for min and max is right.
Well, I feel slightly embarrassed. I should have read more carefully since it says "scan the array THAT HAS THE TOTALS" Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.