I am having a problem getting my program to compile. I recieve the identifier error coming from my array. -
public class GradeCalculator extends JFrame
-
{
-
private static final int WIDTH = 550;
-
private static final int HEIGHT = 430;
-
int gradeCalc;
-
int Student;
-
private StudentList[] = new StudentList [20];
-
private static final int MAX_NUMBER_OF_STUDENTS = 20;
-
11 1989
You haven't named your StudentList array. Really common mistake; I do it all the time.
when i name it:
private StudentList[] sList= new StudentList [20];
I get 13 errors instead of the one error i am having:
GradeCalculator.java:13: cannot find symbol
symbol : class StudentList
location: class GradeCalculator
private StudentList[] sList = new StudentList[20];
^
GradeCalculator.java:13: cannot find symbol
symbol : class StudentList
location: class GradeCalculator
private StudentList[] sList = new StudentList[20];
^
GradeCalculator.java:143: int cannot be dereferenced
gradeCalc.StudentList[s] = new Student();
^
GradeCalculator.java:143: cannot find symbol
symbol : class Student
location: class GradeCalculator
gradeCalc.StudentList[s] = new Student();
^
GradeCalculator.java:145: int cannot be dereferenced
gradeCalc.noOfStudents =
^
GradeCalculator.java:147: int cannot be dereferenced
gradeCalc.score =
^
GradeCalculator.java:150: int cannot be dereferenced
gradeCalc.getStudentData(inFile);
^
GradeCalculator.java:151: int cannot be dereferenced
gradeCalc.displayGradeAverage(0);
^
GradeCalculator.java:187: cannot find symbol
symbol : variable studentList
location: class GradeCalculator
boolean classAvg = studentList[(int) (totalScore / noOfStudents)].getClassAverage();
^
GradeCalculator.java:188: cannot find symbol
symbol : variable StudentList
location: class GradeCalculator
stNameTF.setText(StudentList[stName].getFirstName() + " "
^
GradeCalculator.java:189: cannot find symbol
symbol : variable studentList
location: class GradeCalculator
+ studentList[stName].getLastName());
^
GradeCalculator.java:190: cannot find symbol
symbol : variable StudentList
location: class GradeCalculator
stAvgTA.setText(""+StudentList[(int) (totalScore / 5.0)].getStudentAverage());
^
GradeCalculator.java:191: cannot find symbol
symbol : variable StudentList
location: class GradeCalculator
classAvgTA.setText(""+StudentList[(int) (totalScore / noOfStudents)].getClassAverage()); }
^
13 errors
So this is supposed to be an integer array? eg
private int StudentList [] = new int [20];
or is it an array of students?
private Student StudentList[] = new Student[20];
the project just specifies:
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
this is my program: -
import java.util.*;
-
import java.io.*;
-
import javax.swing.*;
-
import java.awt.*;
-
import java.awt.event.*;
-
-
public class GradeCalculator 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 GradeCalculator()
-
{
-
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);
-
}
-
-
-
-
public static void main (String [] args)
-
{
-
new GradeCalculator();
-
}
-
-
-
-
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");
-
}
-
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 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 / 5.0)].getStudentAverage());
-
classAvgTA.setText(""+StudentList[(int) (totalScore / noOfStudents)].getClassAverage()); }
-
}
-
Where is your class for 1.? -
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.
-
ok i did that: -
import java.util.*;
-
import java.io.*;
-
import javax.swing.*;
-
import java.awt.*;
-
import java.awt.event.*;
-
-
-
public class StudentList
-
{
-
String name; // Student's name.
-
double test1, test2, test3; // Grades on three tests.
-
double getAverage() { // compute average test grade
-
return (test1 + test2 + test3) / 3;
-
}
-
}
-
-
-
public class GradeCalculator extends JFrame
-
{
-
private static final int WIDTH = 550;
-
private static final int HEIGHT = 430;
-
int gradeCalc;
-
int student;
-
private StudentList[] sList = new StudentList[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 GradeCalculator()
-
{
-
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);
-
}
-
-
-
public static void main (String [] args)
-
{
-
new GradeCalculator();
-
}
-
-
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");
-
}
-
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 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()); }
-
}
-
then i get these error i think its because it illegal but dont know how to fix it.
Errors:
StudentList.java:18: class GradeCalculator is public, should be declared in a file named GradeCalculator.java
public class GradeCalculator extends JFrame
^
StudentList.java:150: cannot find symbol
symbol : variable MAX_NUMBER_OF_STUDENTS
location: class GradeCalculator
for (int s = 0; s < MAX_NUMBER_OF_STUDENTS; s++)
^
StudentList.java:151: int cannot be dereferenced
gradeCalc.StudentList[s] = new Student();
^
StudentList.java:151: cannot find symbol
symbol : class Student
location: class GradeCalculator
gradeCalc.StudentList[s] = new Student();
^
StudentList.java:153: int cannot be dereferenced
gradeCalc.noOfStudents =
^
StudentList.java:155: int cannot be dereferenced
gradeCalc.score =
^
StudentList.java:158: int cannot be dereferenced
gradeCalc.getStudentData(inFile);
^
StudentList.java:159: int cannot be dereferenced
gradeCalc.displayGradeAverage(0);
^
StudentList.java:194: cannot find symbol
symbol : variable StudentList
location: class GradeCalculator
boolean classAvg = StudentList[(int) (totalScore / noOfStudents)].getClassAverage();
^
StudentList.java:195: cannot find symbol
symbol : variable StudentList
location: class GradeCalculator
stNameTF.setText(StudentList[stName].getFirstName() + " "
^
StudentList.java:196: cannot find symbol
symbol : variable StudentList
location: class GradeCalculator
+ StudentList[stName].getLastName());
^
StudentList.java:197: cannot find symbol
symbol : variable StudentList
location: class GradeCalculator
stAvgTA.setText(""+StudentList[(int) (totalScore / 3.0)].getStudentAverage());
^
StudentList.java:198: cannot find symbol
symbol : variable StudentList
location: class GradeCalculator
classAvgTA.setText(""+StudentList[(int) (totalScore / noOfStudents)].getClassAverage()); }
^
13 errors
I would like to know how can I use the stringValueOf to remove this error:
double cannot be dereferenced
gradeCalc.noOfStudents = inFile.nextInt(); // get the number of Students
^
edit reply report
What is the variable gradeCalc supposed to represent?
Shouldn't it just be
noOfStudents = inFile.nextInt();
?
It looks like you're treating gradeCalc as a GradeCalculator object, when you've declared it as a non-static int.
Are you using any IDE's? IDE's generally highlight the errors.
Regards
Dheeraj Joshi
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steffen Peters |
last post by:
Hi All,
is there any possibility to get php-mail() working without recompile
php? Im using PHP4.3.3 on a solaris 5.8 box and compiled php without
installed sendmail. Now sendmail is in use but...
|
by: ruud |
last post by:
I am rewriting my Except script from bash to Perl.
But i get an syntax error at the Send command.
Google is not helping me out here, so i hope for an answer here.
Here is a part of the script:
...
|
by: Mak |
last post by:
Hi Everybody,
I try set the Expect: 100-continue in my request to server. The way I
do it is by setting :
<META http-equiv="Expect" content="100-continue">
in my html page. But, it does not...
|
by: sunadmn |
last post by:
Hey all I have installed the PECL expect module and for the life of me I
can get it to work. Below is a sample script I am running and the error
message I am recieving.
<?php
ini_set...
|
by: GrispernMix |
last post by:
bool variant_t::Convert( fieldtype_t newType )
{
if ( newType == fieldType )
{
return true;
}
//
// Converting to a null value is easy.
//
|
by: p175 |
last post by:
I just installed Express C and am getting the following messag
erepeated every three minutes, can someone please advise or help figure
out what this is.
Cheers,
2006-08-09-10.58.17.218000-240...
|
by: graphman |
last post by:
I have a perl script that I'm calling using php's shell_exec that uses
an expect module to go to another system to pull tiff files. The php
perl combination works great when I launch from the...
|
by: jeffc226 |
last post by:
I'm interested in an idiom for handling errors in functions without
using traditional nested ifs, because I think that can be very awkward
and difficult to maintain, when the number of error checks...
|
by: mike3 |
last post by:
Hi.
(crossposted because the program is in C++ and some C++-related
elements are discussed, hence comp.lang.c++, plus general program
design questions are asked, hence comp.programming.)
I'm...
|
by: yohanus |
last post by:
im haveing problems with the following piece of code
in getting an error durring compilling which says
error c2065; 'arraySize' : undeclared identifier line 54
error c2065: 'anArray' :...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |