error on line 136: cannot find symbol
symbol: method score(int)
location: class AveragingGrades.
/*
Chapter 5: Averaging Grades
Programmer: Carl Seyerle
Course: CINS 136-00A
Filename: AveragingGrades.java
Purpose: This is a program that allows a user to enter
class grades into an array of floats. The app
will prompt for the total number of grades to
be entered, then call a method to average the
grades, and finially display the grades and the
resulting average
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
public class AveragingGrades extends Frame implements ActionListener //constructor method
{
int counter;
int _i = counter;
int _Count = 0;
int scoreAverage;
int grade;
int score;
//identifies panels and components
Panel numberPanel = new Panel();
Label numberLabel = new Label("Enter the number of scores to average.");
TextField numberField = new TextField(5);
Button numberButton = new Button("Enter");
Panel scorePanel = new Panel();
Label scoreLabel = new Label("Enter Scores");
TextField scoreField = new TextField(5);
Button scoreButton = new Button("Add");
Panel displayPanel = new Panel();
TextArea displayTitle = new TextArea();
TextArea displayScores = new TextArea(null,counter + 1,5,1);
Panel averagePanel = new Panel();
Label averageLabel = new Label("Your average of" + counter + "scores is: " + scoreAverage + ".");
Button clearButton = new Button("Clear");
public AveragingGrades()
{
//set layouts for frame and panels
this.setLayout(new BorderLayout());
numberPanel.setLayout(new FlowLayout());
scorePanel.setLayout(new FlowLayout());
displayPanel.setLayout(new FlowLayout());
averagePanel.setLayout(new FlowLayout());
//add components to number panel
numberPanel.add(numberLabel);
numberPanel.add(numberField);
numberPanel.add(numberButton);
numberPanel.setBackground(Color.yellow);
//add components to score panel
scorePanel.add(scoreLabel);
scorePanel.add(scoreField);
scorePanel.add(scoreButton);
scorePanel.setBackground(Color.lightGray);
//add components to display panel
displayPanel.add(displayTitle);
displayPanel.add(displayScores);
displayScores.setEditable(false);
displayTitle.setEditable(false);
displayPanel.setBackground(Color.lightGray);
//add components to average panel
averagePanel.add(averageLabel);
averagePanel.add(clearButton);
averagePanel.setBackground(Color.lightGray);
//add panels to frame
add(numberPanel, BorderLayout.NORTH);
add(scorePanel, BorderLayout.WEST);
add(displayPanel, BorderLayout.CENTER);
add(averagePanel, BorderLayout.SOUTH);
numberButton.addActionListener(this);
scoreButton.addActionListener(this);
clearButton.addActionListener(this);
//overriding windowClosing method
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public void AverageScore()
{
scoreAverage = grade / _Count;
}
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
try
{
if (arg == "Enter")
{
int counter = Integer.parseInt(numberField.getText());
scoreField.requestFocus();
JOptionPane.showMessageDialog(null,"Begin entering scores.","Info",JOptionPane.INFORMATION_MESSAGE);
scorePanel.setBackground(Color.yellow);
numberPanel.setBackground(Color.lightGray);
}
if (arg == "Add")
{
int[] averagingGrades = new int[counter - 1];
_Count++;
if (_Count >= _i)
{
averagePanel.setBackground(Color.yellow);
scorePanel.setBackground(Color.lightGray);
}
score(averagingGrades[_Count - 1]) = Integer.parseInt(numberField.getText());
displayTitle.setText("Score " + _Count + " of " + _i);
displayScores.setText("" + _Count + " " + averagingGrades[_Count - 1]);
scoreField.setText("");
grade += score;
}
if (arg == "Clear")
{
numberField.setText("");
scoreField.setText("");
numberPanel.setBackground(Color.yellow);
scorePanel.setBackground(Color.lightGray);
displayPanel.setBackground(Color.lightGray);
averagePanel.setBackground(Color.lightGray);
numberField.requestFocus();
}
}
catch(NumberFormatException x)
{
JOptionPane.showMessageDialog(null,"Your entry was out of bounds.","Error",JOptionPane.INFORMATION_MESSAGE);
}
}
public static void main(String[] args)
{
AveragingGrades f = new AveragingGrades();
f.setBounds(200,200,600,300);
f.setTitle("Averaging Grades");
f.setVisible(true);
} //end of main
}
This post has been edited by pbl: 22 July 2010 - 08:06 PM
Reason for edit:: Code tags fixed

New Topic/Question
Reply




MultiQuote






|