# So confused, I need help!

• November 2nd, 2012, 10:35 PM
sessypeanut
So confused, I need help!
I am taking an intro to java programming class, and I have never done programming before, ever. I'm in a little over my head and my book sucks. My teacher just gave us an assignment after not giving us anything for a month. We need to do the following:

Write a Java program that processes students’ grades.
The program will:
 Repeatedly prompt the user to enter new score or enter -1 to exit
 Assign a grade from F to A to this student and print both the score and
the grade in table with an appropriate header in an output file. The
exact form of the table is left for you to choose
 Count how many A’s, B’s, etc in the class
 Calculate the largest and the lowest score of every grade. For example
the highest A might be 98 and the lowest is 91 and so on
 Calculate the average score of every grade
 Calculate the highest and lowest score in the entire class
 After printing the above mentioned table, report all cumulative results
in the output file with appropriate messages. E.G.
o There were 5 A students in class
o The highest A in class was 99
 An example output is given next page.
 Maintain good indentations that make it readable.
different parts of the program and what their functions are.
 Store the output in file called grades.txt
 Be able to deal with the total absence of one or more grades. For
example, in some cases there are no A’s in class
Make sure that the program is your own work. You may be required to have
homework is finalized.

We have to make a table that looks like this and have the information below it as well.
20 F
98 A
91 A
87 B
85 B
89 B
90 A
62 D
30 F
99 A

There are 4 A student(s) in class
The highest A is 99
The lowest A is 90
The average A is 94.5
++++++++++++++
There are 3 B student(s) in class
The highest B is 89
The lowest B is 85
The average B is 87
++++++++++++++
There are no C students this time
++++++++++++++
There are 1 D student(s) in class
The highest D is 62
The lowest D is 62
The average D is 62
++++++++++++++
There are 2 F student(s) in class
The highest F is 30
The lowest F is 20
The average F is 25
++++++++++++++

To top it all off, it has to print out to a file. I have some of it figured out. I can't figure out the table. Right now the first number I enter is completely ignored and then it doesn't let me enter in any other numbers after the second number is entered and then the rest of the information is wrong.

Here is my (working) code:
Code java:

import java.util.Scanner; // program uses class Scanner

{
public static void main( String[] args )
{
int total = 0; //sum of grades
int aCount = 0; // count of A grades
int aMax = 0; // max of A grade
int aMin = 0; // min of A grade
int bCount = 0; // count of B grades
int cCount = 0; // count of C grades
int dCount = 0; // count of D grades
int fCount = 0; // count of F grades

Scanner input = new Scanner( System.in );

System.out.printf( "%s\n%s\n",
"Type -1 when finished" ); // enter grades and terminate when done

while ( grade != -1 )
{

{
++aCount; // increment aCount
}
else if ( grade >= 80 )
{
++bCount; // increment cCount
}
else if ( grade >= 70 )
{
++cCount; // increment cCount
}
else if ( grade >= 60 )
{
++dCount; // increment dCount
}
else
{
++fCount; // increment fCount
}

{
System.out.println("----------------------");
System.out.println("----------------------");

if ( aCount != 0 )
{
int avgA; // A Average
System.out.printf("There are %d A student(s) in class \n", aCount); // aCount
System.out.printf("The Average A is %d\n", avgA);
}
else
{
System.out.printf("There are no A students this time \n");
}

System.out.print("++++++++++++++ \n");

if ( bCount != 0 )
{
int avgB; // B Average
System.out.printf("There are %d B student(s) in class \n", bCount); // bCount
System.out.printf("The Average B is %d\n", avgB);
}
else
{
System.out.printf("There are no B students this time \n");
}

System.out.print("++++++++++++++ \n");

if ( cCount != 0 )
{
int avgC; // C Average
System.out.printf("There are %d C student(s) in class \n", cCount); // cCount
System.out.printf("The Average C is %d\n", avgC);
}
else
{
System.out.printf("There are no C students this time \n");
}

System.out.print("++++++++++++++ \n");

if ( dCount != 0 )
{
int avgD; // D Average
System.out.printf("There are %d D student(s) in class \n", dCount); // dCount
System.out.printf("The Average D is %d\n", avgD);
}
else
{
System.out.printf("There are no D students this time \n");
}

System.out.print("++++++++++++++ \n");

if ( fCount != 0 )
{
int avgF; // F Average
System.out.printf("There are %d F student(s) in class \n", fCount); // fCount
System.out.printf("The Average F is %d\n", avgF);
}
else
{
System.out.printf("There are no F students this time \n");
}

System.out.print("++++++++++++++ \n");
}
}
}
}

And this is what it gives me:

Type -1 when finished
1
2
----------------------
----------------------
There are no A students this time
++++++++++++++
There are no B students this time
++++++++++++++
There are no C students this time
++++++++++++++
There are no D students this time
++++++++++++++
There are 1 F student(s) in class
The Average F is 70
++++++++++++++

First I tried to do this with a switch statement but after asking for help all my teacher really said was that I should be using an if/else statement, not a switch statement. I'm super frustrated and really need help.
• November 2nd, 2012, 10:45 PM
C++kingKnowledge
Re: So confused, I need help!
for others to read your code easier enclose it in (highlight=Java) code here (/highlight) with brackets [ ] instead of ( )