Can someone work with me on this program. I will put the instructions first, then my code, then the errors
INSTRUCTIONS:
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:
o Open the data file for reading
o load all the data into an array of students from the file,
o Close the file
o Make all modifications to the data in the array of students.
o When saving, open the datafile for writing
o Loop through the students and save the data to the datafile.
o Close the data file.
MY CODE
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GradeCalculator2 extends JFrame
{
private static final int WIDTH = 550;
private static final int HEIGHT = 430;
int GradeCalc;
int student;
private StudentList[] sList = new StudentList[20];
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;
}
// 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 GradeCalculator2()
{
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);
/**
This program creates an instance of the GradeCalculator2 class,
which displays a window on the screen.
*/
public class GradeCalculator2
{
public static void main(String[] args
{
new GradeCalculator2();
}
}
}
ERRORS:
GradeCalculator_2.java:45: invalid method declaration; return type required
public GradeCalculator2()
^
GradeCalculator_2.java:143: illegal start of expression
public class GradeCalculator2
^
GradeCalculator_2.java:145: ')' expected
public static void main(String[] args
^
GradeCalculator_2.java:151: reached end of file while parsing
}
^
4 errors