Grade Calculator Problems

• (4 Pages)
• 1
• 2
• 3
• Last »

57 Replies - 3022 Views - Last Post: 07 June 2010 - 03:14 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=176504&amp;s=425949adc908c89243bf84ca1d4dd846&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 blknmld69

• D.I.C Head

Reputation: -5
• Posts: 102
• Joined: 28-November 09

Grade Calculator Problems

Posted 03 June 2010 - 09:49 AM

Im working on the same assignment. I am coming up with 19 errors.........This is a challenge and I have been working on it all day......Please someone get me started!
GradeCalculator.java:152: class, interface, or enum expected
public static void main (String [] args)
^
GradeCalculator.java:155: class, interface, or enum expected
}
^
GradeCalculator.java:161: class, interface, or enum expected
for (int s = 0; s < MAX_NUMBER_OF_STUDENTS; s++)
^
GradeCalculator.java:161: class, interface, or enum expected
for (int s = 0; s < MAX_NUMBER_OF_STUDENTS; s++)
^
GradeCalculator.java:161: class, interface, or enum expected
for (int s = 0; s < MAX_NUMBER_OF_STUDENTS; s++)
^
GradeCalculator.java:164: class, interface, or enum expected
gradeCalc.noOfStudents =
^
GradeCalculator.java:166: class, interface, or enum expected
gradeCalc.score =
^
GradeCalculator.java:169: class, interface, or enum expected
gradeCalc.getStudentData(inFile);
^
GradeCalculator.java:170: class, interface, or enum expected
gradeCalc.displayGradeAverage(0);
^
GradeCalculator.java:171: class, interface, or enum expected
}
^
GradeCalculator.java:174: class, interface, or enum expected
public void getStudentData(Scanner inFile)
^
GradeCalculator.java:177: class, interface, or enum expected
System.out.println("One Moment Please");
^
GradeCalculator.java:178: class, interface, or enum expected
}
^
GradeCalculator.java:202: class, interface, or enum expected
public void displayGradeAverage(String stName)
^
GradeCalculator.java:205: class, interface, or enum expected
String stName = "";
^
GradeCalculator.java:207: class, interface, or enum expected
boolean classAvg = studentList[totalScore / noOfStudents].getClassAverage();
^
GradeCalculator.java:209: class, interface, or enum expected
stNameTF.setText(studentList[stName].getFirstName() + " "
^
GradeCalculator.java:211: class, interface, or enum expected
stAvgTF.setText(""+studentList[totalScore / 5.0].getStudentAverage());
^
GradeCalculator.java:212: class, interface, or enum expected
classAvgTF.setText(""+studentList[totalScore / noOfStudents].getClassAverage());
^
19 errors

Is This A Good Question/Topic? 0

Replies To: Grade Calculator Problems

#2 japanir

• jaVanir

Reputation: 1014
• Posts: 3,025
• Joined: 20-August 09

Re: Grade Calculator Problems

Posted 03 June 2010 - 01:23 PM

blknmld69 better open your own thread, and post your code, along with those error messages.
Was This Post Helpful? 0

#3 pbl

• There is nothing you can't do with a JTable

Reputation: 8378
• Posts: 31,956
• Joined: 06-March 08

Re: Grade Calculator Problems

Posted 03 June 2010 - 06:48 PM

95% of the time the error: class, interface, or enum expected
comes from unbalenced {}
indent your code properly and the errors will come obvious

Edited by macosxnerd101: I removed the code you indented because I see in another thread which I'm about to merge that this wasn't the OP's code.

This post has been edited by macosxnerd101: 06 June 2010 - 12:28 PM

Was This Post Helpful? 0

#4 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12278
• Posts: 45,364
• Joined: 27-December 08

Re: Grade Calculator Problems

Posted 04 June 2010 - 05:38 PM

I agree with japanir. Topic split.

@blknmld69: Please avoid necroposting. Also, are these errors from your code or from the OP of the thread you posted in?
Was This Post Helpful? 0

#5 blknmld69

• D.I.C Head

Reputation: -5
• Posts: 102
• Joined: 28-November 09

Re: Grade Calculator Problems

Posted 06 June 2010 - 09:46 AM

I need help on the file I attached. Its due tomorrow by 10am. Can someone get me started and help me throughout the day. I have been busy studying for my other classes and gettn my other program done. I know i shouldnt have excuses but its exams time!!!!!!

Desperate to get at least something done. Any help would be greatly appreciated!!!!!!!!!!

Attached File(s)

Was This Post Helpful? 0

#6 m-e-g-a-z

• Winning

Reputation: 497
• Posts: 1,457
• Joined: 19-October 09

Re: Grade Calculator Problems

Posted 06 June 2010 - 10:05 AM

Could you post your code in the brackets below as its easier and safer for us to access your code.

Was This Post Helpful? 0

#7 Ember

• D.I.C Head

Reputation: 70
• Posts: 160
• Joined: 24-April 10

Re: Grade Calculator Problems

Posted 06 June 2010 - 10:12 AM

Well, let's start off with #1 on the list. Create a Student Class:

```public class Student{
//Put a string of the student's name here
//Create an array of integers of size 3 here

public Student(Put Parameters here){
//Initialize fields above with the parameters you put in.
}

public int getGrades(put int param here){
//get the corresponding index and return an int value of that grade
}

public void setGrades(put int param here, put grade int here){
//set the grade based on the corresponding index, won't return anything
}

//Continue doing this with all the accessors~~~~~~~~~~~

```

I think I broke a few rules by posting just this so..yea. We at D.I.C. aren't really supposed to help you if you don't put any effort into trying to solve a problem first. I am assuming you just don't know where to start which is why I created this partial format for you to follow.

Have fun, it won't be too hard if you power through it all in one run.
Was This Post Helpful? 1

#8 blknmld69

• D.I.C Head

Reputation: -5
• Posts: 102
• Joined: 28-November 09

Re: Grade Calculator Problems

Posted 06 June 2010 - 11:24 AM

You assumed correct.....I will start with that. The only thing I had started was the GUI. I will work on it for a few hours and get back with you! Thanks
Was This Post Helpful? 0

#9 blknmld69

• D.I.C Head

Reputation: -5
• Posts: 102
• Joined: 28-November 09

Re: Grade Calculator Problems

Posted 06 June 2010 - 12:23 PM

what is necroposting?
Was This Post Helpful? 0

#10 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12278
• Posts: 45,364
• Joined: 27-December 08

Re: Grade Calculator Problems

Posted 06 June 2010 - 12:32 PM

Topics merged. Please avoid duplicate posting.

Necroposting is where you post in a dead thread. Really, any thread that isn't on the first two pages on the Java forum is considered dead.
Was This Post Helpful? 0

#11 blknmld69

• D.I.C Head

Reputation: -5
• Posts: 102
• Joined: 28-November 09

Re: Grade Calculator Problems

Posted 06 June 2010 - 12:40 PM

ok sorry!!!!!!!!!
Was This Post Helpful? 0

#12 pbl

• There is nothing you can't do with a JTable

Reputation: 8378
• Posts: 31,956
• Joined: 06-March 08

Re: Grade Calculator Problems

Posted 06 June 2010 - 05:03 PM

macosxnerd101, on 06 June 2010 - 01:32 PM, said:

Topics merged. Please avoid duplicate posting.

Necroposting is where you post in a dead thread. Really, any thread that isn't on the first two pages on the Java forum is considered dead.

Don't exagerate Mac, I spend 1 hour a day to answer unanswered posts in all in the fist 4 pages Whish somebody else will do as I do
Was This Post Helpful? 0

#13 blknmld69

• D.I.C Head

Reputation: -5
• Posts: 102
• Joined: 28-November 09

Re: Grade Calculator Problems

Posted 06 June 2010 - 05:32 PM

someone please help me with all these errors. Been working on this allday and my eyes are crossed. Its due tomorrow at 10am. Lord Help me Please!!!!!!!!!!!!!!!!!

```   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;

private static final int MAX_NUMBER_OF_STUDENTS = 20;

// instance variables
private Student[] Student = new Student[MAX_NUMBER_OF_STUDENTS];
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("Studen 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(String stName)
{
displayedStudentIndex = stName;
String stName = "";

boolean classAvg = studentList[totalScore / noOfStudents].getClassAverage();

stNameTF.setText(studentList[stName].getFirstName() + " "
+ studentList[stName].getLastName());
stAvgTF.setText(""+studentList[totalScore / 5.0].getStudentAverage());
classAvgTF.setText(""+studentList[totalScore / noOfStudents].getClassAverage());

}

}

```

ERRORS
----jGRASP exec: javac -g I:\DTC\Spring 2010\Java\GradeCalculator.java

GradeCalculator.java:13: cannot find symbol
symbol : class Student
location: class GradeCalculator
private Student[] Student = new Student[MAX_NUMBER_OF_STUDENTS];
^
GradeCalculator.java:136: cannot find symbol
symbol : class Scanner
location: class GradeCalculator
Scanner inFile =
^
GradeCalculator.java:154: cannot find symbol
symbol : class Scanner
location: class GradeCalculator
public void getStudentData(Scanner inFile)
^
GradeCalculator.java:13: cannot find symbol
symbol : class Student
location: class GradeCalculator
private Student[] Student = new Student[MAX_NUMBER_OF_STUDENTS];
^
GradeCalculator.java:137: cannot find symbol
symbol : class Scanner
location: class GradeCalculator
new Scanner(new FileReader("AcademicGrades.txt"));
^
GradeCalculator.java:137: cannot find symbol
symbol : class FileReader
location: class GradeCalculator
new Scanner(new FileReader("AcademicGrades.txt"));
^
GradeCalculator.java:140: cannot find symbol
symbol : variable gradeCalc
location: class GradeCalculator
gradeCalc.studentList[s] = new Student();
^
GradeCalculator.java:140: cannot find symbol
symbol : class Student
location: class GradeCalculator
gradeCalc.studentList[s] = new Student();
^
GradeCalculator.java:142: cannot find symbol
symbol : variable gradeCalc
location: class GradeCalculator
gradeCalc.noOfStudents =
^
GradeCalculator.java:144: cannot find symbol
symbol : variable gradeCalc
location: class GradeCalculator
gradeCalc.score =
^
GradeCalculator.java:147: cannot find symbol
symbol : variable gradeCalc
location: class GradeCalculator
gradeCalc.getStudentData(inFile);
^
GradeCalculator.java:148: cannot find symbol
symbol : variable gradeCalc
location: class GradeCalculator
gradeCalc.displayGradeAverage(0);
^
GradeCalculator.java:165: displayGradeAverage(java.lang.String) in GradeCalculator cannot be applied to (int)
displayGradeAverage(displayedStudentIndex - 1);
^
GradeCalculator.java:167: displayGradeAverage(java.lang.String) in GradeCalculator cannot be applied to (int)
displayGradeAverage(displayedStudentIndex);
^
GradeCalculator.java:170: displayGradeAverage(java.lang.String) in GradeCalculator cannot be applied to (int)
displayGradeAverage(displayedStudentIndex + 1);
^
GradeCalculator.java:172: displayGradeAverage(java.lang.String) in GradeCalculator cannot be applied to (int)
displayGradeAverage(displayedStudentIndex);
^
GradeCalculator.java:174: displayGradeAverage(java.lang.String) in GradeCalculator cannot be applied to (int)
displayGradeAverage(0);
^
GradeCalculator.java:182: incompatible types
found : java.lang.String
required: int
displayedStudentIndex = stName;
^
GradeCalculator.java:183: stName is already defined in displayGradeAverage(java.lang.String)
String stName = "";
^
GradeCalculator.java:185: cannot find symbol
symbol : variable studentList
location: class GradeCalculator
boolean classAvg = studentList[totalScore / noOfStudents].getClassAverage();
^
GradeCalculator.java:185: possible loss of precision
found : double
required: int
boolean classAvg = studentList[totalScore / noOfStudents].getClassAverage();
^
GradeCalculator.java:187: cannot find symbol
symbol : variable studentList
location: class GradeCalculator
stNameTF.setText(studentList[stName].getFirstName() + " "
^
GradeCalculator.java:187: incompatible types
found : java.lang.String
required: int
stNameTF.setText(studentList[stName].getFirstName() + " "
^
GradeCalculator.java:188: cannot find symbol
symbol : variable studentList
location: class GradeCalculator
+ studentList[stName].getLastName());
^
GradeCalculator.java:188: incompatible types
found : java.lang.String
required: int
+ studentList[stName].getLastName());
^
GradeCalculator.java:189: cannot find symbol
symbol : variable studentList
location: class GradeCalculator
stAvgTF.setText(""+studentList[totalScore / 5.0].getStudentAverage());
^
GradeCalculator.java:189: possible loss of precision
found : double
required: int
stAvgTF.setText(""+studentList[totalScore / 5.0].getStudentAverage());
^
GradeCalculator.java:189: cannot find symbol
symbol : variable stAvgTF
location: class GradeCalculator
stAvgTF.setText(""+studentList[totalScore / 5.0].getStudentAverage());
^
GradeCalculator.java:190: cannot find symbol
symbol : variable studentList
location: class GradeCalculator
classAvgTF.setText(""+studentList[totalScore / noOfStudents].getClassAverage());
^
GradeCalculator.java:190: possible loss of precision
found : double
required: int
classAvgTF.setText(""+studentList[totalScore / noOfStudents].getClassAverage());
^
GradeCalculator.java:190: cannot find symbol
symbol : variable classAvgTF
location: class GradeCalculator
classAvgTF.setText(""+studentList[totalScore / noOfStudents].getClassAverage());
^
31 errors

Attached File(s)

Was This Post Helpful? -1

#14 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12278
• Posts: 45,364
• Joined: 27-December 08

Re: Grade Calculator Problems

Posted 06 June 2010 - 05:38 PM

Duplicate Topics Merged. Please stop opening up duplicate threads.

Just some quick things I noticed while glancing through. First, you can fix your errors with Scanner and FileReader by importing java.util.* and java.io.*. Next, your class Student doesn't seem to be in visible scope for the GradeCalculator class.

Also, it isn't a good idea to name your array or any variable the same as the type, like you do here: Student[] Student.
Was This Post Helpful? 0

#15 m-e-g-a-z

• Winning

Reputation: 497
• Posts: 1,457
• Joined: 19-October 09

Re: Grade Calculator Problems

Posted 06 June 2010 - 05:41 PM

No need to shout blknmld69.

Most of these errors are because you are using the wrong type.

e.g Line 190

found : double
required: int

This post has been edited by m-e-g-a-z: 06 June 2010 - 05:54 PM

Was This Post Helpful? 0

• (4 Pages)
• 1
• 2
• 3
• Last »

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }