Good Morning, Having all kinds of problems with my programs. Seems as though is trying to read the StudentList file but cant. Im confused. I run the program and it goes to the StudentList.java and gives the errors below after the code. PLEASE HELP! project is past due and the final day before i receive a zero is by 10am Mod=nday. I have also attached the assignment for you to get an understanding of what i am doing.

import java.util.*; 
import java.io.*; 
import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*; 

public class SuperProject extends JFrame 
{ 
   private static final int WIDTH = 550; 
   private static final int HEIGHT = 430; 
   int gradeCalc; 
   int Student; 
   private StudentList[] sList = new StudentList[20]; 
   private static final int MAX_NUMBER_OF_STUDENTS = 20; 

// instance variables 
   private int noOfStudents; 
   private double score, tst1, tst2, tst3; 
   private double classAvg, stAvg, totalScore; 
   private int displayedStudentIndex = 0; 
   private char ltrGrade; 
   private String stName; 

// This area is for the GUI components 
// Each item that will be displayed will 
// have a label and a textfield, (L) and (TF), 
// respectively. 
   private JLabel stNameL, tst1L, tst2L, tst3L, 
   classAvgL, stAvgL, headingL; 
   private JTextField stNameTF, tst1TF, tst2TF, tst3TF; 
   private JTextArea classAvgTA, stAvgTA; 
   private JButton exitB, nextB, prevB, calcGrade; 
   private ButtonHandler bHandler; 

   public SuperProject() 
   { 
      setTitle("Grade Calculator");       // set's the title 
      setSize(WIDTH, HEIGHT);               // set the window size 
      Container pane = getContentPane(); // get the container 
      pane.setLayout(null);                   // set the container's layout to null 
      bHandler = new ButtonHandler();    // instantiate the button event handler 

   // instantiate the labels 
      headingL = new JLabel("STUDENT RECORD"); 
      stNameL = new JLabel("Student Name", SwingConstants.RIGHT); 
      tst1L = new JLabel("Test 1", SwingConstants.LEFT); 
      tst2L = new JLabel("Test 2", SwingConstants.LEFT); 
      tst3L = new JLabel("Test 3", SwingConstants.LEFT); 
      stAvgL = new JLabel("Student Average " 
         + "\n" + "Class Average"); 

   //instantiate the text fields 
      stNameTF = new JTextField(65); 
      tst1TF = new JTextField(10); 
      tst2TF = new JTextField(10); 
      tst3TF = new JTextField(10); 

   // instantiate the text area 
      classAvgTA = new JTextArea(6, 20); 
      classAvgTA.setAutoscrolls(true); 
   // instantiate the buttons and register the listener 
      exitB = new JButton("Exit"); 
      exitB.addActionListener(bHandler); 
      nextB = new JButton("Next"); 
      nextB.addActionListener(bHandler); 
      prevB = new JButton("Previous"); 
      prevB.addActionListener(bHandler); 
      calcGrade = new JButton("Calc Grade"); 
      calcGrade.addActionListener(bHandler); 
   // set the size of the labels, text fields, and buttons 
      headingL.setSize(200, 30); 
      stNameL.setSize(100, 30); 
      stNameTF.setSize(100, 30); 
      tst1L.setSize(100, 30); 
      tst1TF.setSize(100, 30); 
      tst2L.setSize(120, 30); 
      tst2TF.setSize(100, 30); 
      tst3L.setSize(100, 30); 
      tst3TF.setSize(100, 30); 
      classAvgTA.setSize(370, 120); 
      calcGrade.setSize(100, 30); 
      prevB.setSize(100, 30); 
      nextB.setSize(100, 30); 
      exitB.setSize(100, 30); 

   //set the location of the labels, text fields, 
   //and buttons 
      headingL.setLocation(220, 10); 
      stNameL.setLocation(20, 50); 
      stNameTF.setLocation(120, 50); 
      tst1L.setLocation(20, 100); 
      tst1TF.setLocation(120, 100); 
      tst2L.setLocation(300, 50); 
      tst2TF.setLocation(420, 50); 
      tst3L.setLocation(300, 100); 
      tst3TF.setLocation(420, 100); 
      classAvgTA.setLocation(70, 230); 
      prevB.setLocation(120, 370); 
      exitB.setLocation(220, 370); 
      nextB.setLocation(320, 370); 
      calcGrade.setLocation(420, 370);

   //add the labels, text fields, and buttons to the pane 
      pane.add(headingL); 
      pane.add(stNameL); 
      pane.add(stNameTF); 
      pane.add(tst1L); 
      pane.add(tst1TF); 
      pane.add(tst2L); 
      pane.add(tst2TF); 
      pane.add(tst3L); 
      pane.add(classAvgTA); 
      pane.add(calcGrade); 
      pane.add(prevB); 
      pane.add(exitB); 
      pane.add(nextB); 
      setVisible(true); //show the window 
      setDefaultCloseOperation(EXIT_ON_CLOSE); 
      System.exit(0); 
   } 

      private class ButtonHandler implements ActionListener 
   { 
           public void actionPerformed (ActionEvent e)  
          {  
             if (e.getActionCommand().equals("Previous"))  
                if (displayedStudentIndex > 0)  
                   displayGradeAverage(displayedStudentIndex - 1);  
                else  
                   displayGradeAverage(displayedStudentIndex);  
             else if (e.getActionCommand().equals("Next"))  
                if (displayedStudentIndex + 1 < noOfStudents)  
                   displayGradeAverage(displayedStudentIndex + 1);  
                else  
                   displayGradeAverage(displayedStudentIndex);  
             else if (e.getActionCommand().equals("Calc Grade"))  
                displayGradeAverage(0);  
             else  
                System.exit(0);  
          }  

   public static void main (String [] args) 
   { 
      new SuperProject(); 
   } 

   Scanner inFile = 
   new Scanner(new FileReader("AcademicGrades.txt")); 
   { 
      for (int s = 0; s < MAX_NUMBER_OF_STUDENTS; s++) 
         gradeCalc.StudentList[s] = new Student(); 
      gradeCalc.noOfStudents = 
         inFile.nextInt();     // get the number of students 
      gradeCalc.score = 
         inFile.nextDouble(); // get the student's scores 
      gradeCalc.getStudentData(inFile); 
      gradeCalc.displayGradeAverage(0); 
   } 

// get the student data from file 
   public void getStudentData(Scanner inFile) 
   { 
      System.out.println("Grade Calculator is getting information..."); 
      System.out.println("One Moment Please"); 
   } 


        public void displayGradeAverage(int stName)  
       {  
          displayedStudentIndex = stName;  
          String strName = "";  
          boolean classAvg = studentList[(int) (totalScore / noOfStudents)].getClassAverage();  
          stNameTF.setText(StudentList[stName].getFirstName() + " "  
                                                             + studentList[stName].getLastName()); 
          stAvgTA.setText(""+StudentList[(int) (totalScore / 3.0)].getStudentAverage()); 
          classAvgTA.setText(""+StudentList[(int) (totalScore / noOfStudents)].getClassAverage()); } 
        } 
     }

Errors
----jGRASP exec: javac -g SuperProject.java

StudentList.java:5: class GradeCalculator3 is public, should be declared in a file named GradeCalculator3.java
public class GradeCalculator3 extends JFrame
^
SuperProject.java:13: cannot access StudentList
bad class file: .\StudentList.java
file does not contain class StudentList
Please remove or make sure it appears in the correct subdirectory of the classpath.
private StudentList[] sList = new StudentList[20];
^

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

class GradeCalculator3 is public, should be declared in a file named GradeCalculator3.java

What exactly about that do you not understand?

How can I correct it?

You must put the declaration of the public class GradeCalculator3 in a file called GradeCalculator3.java, just like it says.
The java compiler requires that every public top-level class is declared in a .java file whose name is the same as the name of the class. Therefore, you cannot put two top-level public classes in the same .java file

I have done that many times and it does the same thing. When I compile SuperProject it opens the GradeCalculator3 gives the declaration error. I save the file as GradeCalculator3 and it does the same thing when I compile SuperProject again.

Did you delete the old (incorrectly named) file?
The error message says it finds the declaration of that class in a file called StudentList.java, on line 5.

You mean delet GradeCalculator3.

You must have exactly one declaration of the class GradeCalculator3 and that must be in a file called GradeCalculator3.java. Delete all other declarations of GradeCalculator3

ok i deleted it now im getting all these errors: I think a need to create a StudentList class

-jGRASP exec: javac -g SuperProject.java

SuperProject.java:13: cannot find symbol
symbol : class StudentList
location: class SuperProject
private StudentList[] sList = new StudentList[20];
^
SuperProject.java:13: cannot find symbol
symbol : class StudentList
location: class SuperProject
private StudentList[] sList = new StudentList[20];
^
SuperProject.java:144: inner classes cannot have static declarations
public static void main (String [] args)
^
SuperProject.java:153: int cannot be dereferenced
gradeCalc.StudentList[s] = new Student();
^
SuperProject.java:153: cannot find symbol
symbol : class Student
location: class SuperProject.ButtonHandler
gradeCalc.StudentList[s] = new Student();
^
SuperProject.java:154: int cannot be dereferenced
gradeCalc.noOfStudents =
^
SuperProject.java:156: int cannot be dereferenced
gradeCalc.score =
^
SuperProject.java:158: int cannot be dereferenced
gradeCalc.getStudentData(inFile);
^
SuperProject.java:159: int cannot be dereferenced
gradeCalc.displayGradeAverage(0);
^
SuperProject.java:174: cannot find symbol
symbol : variable studentList
location: class SuperProject.ButtonHandler
boolean classAvg = studentList[(int) (totalScore / noOfStudents)].getClassAverage();
^
SuperProject.java:175: cannot find symbol
symbol : variable StudentList
location: class SuperProject.ButtonHandler
stNameTF.setText(StudentList[stName].getFirstName() + " "
^
SuperProject.java:176: cannot find symbol
symbol : variable studentList
location: class SuperProject.ButtonHandler
+ studentList[stName].getLastName());
^
SuperProject.java:177: cannot find symbol
symbol : variable StudentList
location: class SuperProject.ButtonHandler
stAvgTA.setText(""+StudentList[(int) (totalScore / 3.0)].getStudentAverage());
^
SuperProject.java:178: cannot find symbol
symbol : variable StudentList
location: class SuperProject.ButtonHandler
classAvgTA.setText(""+StudentList[(int) (totalScore / noOfStudents)].getClassAverage()); }
^
14 errors

Your program refers to a StudentList class, so yes, you must have one. I hope you didn't delete it while fixing the GradeCalculator3 problem!

lol I hate deleting stuff. I do believe i did! Oh wow now i have to create another one. This is starting to get very confusing and frustrating.

Just look in the recycle bin.

I know this is the basic for the class but can someone help me with this I have to go to my son's game and will be back aroung 4pm.

class {

2 method 1 {

3 }

4 method 2 {

5 }

6 ...

7 method n {

8 }

9 }


Objective
1. Need a class which will contain:
a. Student Name
b. Student Grades (an array of 3 grades)
c. A constructor that clears the student data (use -1 for unset grades)
d. Accessors (get functions) for each of the above, average, and letter grade
e. Mutators (set functions) for items a, b, c
f. Note that the accessor and mutator for Student grades has to have an argument for the grade index.
2. Need another class which will contain:
a. An Array of Students (1 above)
b. A count of number of students in use
c. Constructor that reads data from a text file and sets up the students

Member Avatar for coil

Just a review of the basic structure of a class - I think this is where you're having the most problems:

class Test { //You can call it whatever you want
	private int id; //Declare all variables here
	
	public Test(int i) { //This is a constructor that takes an int as an argument
		id=i;
		//Do anything else you want
	}
	public Test() { //A default constructor with no arguments - optional
		id=1; 
	}
	//Any other constructors
	
	public int getID() { return id; } //Accessor method
	
	public void setID(int i) { //Mutator method
		id=i;	
	}

	//Any other methods
}

so basically i just put everthing that I have now in the StudentClass?

Member Avatar for coil

Sort of, but not exactly.

You put everything that's needed to define a Student into the class. Your Student class should contain stuff like ID, name, grades, and so on, because every student has one of those. Your Student class should also contain methods related to those, like accessors and mutators.

However, stuff like initializing Students, having Students interact with other Students, etc. shouldn't go in the Student class.

can u help me I have been on this project all night. Its due tomorrow by 10am. I have done everything seen all kinds of code and my mind is twisted and tired now. If i could just get it to compile I wont be deducted 20 points.

Create a program to enter grades and calculate averages and letter grades.

  1. Need a class which will contain:
    a. Student Name
    b. Student Grades (an array of 3 grades)
    c. A constructor that clears the student data (use -1 for unset grades)
    d. Accessors (get functions) for each of the above, average, and letter grade
    e. Mutators (set functions) for items a, b, c
    f. Note that the accessor and mutator for Student grades has to have an argument for the grade index.
  2. Need another class which will contain:
    a. An Array of Students (1 above)
    b. A count of number of students in use
    c. Constructor that reads data from a text file and sets up the students
  3. You need to create a graphical user interface that allows you to:
    a. Read data from file
    b. Add new students
    c. Process existing students
    d. Add test grades
    e. Based on a radio button setting display either the average or the letter grade
    f. Save modified data to file
  4. A possible graphical look is as follows:
  5. Add comments and use proper indentation.

NOTE: You need actionCommand to handle saving a file and you cannot modify actionCommand with a “throws IOException” clause. The way to solve this is as follows:
Assuming that you have a method called saveData that saves the data, change its call as follows:

try 
{   saveData();
} catch (IOException x)
{
}

The function saveData, your function to load data, and the constructor will need a “throws IOException” clause.
Additional Information:

  • An accessor is needed to save the test grades, which should always be numbers.
  • I would like that system to accept a student with no grades, then later add one or more grades, and when all grades are entered, calculate the final average or grade.
  • The way to handle changes in data using a text file is:
  • Open the data file for reading
  • load all the data into an array of students from the file,
  • Close the file
  • Make all modifications to the data in the array of students.
  • When saving, open the datafile for writing
  • Loop through the students and save the data to the datafile.
  • Close the data file.

My program that I have is already posted with the errors.

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.