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! :)