954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Simple problem: calculate grade averages/raised averages from file

public class Grades{
	
public int scoreTotal;
public int numScores;
double average;
static String file = "randomNumbers.txt"; 	
int lowest;
int x;
int temp;

public static void main(String[] args) throws FileNotFoundException{

int scoreTotal = 0;
int numScores = 0;
double average = 0;
int lowest = -1;
int temp = 0;

Scanner optScan = new Scanner(System.in);
System.out.println("Do you want to drop your lowest score? Enter true or false.");
boolean isDropped = optScan.nextBoolean(); 
    
Scanner scan = new Scanner(file);    

while(scan.hasNextInt()){
temp = scan.nextInt();
scoreTotal += temp;

   	 	if(lowest>temp) {
   	 		lowest = temp;
   	 		}
 

    if(isDropped==true){
   	average = (scoreTotal-lowest)/(numScores-1);
    }
    
    else if(isDropped==false){
   	average = (scoreTotal/numScores);
    }
}
System.out.println("This is the average: "+average);    
System.out.println("This is the score total: " +scoreTotal);
System.out.println("This is the lowest: " +lowest);

}
}

Currently, it is returning this if I type in true for the boolean isDropped:
This is the average: 0.0
This is the score total: 0
This is the lowest: -1


And if false:
This is the average: 0.0
This is the score total: 0
This is the lowest: -1

So it's not calculating anything, it's only taking the initial values. I'm pretty new to Java and have been tweaking this for a while...with no results. Help appreciated greatly, thanks! :)

LogicalOutlier
Newbie Poster
8 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

For debugging your code I'd recommend you add printlns to show the values of variables as they change and to show the execution flow. The print out should help you understand what the problem is.

You forgot to show what the correct output should be.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: