This program determines the grade average, raised grade average, of individual students and all students.

The program takes scanner input. In the scanner, the number of students, the number of grades for each student, and the grades of each student are entered.

Ultimately, I need to print out each student's grade average, grade average when the lowest grade is dropped, total grade average of the "class," and raised grade average of the class.

I have been spending an inordinate amount of time on this.

Currently, my questions are:

How do I use nested for loops to take all the scores for ONE STUDENT before moving on to the next?

How do I prevent the program from totaling all the scores I'm entering as the total scores for the last student?

And how do I get the lowest score to drop?

That's where the program is malfunctioning right now.

I have posted the full code and output below. It's probably something simple, but I'm losing sleep over it!

Thanks :)

import java.util.Scanner;

public class TesterClass {
//Program is not distinguishing between the students
//And is not calculating the class average or raised class average.
	
public static void main(String[] args) {
	
int allTotal = 0;
int totalLowest = 0;
int studTotal = 0;
int studRaiseTotal = 0;
int numScores = 0;
int lowest = 0;
int students = 0;
double studRaiseAve = 0;
double studNormAve = 0;
double allAve = 0;
double allRaiseAve = 0;
	

Scanner testScan = new Scanner(System.in);
System.out.println("How many students are you entering scores for?"); 
students = testScan.nextInt();
System.out.println("How many scores do you need to enter for each student?");
numScores = testScan.nextInt();
int[] studentsArray = new int[students];	
int[] scoresArray = new int[numScores];

for(int bigTemp: studentsArray){ //determines how many scores are entered for each student
	
	
	
for(int temp: scoresArray) //determines the total and average scores for each student
{ 
			
		int n = bigTemp+1;
		System.out.println("Enter a score for student number: "+n);
		temp = testScan.nextInt();
		studTotal += temp;
			
			if(temp<lowest)
			{
			lowest = temp;
			
			
			 if(numScores>1);{
			 studRaiseTotal = studTotal-lowest;
			 studRaiseAve = (double)(studRaiseTotal/(numScores-1)); 
			 }
						 
			 if(numScores==1){
			 studRaiseTotal = studTotal;
			 studRaiseAve = (double) (studRaiseTotal/numScores);
			 }
			
			}
}			
			studNormAve = (double)(studTotal/numScores);

			System.out.println("Here is the student's total test scores.");
   		 	System.out.println(studTotal);
			System.out.println("Here is the student's average test scores.");
			System.out.println(studNormAve);
			System.out.println("Here is the student's raised score.");
			System.out.println(studRaiseAve);
			
			if (studNormAve>=70){
   		 		System.out.println("This student passes.");
				System.out.println("The student's average test score is: "+studNormAve);
   		 	}
    
   		 	else{
   		 		System.out.println("This student fails.");
				System.out.println("The student's average test score is: "+studNormAve);
   		 	}

}
allTotal += studTotal;
totalLowest += lowest;
	
System.out.println("Testing for the total: "+allTotal); 
System.out.println("Testing for the lowest: "+lowest); 
System.out.println("Testing for the total lowest: "+totalLowest);
    
allAve = (double)(allTotal/(students*numScores));
System.out.println("Here is the class's average.");
System.out.println(allAve);
    
allRaiseAve = (double)((allTotal-totalLowest)/(students*numScores));
System.out.println("Here is the raised class average.");
System.out.println(allRaiseAve);
    
}
}

How many students are you entering scores for?
2
How many scores do you need to enter for each student?
2
Enter a score for student number: 1
100
Enter a score for student number: 1
80
Here is the student's total test scores.
180
Here is the student's average test scores.
90.0
Here is the student's raised score.
0.0
This student passes.
The student's average test score is: 90.0
Enter a score for student number: 1
59
Enter a score for student number: 1
49
Here is the student's total test scores.
288
Here is the student's average test scores.
144.0
Here is the student's raised score.
0.0
This student passes.
The student's average test score is: 144.0
Testing for the total: 288
Testing for the lowest: 0
Testing for the total lowest: 0
Here is the class's average.
72.0
Here is the raised class average.
72.0

You are using condensed for loops with your int arrays, which can be tricky. Ints are not objects but primitive types, so if you change it within the loop, the value in the array will NOT be changed.
If you use

for(int j=0; j<students; j++)

you can access and change the variable of the current student with

studentArray[j]

.

Your questions:
1: Look into my explanation above, ask of it doesn't help.
2: Make an array with the total of each student, instead of an allStudentTotal variable.
3: In the end of your program, make a loop that loops through all the total scores of the students. In a variable outside the loop, keep a record of the index with the lowest score.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.