G
geletine
I have been asked to design and create a program that reads in a
sequence of student grades and computes the average grade, the number
of students who pass (a grade of at least 60) and the number who fail.
The program will print the total number of students, average grades,
number of students who pass and number of students who fail.
I may be looking at the problem in the completely wrong way but here is
my first attempt of the code
import java.io.*;
public class grades
{
public static void main (String args [])throws IOException
{
int totalstudents, averagegrade, numberofgrade, numberofstudents,
total;
String information ;
BufferedReader stgin = new BufferedReader ( new InputStreamReader (
System.in ) );
total = 0;
numberofstudents = 0;
totalstudents = 0;
averagegrade = 0;
System.out.println ("Enter the number of students");
information = stgin.readLine();
numberofstudents = Integer.parseInt (information) ;
System.out.println ("Enter grade of a student");
information = stgin.readLine();
numberofgrade = Integer.parseInt( information );
for ( numberofgrade = 1; numberofgrade >= 60; )
{
numberofstudents = numberofstudents + totalstudents;
total = total + numberofgrade ;
averagegrade = total / numberofgrade;
}
System.out.println ( " Total amount of students entered" +
totalstudents );
System.out.println ( " The average student grade is " + averagegrade);
System.out.println ( " Total amount of students that passed is " +
information );
for ( numberofgrade = 1; numberofgrade <60; )
{
numberofstudents = numberofstudents + totalstudents;
total = total + numberofgrade;
averagegrade = total / numberofgrade;
}
System.out.println ( " Total amount of students entered" +
totalstudents );
System.out.println ( " The average student grade is " + averagegrade);
System.out.println ( " Total amount of students that passed is " +
information);
}
}
sequence of student grades and computes the average grade, the number
of students who pass (a grade of at least 60) and the number who fail.
The program will print the total number of students, average grades,
number of students who pass and number of students who fail.
I may be looking at the problem in the completely wrong way but here is
my first attempt of the code
import java.io.*;
public class grades
{
public static void main (String args [])throws IOException
{
int totalstudents, averagegrade, numberofgrade, numberofstudents,
total;
String information ;
BufferedReader stgin = new BufferedReader ( new InputStreamReader (
System.in ) );
total = 0;
numberofstudents = 0;
totalstudents = 0;
averagegrade = 0;
System.out.println ("Enter the number of students");
information = stgin.readLine();
numberofstudents = Integer.parseInt (information) ;
System.out.println ("Enter grade of a student");
information = stgin.readLine();
numberofgrade = Integer.parseInt( information );
for ( numberofgrade = 1; numberofgrade >= 60; )
{
numberofstudents = numberofstudents + totalstudents;
total = total + numberofgrade ;
averagegrade = total / numberofgrade;
}
System.out.println ( " Total amount of students entered" +
totalstudents );
System.out.println ( " The average student grade is " + averagegrade);
System.out.println ( " Total amount of students that passed is " +
information );
for ( numberofgrade = 1; numberofgrade <60; )
{
numberofstudents = numberofstudents + totalstudents;
total = total + numberofgrade;
averagegrade = total / numberofgrade;
}
System.out.println ( " Total amount of students entered" +
totalstudents );
System.out.println ( " The average student grade is " + averagegrade);
System.out.println ( " Total amount of students that passed is " +
information);
}
}