I'm working on the following assignment and could use some help:

A teacher has five students who have taken four tests.The teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four test scores:

Test Score Letter Grade
90-100 A
80-89 B
70-79 C
60-69 D
0-59 F

Write a class that uses a string array or an ArrayList object to hold the five students' names, an array of five characters to hold the five students' letter grades, and five arrays of four doubles each to hold each student's set of test scores. The class should have methods that return a specific student's name, average test score, and a
letter grade based on the average. Demonstrate the class in a program that allows the user to enter each student's name and his or her four test scores. It should then display each student's average test score and letter grade. Input validation: Do not accpet test scores less than zero or greater than 100.

Here are my two files of code that I have so far:

public class Grades
{	// Begin public class Grades

	private double[] testScores;	// Variable that will ref an array of test scores

	/**
		Constructor
		@param scoreArray An array of test scores
	*/

	public Grades(double[] scoreArray)
	{	// Assign the array argument to the testScores field
		testScores = scoreArray;
	}

	/**
		getAverage method
		@return The average of the test scores
	*/

	public double getAverage()
	{	// Begin public double getAverage()
		double total = 0;	// To hold the score total
		double average;		// To hold the average

		// If array contains less than 4 test scores, display error message and set
		// average to 0
		if (testScores.length < 4)
		{	// Begin if statement
			System.out.println("Error: You must have atleast " +
								"four test scores!");
			average = 0;
		}	// End if statement
		else
		{	// Begin else statement
			// Calculate total of the scores
			for (double score : testScores)
				total += score;
			// Get the average of the scores
			average = total / (testScores.length - 1);
		}	// End else statement

		// Return the average of the test scores
		return average;

	}	// End public double getAverage()

}	// End public class Grades
import java.text.DecimalFormat;		// Needed to format test score average
import javax.swing.JOptionPane;		// Needed for showInputDialog & showMessageDialog

public class calcAverage
{	// Begin public class calcAverage
	static DecimalFormat formatter = new DecimalFormat("###.##");	// Global decimal formatter

	public static void main(String[] args)
	{	// Begin public static void main(String[] args)

		int numScores;		// To hold the number of scores
		String studNames;		// To hold the names of the students

		// Get the number of test scores
		System.out.println("How many test scores do you have? ");

		numScores = keyboard.nextInt();

		// Get the names of the students
		System.out.println("Please enter the student's name ");

		// Create an array to hold the test scores
		double[] scores = new double[numScores];

		// Create an array to hold the names of the students
		String[] names = new String[studNames];

		// Get the test scores and store them in the scores array
		for (int index = 0; index < numScores; index++)
		{	// Begin for loop
			System.out.println("Enter score" +
								(index + 1) + ": ");
			scores[index] = keyboard.nextDouble();
		}	// End for loop

		// Create a Grades object, passing the scores array as an argument to the constructor
		Grades myGrades = new Grades(scores);

		// Display the average of the test scores
		System.out.println("Your test score average is " +
							myGrades.getAverage());

	}	// End public static void main(String[] args)

}	// End public class calcAverage

If someone could please give me some direction as to where I go from here, I would appreciate it.

Recommended Answers

All 14 Replies

You are heading in a decent enough direction (there's too much code (eg collection of student names) in main that should be in the Grades class, but don't worry about that yet) - have you tried executing your code? There's enough here to try a run and (probably) generate some errors that you can start to fix. Once you get some code running, that will give you a base, and the motivation, to improve it.

So can I just add another constructor in the Grades class for the students' names? Also, I am trying to figure out the string arrays versus an array list. I know I need to start at index[0] for the array, but can you give me an example of how I would do this since I can't really initialize the array since I'm asking the user for the students' names instead of just assiging them and doing it as a test program. First I think I understand what I need to do, then I second guess myself and get more confused.

I have a slight problem here, because the "right" way to do this is to have something like a Student class that holds one student's name & scores, the have an ArrayList of Students. However, that doesn't quite fit the very specific way the project has been specified.
So, sticking with the spec., your class needs to have arrays for student name etc for all the students.
Rather than trying to do too much in constructors, I'd suggest a single constructor for the class (mayber taking as a parameter the number of students so it can initialise all the arrays to the right sizes), then use traditional getters & setters to populate the arrays from the test program ...

Students students = new Students(5);
students. setName(0, "Fred"); // name of first student
students. setName(1, "Jane"); // name of second student
students.setScores(0 , 10,20,30,40,50); // scores for first student
students,getGrade(0);  // returns grade for first student

As for array vs ArrayList for the names...
ArrayList is virtually alweays a better choice then array in real-life applications because its easier to handle variable numbers of things. In this case the size is known, so there's not much in it. Since you have to use arrays for the scores etc, maybe you should stick to arrays for now, and get into ArrayLists later.
You can initialise an array without knowing the values:

String[] strings = new String[5]; / array of 5 strings (all null)
strings[0] = "first string"; // etc

Ok, here are my revised codes. I tried compiling and got tons of errors referencing "class, interface, or enum expected" and I'm not sure what that is referring to. For example, in the Grades.java file, it is stating this error at line 160 where I have " } // End if statement ".

public class Grades
{	// Begin public class Grades

	private double[] testScores;	// Variable that will ref an array of test scores

	/**
		Constructor
		@param scoreArray An array of test scores
	*/ 	public Grades(double[] scoreArray)

	{	// Assign the array argument to the testScores field
	testScores = scoreArray;
	}

	/**
		getAverage method
		@return The average of the test scores
	*/ 	public double getAverage()

	{	// Begin public double getAverage()

	double total = 0;	// To hold the score total
	double average;		// To hold the average

	// If array contains less than 4 test scores, display error message and set
	// average to 0
	if (testScores.length < 4)
	{	// Begin if statement
	System.out.println("Error: You must have atleast " +
				"four test scores!");

	average = 0;
	}	// End if statement
	else
	{	// Begin else statement
	// Calculate total of the scores
	for (double score : testScores)

	total += score;			// Get the average of the scores
	average = total / (testScores.length - 1);
	}	// End else statement

	// Return the average of the test scores
	return average;

	}	// End public double getAverage()

}	// End public class Grades


	private double[] testScores;	// Variable that will ref an array of test scores

	/**
		Constructor
		@param scoreArray An array of test scores
	*/

	public Grades(double[] scoreArray)
	{	// Assign the array argument to the testScores field
		testScores = scoreArray;
	}

	/**
		getAverage method
		@return The average of the test scores
	*/

	public double getAverage()
	{	// Begin public double getAverage()
		double total = 0;	// To hold the score total
		double average;		// To hold the average

		// If array contains less than 4 test scores, display error message and set
		// average to 0
		if (testScores.length < 4)
		{	// Begin if statement
			JOptionPane.showMessageDialog("Error: You must have atleast " +
											"four test scores!");
			average = 0;
		}	// End if statement
		else
		{	// Begin else statement
			// Calculate total of the scores
			for (double score : testScores)
				total += score;
			// Get the average of the scores
			average = total / (testScores.length - 1);
		}	// End else statement

		// Return the average of the test scores
		return average;

	}	// End public double getAverage()



	private String[] studNames;		// Variable that will ref an array of student names

		/**
			Constructor
			@param namesArray An array of student names
		*/

		public Grades(String[] namesArray)
		{	// Assign the array argument to the studNames field
			studNames = namesArray;
		}

		/**
			getNames method
			@return The names of the students

		*/

		public String getNames()
		{	// Begin public String getNames()
			String names;		// To hold the student names

			// If array contains less than 5 students, display error message
			if (studNames.length < 5)
			{	// Begin if statement
				JOptionPane.showMessageDialog("Error: You must have atleast " +
									"five student names!");
			}	// End if statement

			// Return the student names
			return names;

	}	// End public double getstudNames()

}	// End public class Grades
import java.text.DecimalFormat;		// Needed to format test score average
import javax.swing.JOptionPane;		// Needed for showInputDialog & showMessageDialog

public class calcAverage
{	// Begin public class calcAverage
	static DecimalFormat formatter = new DecimalFormat("###.##");	// Global decimal formatter

	public static void main(String[] args)
	{	// Begin public static void main(String[] args)

		int numScores;						// To hold the number of scores
		String studNames;					// To hold the names of the students
		String[] strings = new String[5]; 	// Array of 5 strings
		String[0] = " "; 					// First Name string array
		String[1] = " ";					// Second Name string array
		String[2] = " ";					// Third Name string array
		String[3] = " ";					// Fourth Name string array

		// Get the number of test scores
		JOptionPane.showInputDialog("How many test scores do you have? ");

		// Get the names of the students
		JOptionPane.showInputDialog("Please enter the student's name ");

		// Create an array to hold the test scores
		double[] scores = new double[numScores];

		// Create an array to hold the names of the students
		String[] names = new String[studNames];

		// Get the test scores and store them in the scores array
		for (int index = 0; index < numScores; index++)
		{	// Begin for loop
			System.out.println("Enter score" +
								(index + 1) + ": ");
		}	// End for loop

		// Create a Grades object, passing the scores array as an argument to the constructor
		Grades myGrades = new Grades(scores);

		// Display the average of the test scores
		JOptionPane.showMessageDialog("Your test score average is " +
									   myGrades.getAverage());

	}	// End public static void main(String[] args)

}	// End public class calcAverage

You have the words "end if statement" in three different places so that isn't very helpful. You've stated that the error is at line 160 but you only posted 130 lines of code. Post your errors and be specific about which lines of code they are at.

Here is exactly what I have for my program thus far. Above, I did not include the introductory comment section for each part.

/*
Name:			Heather Andrews

Program:		calcAverage.java

Date:			April 24, 2010

Description:	A teacher has five students who have taken four tests.
				The teacher uses the following grading scale to assign
				a letter grade to a student, based on the average of his
				or her four test scores:

					Test Score			Letter Grade
		  				90-100			         A
		  				80-89				     B
		  				70-79				     C
		  				60-69				     D
		 				 0-59				     F

				Write a class that uses a string array or an ArrayList
				object to hold the five students' names, an array of
				five characters to hold the five students' letter grades,
				and five arrays of four doubles each to hold each student's
				set of test scores.  The class should have methods that
				return a specific student's name, average test score, and a
				letter grade based on the average.

				Demonstrate the class in a program that allows the user to
				enter each student's name and his or her four test scores.
				It should then display each student's average test score and
				letter grade.

				Input validation:  Do not accpet test scores less than zero
				or greater than 100.
*/

import java.text.DecimalFormat;		// Needed to format test score average
import javax.swing.JOptionPane;		// Needed for showInputDialog & showMessageDialog

public class calcAverage
{	// Begin public class calcAverage
	static DecimalFormat formatter = new DecimalFormat("###.##");	// Global decimal formatter

	public static void main(String[] args)
	{	// Begin public static void main(String[] args)

		int numScores;						// To hold the number of scores
		String studNames;					// To hold the names of the students
		String[] strings = new String[5]; 	// Array of 5 strings
		String[0] = " "; 					// First Name string array
		String[1] = " ";					// Second Name string array
		String[2] = " ";					// Third Name string array
		String[3] = " ";					// Fourth Name string array

		// Get the number of test scores
		JOptionPane.showInputDialog("How many test scores do you have? ");

		// Get the names of the students
		JOptionPane.showInputDialog("Please enter the student's name ");

		// Create an array to hold the test scores
		double[] scores = new double[numScores];

		// Create an array to hold the names of the students
		String[] names = new String[studNames];

		// Get the test scores and store them in the scores array
		for (int index = 0; index < numScores; index++)
		{	// Begin for loop
			System.out.println("Enter score" +
								(index + 1) + ": ");
		}	// End for loop

		// Create a Grades object, passing the scores array as an argument to the constructor
		Grades myGrades = new Grades(scores);

		// Display the average of the test scores
		JOptionPane.showMessageDialog("Your test score average is " +
									   myGrades.getAverage());

	}	// End public static void main(String[] args)

}	// End public class calcAverage
/**
Name:			Heather Andrews

Program:		calcAverage.java

Date:			April 24, 2010

Description:	A teacher has five students who have taken four tests.
				The teacher uses the following grading scale to assign
				a letter grade to a student, based on the average of his
				or her four test scores:

					Test Score			Letter Grade
		  				90-100			         A
		  				80-89				     B
		  				70-79				     C
		  				60-69				     D
		 				 0-59				     F

				Write a class that uses a string array or an ArrayList
				object to hold the five students' names, an array of
				five characters to hold the five students' letter grades,
				and five arrays of four doubles each to hold each student's
				set of test scores.  The class should have methods that
				return a specific student's name, average test score, and a
				letter grade based on the average.

				Demonstrate the class in a program that allows the user to
				enter each student's name and his or her four test scores.
				It should then display each student's average test score and
				letter grade.

				Input validation:  Do not accpet test scores less than zero
				or greater than 100.
*/

public class Grades
{	// Begin public class Grades

	private double[] testScores;	// Variable that will ref an array of test scores

	/**
		Constructor
		@param scoreArray An array of test scores
	*/ 	public Grades(double[] scoreArray)

	{	// Assign the array argument to the testScores field
	testScores = scoreArray;
	}

	/**
		getAverage method
		@return The average of the test scores
	*/ 	public double getAverage()

	{	// Begin public double getAverage()

	double total = 0;	// To hold the score total
	double average;		// To hold the average

	// If array contains less than 4 test scores, display error message and set
	// average to 0
	if (testScores.length < 4)
	{	// Begin if statement
	System.out.println("Error: You must have atleast " +
				"four test scores!");

	average = 0;
	}	// End if statement
	else
	{	// Begin else statement
	// Calculate total of the scores
	for (double score : testScores)

	total += score;			// Get the average of the scores
	average = total / (testScores.length - 1);
	}	// End else statement

	// Return the average of the test scores
	return average;

	}	// End public double getAverage()

}	// End public class Grades


	private double[] testScores;	// Variable that will ref an array of test scores

	/**
		Constructor
		@param scoreArray An array of test scores
	*/

	public Grades(double[] scoreArray)
	{	// Assign the array argument to the testScores field
		testScores = scoreArray;
	}

	/**
		getAverage method
		@return The average of the test scores
	*/

	public double getAverage()
	{	// Begin public double getAverage()
		double total = 0;	// To hold the score total
		double average;		// To hold the average

		// If array contains less than 4 test scores, display error message and set
		// average to 0
		if (testScores.length < 4)
		{	// Begin if statement
			JOptionPane.showMessageDialog("Error: You must have atleast " +
											"four test scores!");
			average = 0;
		}	// End if statement
		else
		{	// Begin else statement
			// Calculate total of the scores
			for (double score : testScores)
				total += score;
			// Get the average of the scores
			average = total / (testScores.length - 1);
		}	// End else statement

		// Return the average of the test scores
		return average;

	}	// End public double getAverage()



	private String[] studNames;		// Variable that will ref an array of student names

		/**
			Constructor
			@param namesArray An array of student names
		*/

		public Grades(String[] namesArray)
		{	// Assign the array argument to the studNames field
			studNames = namesArray;
		}

		/**
			getNames method
			@return The names of the students

		*/

		public String getNames()
		{	// Begin public String getNames()
			String names;		// To hold the student names

			// If array contains less than 5 students, display error message
			if (studNames.length < 5)
			{	// Begin if statement
				JOptionPane.showMessageDialog("Error: You must have atleast " +
									"five student names!");
			}	// End if statement

			// Return the student names
			return names;

	}	// End public double getstudNames()

}	// End public class Grades

When I try to run the programs, I am getting an error message referring to multiple lines of the code stating "class, interface, or enum expected". One of the places I am receiving it is at line 160.

You seem to have the wrong number of closing brackets. You should have one opening bracket for each closing bracket, and it looks like (at first glance) that you never close the getNames() method. Your indentation makes it hard to count, though. Opening and closing brackets should line up, and where you have control structures (for/while loops, if statements, etc) they should look something like this:

if (something)
{
    thisMethodIsIndented();
    thisVariableAssignmentIsIndented = 1 + 1;
}

whereas yours in certain places looks like this, which makes it harder to see errors and read the code:

if (something)
{
thisMethodIsIndented();
thisVariableAssignmentIsIndented = 1 + 1;
}

I double checked my brackets and there is an opening and closing for each.

Doesn't matter, you should still use proper formatting so that it doesn't waste your time (when you're looking for errors) and my time when I'm trying to help you.

Anyway, in the code you posted above, you declared the same variable "testScores" multiple times and you declared the Grades constructor and the getAverage() method multiple times also.

The code without duplicate variable and method declarations is as follows. You should note that your code still has several syntactical and logical errors. For example, in your getNames() method, there is a syntax error because you are calling the showMessageDialog() method with only one argument, but it can only be called with either 2 or 3 arguments. You should look online to learn how to use that method properly. You have a logical error in your getNames() method because you have declared a variable "names" but you never initialized it to anything. So your return statement is returning null. I don't know what you wanted your getNames() method to do because your comments are pretty useless. A good comment would be something like "The get names method check the studNames array to make sure it has at least 5 names in it, and if it does not, then the method prompts the user to enter more names until studNames has 5 names. getNames() then returns this array of studNames". You should also note that getWhatever() is usually reserved in Java as a name meaning return the variable "whatever" and setWhatever(somethingElse) is usually reserved to change the value of "whatever" to "somethingElse". So using getNames as the title of a method that prompts the user and does other word is slightly confusing. A more descriptive method title and a method comment to explain the overall goal of the method would go a long way. Your comment "If array contains less than 5 students, display error message" is a good comment. Comments like "to hold the student names", "Begin if statement", "return the student names" - are all examples of useless comments that make it harder to understand your code. (I understand if you were only putting them there to help yourself learn, this is general advice - you should never put that kind of stuff in code you hand in for grading).

package other;

import javax.swing.JOptionPane;


public class Grades
{	
	private double[] testScores;

	/**
		Constructor
		@param scoreArray An array of test scores
	*/

	public Grades(double[] scoreArray)
	{	
		testScores = scoreArray;
	}

	/**
		getAverage method
		@return The average of the test scores
	*/

	public double getAverage()
	{	
		double total = 0;	// To hold the score total
		double average;		// To hold the average

		// If array contains less than 4 test scores, display error message and set
		// average to 0
		if (testScores.length < 4)
		{	// Begin if statement
			JOptionPane.showMessageDialog("Error: You must have atleast " +
											"four test scores!");
			average = 0;
		}	
		else
		{	
			// Calculate total of the scores
			for (double score : testScores)
				total += score;
			
			// Get the average of the scores
			average = total / (testScores.length - 1);
		}	
		
		return average;

	}	



	private String[] studNames;		// Variable that will ref an array of student names

		/**
			Constructor
			@param namesArray An array of student names
		*/

		public Grades(String[] namesArray)
		{	
			studNames = namesArray;
		}

		/**
			getNames method
			@return The names of the students

		*/

		public String getNames()
		{	
			String names;		

			// If array contains less than 5 students, display error message
			if (studNames.length < 5)
			{	
				JOptionPane.showMessageDialog("Error: You must have atleast " +
									"five student names!");
			}	

			return names;

	}	

}

I put the comments in there because that is what is shown on handouts by the instructor to do. This may be something that changes in the advanced java course next semester, but as of right now we are instructed to put that in there so someone can figure out exactly what is going on every step of the way.

For the getNames() I am trying to create a constructor to get the names of the 5 students that the teacher may enter. What is the correct way to do this?

For the getNames() I am trying to create a constructor to get the names of the 5 students that the teacher may enter. What is the correct way to do this?

It depends how the teacher has said she wants to be able to input the names. If the teacher wants to type in the names in a GUI, then you can use the JOptionPane method showInputDialog. If the teacher wants to be able to enter the names at the command line then you can use System.out.println("Enter the name"); and use the Scanner class to read in the name.

I revised the programs to as follows and when I try to run the program, it is not calculating an average after I enter in the test scores. What am I missing?

import java.text.DecimalFormat;		// Needed to format test score average
import javax.swing.JOptionPane;		// Needed for showInputDialog & showMessageDialog

public class calcAverage
{	// Begin public class calcAverage
	static DecimalFormat formatter = new DecimalFormat("###.##");	// Global decimal formatter

	public static void main(String[] args)
	{	// Begin public static void main(String[] args)

		final int STUDENTS = 5;				// Number of students
		int numScores = 4;					// To hold number of scores
		String studNames;					// To hold the names of the students
		String[] names = new String[5]; 	// Array of 5 strings

		// enter for loop here to have it go through 5 students with 4 test scores
		for (int index = 0; index < STUDENTS; index++)
		//{	// Begin for loop
		// Get the names of the students
		JOptionPane.showInputDialog("Please enter the student's name. ");

		// Create an array to hold the test scores
		double[] scores = new double[numScores];

		// Get the test scores and store them in the scores array
		for (int index = 0; index < numScores; index++)
		{	// Begin for loop
			JOptionPane.showInputDialog("Enter score" +
								    (index + 1) + ": ");
		}	// End for loop

		//}	// End for loop that was used for going through 5 students with 4 test scores

		// Create a Grades object, passing the scores array as an argument to the constructor
		Grades myGrades = new Grades(scores);

		// Display the average of the test scores
		JOptionPane.showMessageDialog(null,
							"Your test score average is\n" +
									   myGrades.getAverage());

	}	// End public static void main(String[] args)

}	// End public class calcAverage
public class Grades
{	// Begin public class Grades

	private double[] testScores;	// Variable that will ref an array of test scores

	/**
		Constructor
		@param scoreArray An array of test scores
	*/ 	public Grades(double[] scoreArray)

	{	// Assign the array argument to the testScores field
	testScores = scoreArray;
	}

	/**
		getAverage method
		@return The average of the test scores
	*/ 	public double getAverage()

	{	// Begin public double getAverage()

	double total = 0;	// To hold the score total
	double average;		// To hold the average

	// If array contains less than 4 test scores, display error message and set
	// average to 0
	if (testScores.length < 4)
	{	// Begin if statement
	System.out.println("Error: You must have atleast " +
				"four test scores!");

	average = 0;
	}	// End if statement
	else
	{	// Begin else statement
	// Calculate total of the scores
	for (double score : testScores)

	total += score;			// Get the average of the scores
	average = total / (testScores.length - 1);
	}	// End else statement

	// Return the average of the test scores
	return average;

	}	// End public double getAverage()

}	// End public class Grades

I have faced some class which deals with smth. identical to your task. So I modified that class to meet your requirements and came with the following class. You can create an object-instance of this class and use in your program

/***************************************************************************
 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


public class StudentInfo{

	private static class StudentEntry{

		String name;
		double grade0, grade1, grade2, grade3;
		
		public char getLetterGrade(){
			double averageGrade=(grade0+grade1+grade2+grade3)/4;
			if(averageGrade>=90 && averageGrade<=100)
				return 'A';
			else if(averageGrade>=80 && averageGrade<=89)
				return 'B';
			else if(averageGrade>=70 && averageGrade<=79)
				return 'C';
			else if(averageGrade>=60 && averageGrade<=69)
				return 'D';
			else if(averageGrade>=0 && averageGrade<=59)
				return 'F';
			else
				return 'r';
	}
	}//end class StudentEntry

	private StudentEntry[] data;
	private int dataCount;

	public StudentInfo(){
		data=new StudentEntry[1];
		dataCount=0;
	}//end constructor

	private int find(String name){
		for(int i=0; i<dataCount; i++){
			if(data[i].name.equals(name))
				return i;
		}
		return -1;
	}
	public double getAverageGrade(String name){
		int position=find(name);
		if(position==-1)
			return -1;
		else
			return (data[position].grade0+data[position].grade1+data[position].grade2+data[position].grade3)/4;
	}



	public void putGrades(String name, double g0, double g1, double g2, double g3){
		if(name==null || g0==-1 || g1==-1 || g2==-1 || g3==-1)
			throw new IllegalArgumentException("Name and grades cannot be empty");
		if((g0<0||g0>100)&&(g1<0||g1>100)&&(g2<0||g2>100)&&(g3<0||g3>100))
			throw new IllegalArgumentException("Grades must be in the range from 0 to 100");
		int i=find(name);
		if(i>=0){
		//the name already exists, replace the old grades
			data[i].grade0=g0;
			data[i].grade1=g1;
			data[i].grade2=g2;
			data[i].grade3=g3;
		}
		else{
			//add a new name/grades to the array. If the array is already full create a larger one
			if(dataCount==data.length){
				StudentEntry[] newData=new StudentEntry[2*data.length];
				System.arraycopy(newData, 0, data, 0, dataCount);
				data=newData;
			}
			StudentEntry newEntry=new StudentEntry(); //create a new set of student info
			newEntry.name=name;
			newEntry.grade0=g0;
			newEntry.grade1=g1;
			newEntry.grade2=g2;
			newEntry.grade3=g3;
			data[dataCount]=newEntry;
			dataCount++;

		}
	}
}//end class StudentInfo
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.