PDA

View Full Version : java beginner, help on grade calculator



bokononist
04-09-2007, 02:40 AM
Hey, I'm taking my first programming class and I'm pretty stuck on my first java project. Any advice would be really appreciated, thanks a lot. I think the problem might be that I'm declaring some things wrong, but I'm sure it's pretty full of other mistakes too. The program is supposed to collect some grades and make some computations with them.


import java.io.*;

public class GradeAverage {

public static void main(String[] args) throws IOException {

//stdin.readLine() will be used to get user input
BufferedReader stdin = new BufferedReader(
new InputStreamReader(System.in));

//The max size of our arrays
int arraySize = 100;

//A String array to hold some names
String[] names = new String[arraySize];
String[] firstNames = new String[arraySize];
//grade holder
int[] firstGrades;
int[] secondGrades;
int[] thirdGrades;
//A temp holder for a name, and a count of the number of students entered
String tempName;
int numberOfNames;


//This loop goes through the array and asks for a name
//for each slot in the array
for(int i=0; i<arraySize; i++) {
System.out.print("Enter last name " + i + ": ");
tempName = stdin.readLine();

//Check to see if the entered name is a period
//if so, we can quit
if(tempName.equals(".")) {
break;
}

//If it passed the previous check, we can enter the name and increment our counter
names[i] = tempName;
numberOfNames++;
//rest of info
String[i] firstName;
for(int i=0; i<arraySize; i++) {
System.out.print("Enter first name " + i + ": ");
firstName = stdin.readLine();}
firstNames[i] = firstName;

int[i] firstGrade = 0;
for(int i=0; i<arraySize; i++) {
System.out.print("Enter first grade " + i + ": ");
firstGrade = stdin.readLine();}
firstGrades[i] = firstGrade;

int[i] secondGrade = 0;
for(int i=0; i<arraySize; i++) {
System.out.print("Enter second grade " + i + ": ");
secondGrade = stdin.readLine();}
secondGrades[i] = secondGrade;

int[i] thirdGrade = 0;
for(int i=0; i<arraySize; i++) {
System.out.print("Enter third grade " + i + ": ");
thirdGrade = stdin.readLine();}
thirdGrades[i] = thirdGrade;





}

//Print out each array index and corresponding name with a tab in between
for(int i=0; i<numberOfNames; i++) {
System.out.println(i + "\t" + names[i]);
}
for(int i=0; i<numberOfNames; i++) {
System.out.println(i + "\t" + firstNames[i]);
}
for(int i=0; i<numberOfNames; i++) {
System.out.println(k + "\t" + firstGrades[i]);
}
for(int i=0; i<numberOfNames; i++) {
System.out.println(i + "\t" + secondGrades[i]);
}
for(int i=0; i<numberOfNames; i++) {
System.out.println(i + "\t" + thirdGrades[i]);
}
//computations
int[i] averageGrade;
int sumAverage;
int totalAverage;
averageGrade[i] = (firstGrades[i]+secondGrades[i]+thirdGrades[i])/3;
for (int i=0; i<numberOfNames; i++) {
sumAverage = sum + averageGrade[i];
}
totalAverage = sumAverage/numberOfNames;
//output
for(int i=0; i<numberOfNames; i++) {
System.out.println(i + "\t" + names[i] + "\t" firstNames[i] + "\t" + averageGrade [i]);
}
System.out.println( "the class average is" + totalAverage;
}




}