Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Help!! Need to add a few things and I be lost!!

1. ## 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]  import java.io.FileNotFoundException;
import java.util.Scanner;

//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;

//Use an array to store the 3 test scores
private static int[] testScore = new int;

private static String name;

//initialize the average, grade and name to zero,empty and null
average = 0;

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);

}

}

//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) {

} else if (average < 90 && average >= 80) {

} else if (average < 80 && average >= 70) {

} else if (average < 70 && average >= 60) {

} else {

}

}

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"))) {

//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

//Calculate the average

//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.  Reply With Quote

3. ## Re: Help!! Need to add a few things and I be lost!!

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.

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?  Reply With Quote