/*
Name: Charyl Janney
Date: July 21 2011
Project: Chpt5ex3
File Name: AverageScores.java
This application calculates an average upon enter number of
scores and calculating an average of these scores.
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
import java.io.*;
public class AverageScores extends frame
{
//Declare variable
Panel topPanel();
public AverageScores()
{
topPanel = new Panel();
//setup frame
this.setLayout(new BorderLayout());
topPanel.setLayout(new GridLayout((totalGrades + 1),2,10,10));
}
//add components to frame
add(topPanel.BorderLayout.NORTH);
public static void main(String[] args) throws IOException
{
try
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in) );
System.out.print( "Please enter number of tests: " );
int nrOfTests = Integer.parseInt(input.readLine());
//the sumOfAllGrades
double sumOfAllGrades = 0;
for( int i=0; i < nrOfTests; i++ )
{
System.out.print( "Enter the grade for Test " +(i+1)+ ": " );
double grade = Double.parseDouble(input.readLine());
//add current grade to sumOffAllGrades
sumOfAllGrades += grade;
}
//calculating average
double average = sumOfAllGrades/nrOfTests;
System.out.println("The total grade average is: " + average);
}
catch( Exception e )
{
e.printStackTrace();
}
//sets Frame up
AverageScores f = new AverageScores();
f.setTitle("Average Scores");
f.setBounds(50, 100, 300, 400);
f.setLocationRelativeTo(null);
f.setVisible(true);
{
}
}
}
It runs fine without the border/panels. My errors are this:
C:\Documents and Settings\CE User\Desktop\Java_OnLine_Course\chpt6\AverageScores.java:30: invalid method declaration; return type required
add(topPanel.BorderLayout.NORTH);
^
C:\Documents and Settings\CE User\Desktop\Java_OnLine_Course\chpt6\AverageScores.java:30: <identifier> expected
add(topPanel.BorderLayout.NORTH);
^
2 errors
Tool completed with exit code 1
Can anyone help?

New Topic/Question
Reply



MultiQuote






|