I'm taking a java class online, and I need to make a program that calculates grades. However, my output is supposed to have decimal places, but instead it has a single 0. I understand that when you divide a double by an integer it truncates (or removes the decimal values in case I am using that word wrong) it, but I'm not allowed to change the initializations or add any. That would mean I can't change the data type from int to double in the initializations.
I'm not too sure what the right terminology is for this, as my searches on both here and google have turned up with nothing.
Test 3's average calculation is supposed to have the decimal place. the first two come up with 97.0 and 88.0, as they are supposed to. The third one is supposed to come up with 86.333 with the three repeating.
//local variables
int numTests = 0; //counts number of tests
int testGrade = 0; //individual test grade
int totalPoints = 0; //total points for all tests
double average = 0.0; //average grade
//Test 1 Grade
testGrade = 97;
numTests++; //number of tests increased by one.
totalPoints = totalPoints + testGrade; //add the test grade to the total points.
average = (totalPoints / numTests); //calculate the average out of all the tests.
System.out.print("n = " + numTests + " New Test Grade = " + testGrade + " Total Points = " + totalPoints);
System.out.println(" Average Score: " + average);
//Test 2 Grade
testGrade = 79;
numTests++;
totalPoints += testGrade;
average = (totalPoints / numTests);
System.out.print("n = " + numTests + " New Test Grade = " + testGrade + " Total Points = " + totalPoints);
System.out.println(" Average Score: " + average);
//Test 3 Grade
testGrade = 83;
numTests++;
totalPoints += testGrade;
average = (totalPoints / numTests);
System.out.print("n = " + numTests + " New Test Grade = " + testGrade + " Total Points = " + totalPoints);
System.out.println(" Average Score: " + average);