Help!! Need to add a few things and I be lost!!
Her's my code with print out below.
But I need the overall class average to be right, and I need to add A=x B=x C=x D=x F=x
X= how many where given out
I like to meet the person who said can't teach an old dog new tricks, I'm almost a believer.
Code :
[CODE] import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
public class StudentGrades {
//Declare variables and make the total test a constant equal to 3, since there are 3 tests
private static double TOTAL_TESTS = 3;
private static double average;
private static char grade;
//Use an array to store the 3 test scores
private static int[] testScore = new int[3];
private static String name;
public StudentGrades() {
//initialize the average, grade and name to zero,empty and null
average = 0;
grade = ' ';
name="null";
}
public static void getAverage(Scanner inFile) {
//create local variable to store temporary average in
int tempAverage = 0;
for (int num = 0; num <=2; num++) {
testScore[num] = inFile.nextInt();
//Add all the scores together per student
tempAverage = testScore[num] + tempAverage;
//Divide the average by the total amount of tests(3)
average = (double)tempAverage / (TOTAL_TESTS);
}
}
public char calculateGrade(Scanner inFile) {
//Assign a grade to the appropriate numerical value
//A=90-100 B=80-89 C=70-79 D=60-69 F=Below 60
if (average <= 100 && average >= 90) {
grade = 'A';
} else if (average < 90 && average >= 80) {
grade = 'B';
} else if (average < 80 && average >= 70) {
grade = 'C';
} else if (average < 70 && average >= 60) {
grade = 'D';
} else {
grade = 'F';
}
//Return the appropriate grade
return grade;
}
public static void main(String[] args) throws FileNotFoundException {
//Open the file that you are reading the information from
try (Scanner inFile = new Scanner(new FileReader("TestDate.txt"))) {
StudentGrades averages = new StudentGrades();
//Read the input file until there is no text
while (inFile.hasNext()) {
// get the name of the student
name = inFile.next();
// get the name of the student
StudentGrades.getAverage(inFile);
//Calculate the average
grade = averages.calculateGrade(inFile);
//Output each students name, test scores, average numerical grade and letter grade
for (int num = 0; num <= 2; num++) {
//calculate sum of all array elements
}
System.out.printf("%s\t has an average grade of %.2f You will receive a %s in this class.\n", name, average, grade);
}
System.out.printf("\nOverall Class Average is %.2f\n",average/1.4);
//generates three random numbers between 0 and 50, calculates the average.
int one,two,three;
one=(int)(Math.random()*(51));
two=(int)(Math.random()*(51));
three=(int)(Math.random()*(51));
int average=(one+two+three)/3;
System.out.printf("\nThe following program generates 3 random numbers, then averages them.\n");
System.out.printf("\nThe average of\t"+one+" "+two+" "+three+" is "+average);
}
}
}
[/CODE]
Current print out is:
Connie has an average grade of 85.33 You will receive a B in this class.
James has an average grade of 92.00 You will receive a A in this class.
Susan has an average grade of 52.33 You will receive a F in this class.
Jake has an average grade of 66.33 You will receive a D in this class.
Karen has an average grade of 77.33 You will receive a C in this class.
Bill has an average grade of 99.00 You will receive a A in this class.
Fred has an average grade of 85.33 You will receive a B in this class.
Cheryl has an average grade of 75.00 You will receive a C in this class.
Pam has an average grade of 65.00 You will receive a D in this class.
Steve has an average grade of 45.00 You will receive a F in this class.
John has an average grade of 86.33 You will receive a B in this class.
David has an average grade of 81.67 You will receive a B in this class.
Corina has an average grade of 91.67 You will receive a A in this class.
Delia has an average grade of 74.00 You will receive a C in this class.
Evan has an average grade of 99.00 You will receive a A in this class.
Overall Class Average is 70.71
The following program generates 3 random numbers, then averages them.
The average of 45 35 23 is 34
----jGRASP: operation complete.
Re: Help!! Need to add a few things and I be lost!!
Quote:
I need the overall class average to be right,
Please explain what the problem is. Show the current output and explain what is wrong with it and show the correct answer.
Quote:
I need to add A=x B=x C=x D=x F=x X= how many where given out
Can you explain what you are asking here? An example perhaps?