hi guys! so im basically editting my post i made earlier as it wznt as specific..
i have to make a program that basically ranks students by their cumulative gpa. the student's info is on a csv file written in a format like this, "name,bday,sex,9-1,9-2,10-1,10-2.....,cumulative". my question is, should i read this whole line nd jz use the cumulative data (im not sure how to do dat:/) or make a separate class nd make an array (for loop nd stuff) btw this program is a portion of a major program, basically a student ranker (some may know the program gradequick?) which has info abt da students freshmen gpa to senior gpa. i was able to add the student's info into my program nd saving the list as a csv file. but now im kinda stuck on the ranking part :/ please help me! heres a code for my program.. i hope you understand it.. oh and another thing is, i was able to recall the student that i wanted to edit, but after changing the data, if i press the save button again, instead of changing the original student, it saves it as a new student.. how do i change this..
import java.io.*;
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;
import java.awt.event.*;
public class Create extends JFrame
{
Container mainPane = getContentPane();
private JButton editButton = new JButton("Edit Student");
private JButton viewButton = new JButton("View Students");
private JButton rankButton = new JButton("View Rank");
private JButton saveButton = new JButton("Save");
private JButton resetButton = new JButton("Reset");
private JButton quitButton = new JButton("Quit");
private JTextField nameField = new JTextField();
private JTextField idField = new JTextField();
private JTextField bdayField = new JTextField();
private JTextField sexField = new JTextField();
private JTextField nine1Field = new JTextField();
private JTextField nine2Field = new JTextField();
private JTextField ten1Field = new JTextField();
private JTextField ten2Field = new JTextField();
private JTextField elev1Field = new JTextField();
private JTextField elev2Field = new JTextField();
private JTextField twelve1Field = new JTextField();
private JTextField twelve2Field = new JTextField();
private JTextArea outputArea = new JTextArea();
private BufferedReader inFile;
private PrintStream p;
private int num, id, i, id1, rank, counter;
private double q, w, e, r, t, y, u, o, cum;
private double[] cumu;
private String name, bday, sex, f, ques;
private Data[] students;
private Data student;
public Create(){
super("GPA Checker");
gradeQuick();
}
public void gradeQuick(){
mainPane.setLayout(new GridLayout(1,3));
JPanel leftPane = new JPanel(new GridLayout(2,2));
JPanel midPane = new JPanel(new GridLayout(7,2));
JPanel rightPane = new JPanel(new GridLayout(1,1));
JPanel midSubPane1 = new JPanel(new GridLayout(1,1));
JPanel midSubPane2 = new JPanel(new GridLayout(1,1));
JPanel midSubPane3 = new JPanel(new GridLayout(1,1));
JPanel midSubPane4 = new JPanel(new GridLayout(1,1));
JPanel midSubPane5 = new JPanel(new GridLayout(1,1));
JPanel midSubPane6 = new JPanel(new GridLayout(1,1));
JPanel midSubPane7 = new JPanel(new GridLayout(1,1));
JPanel midSubPane8 = new JPanel(new GridLayout(1,1));
JPanel midSubPane9 = new JPanel(new GridLayout(1,1));
JPanel midSubPane10 = new JPanel(new GridLayout(1,1));
JPanel midSubPane11 = new JPanel(new GridLayout(1,1));
JPanel midSubPane12 = new JPanel(new GridLayout(1,1));
saveButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent z){
try{
counter = 0;
String[] line;
BufferedReader inFile2 = new BufferedReader(new FileReader("students.csv"));
inFile2.readLine();
while(inFile2.ready()){
inFile2.readLine();
counter++;
}
inFile2.close();
line = new String[counter];
students = new Data[counter];
BufferedReader inFile = new BufferedReader(new FileReader("students.csv"));
inFile.readLine();
for(int i=0;i<counter;i++){
line[i] = inFile.readLine();
}
inFile.close();
p = new PrintStream(new FileOutputStream("students.csv"));
p.println("Name , ID , Gender , Birthday, 9-1 , 9-2 , 10-1 , 10-2 , 11 -1 , 11-2 , 12-1 , 12-2 , Cumulative");
for(int i=0;i<counter;i++){
p.println(line[i]);
}
name = nameField.getText();
id = Integer.parseInt(idField.getText());
sex = sexField.getText();
bday = bdayField.getText();
q = Double.parseDouble(nine1Field.getText());
w = Double.parseDouble(nine2Field.getText());
e = Double.parseDouble(ten1Field.getText());
r = Double.parseDouble(ten2Field.getText());
t = Double.parseDouble(elev1Field.getText());
y = Double.parseDouble(elev2Field.getText());
u = Double.parseDouble(twelve1Field.getText());
o = Double.parseDouble(twelve2Field.getText());
if(o>0){
cum= ((q+w+e+r+t+y+u+o)/8);
}
else if(u>0){
cum= ((q+w+e+r+t+y+u)/7);
}
else if(y>0){
cum= ((q+w+e+r+t+y)/6);
}
else if(t>0){
cum= ((q+w+e+r+t)/5);
}
else if(r>0){
cum= ((q+w+e+r)/4);
}
else if(e>0){
cum= ((q+w+e)/3);
}
else if(w>0){
cum= ((q+w)/2);
}
else if(q>0){
cum= ((q)/1);
}
// students[counter] = new Data(name, id, sex, bday, q, w, e, r, t, y, u, o, cum);
p.println(name+","+ id+","+ sex+","+ bday+","+ q+","+ w+","+ e+","+ r+","+ t+","+ y+","+ u+","+ o+","+ cum);
// p.println(students[counter].getName()+" , "+students[counter].getID()+" , "+students[counter].getSex()+" , "+students[counter].getBday()+" , " +students[counter].get91()+" , " +students[counter].get92()+" , "+students[counter].get101()+" , "+students[counter].get102()+" , "+students[counter].get111()+" , "+students[counter].get112()+" , "+students[counter].get121()+" , "+students[counter].get122()+" , "+students[counter].getCum());
p.close();
}catch(IOException e){
System.err.println("Error");
}
}//end of actionPerformed
}//end of inner class
);//end of argument
editButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
String[] blah = new String[12];
f = JOptionPane.showInputDialog("Enter ID Number of student you wish to edit");
id1 = Integer.parseInt(f);
int comma;
int id2 = 0;
String txt,txt2;
BufferedReader inFile3 = new BufferedReader(new FileReader("students.csv"));
inFile3.readLine();
do{
txt = inFile3.readLine();
comma = txt.indexOf(",");
txt2 = txt.substring(comma+1,comma+6);
id2 = Integer.parseInt(txt2);
}while(id1!=id2);
for(int index=0;index<blah.length;index++){
comma = txt.indexOf(",");
blah[index] = txt.substring(0,comma);
txt = txt.substring(comma+1);
}
nameField.setText(blah[0]);
idField.setText(blah[1]);
sexField.setText(blah[2]);
bdayField.setText(blah[3]);
nine1Field.setText(blah[4]);
nine2Field.setText(blah[5]);
ten1Field.setText(blah[6]);
ten2Field.setText(blah[7]);
elev1Field.setText(blah[8]);
elev2Field.setText(blah[9]);
twelve1Field.setText(blah[10]);
twelve2Field.setText(blah[11]);
// student = new Data(
}
catch(IOException e4){
}
}//end of actionPerformed
}//end of inner class
);//end of argument
viewButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e1){
}//end of actionPerformed
}//end of inner class
);//end of argument
rankButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e1){
IM STUCK HERE :S
}
}//end of actionPerformed
}//end of inner class
);//end of argument
saveButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e1){
}//end of actionPerformed
}//end of inner class
);//end of argument
resetButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e1){
setVisible(false);
new Create();
}//end of actionPerformed
}//end of inner class
);//end of argument
quitButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e1){
Create.this.dispose();
System.exit(0);
}//end of actionPerformed
}//end of inner class
);//end of argument
leftPane.setBorder(BorderFactory.createTitledBorde r("Program Options"));
midPane.setBorder(BorderFactory.createTitledBorder ("Input"));
rightPane.setBorder(BorderFactory.createTitledBord er("Output"));
leftPane.add(viewButton);
leftPane.add(rankButton);
leftPane.add(resetButton);
leftPane.add(quitButton);
midSubPane1.setBorder(BorderFactory.createTitledBo rder("Name(Last. First)"));
midSubPane2.setBorder(BorderFactory.createTitledBo rder("ID #"));
midSubPane3.setBorder(BorderFactory.createTitledBo rder("Birthday(MM/DD/YY)"));
midSubPane4.setBorder(BorderFactory.createTitledBo rder("Sex(M/F)"));
midSubPane5.setBorder(BorderFactory.createTitledBo rder("Grade 9 - 1"));
midSubPane6.setBorder(BorderFactory.createTitledBo rder("Grade 9 - 2"));
midSubPane7.setBorder(BorderFactory.createTitledBo rder("Grade 10 - 1"));
midSubPane8.setBorder(BorderFactory.createTitledBo rder("Grade 10 - 2"));
midSubPane9.setBorder(BorderFactory.createTitledBo rder("Grade 11 - 1"));
midSubPane10.setBorder(BorderFactory.createTitledB order("Grade 11 - 2"));
midSubPane11.setBorder(BorderFactory.createTitledB order("Grade 12 - 1"));
midSubPane12.setBorder(BorderFactory.createTitledB order("Grade 12 - 2"));
midSubPane1.add(nameField);
midSubPane2.add(idField);
midSubPane3.add(bdayField);
midSubPane4.add(sexField);
midSubPane5.add(nine1Field);
midSubPane6.add(nine2Field);
midSubPane7.add(ten1Field);
midSubPane8.add(ten2Field);
midSubPane9.add(elev1Field);
midSubPane10.add(elev2Field);
midSubPane11.add(twelve1Field);
midSubPane12.add(twelve2Field);
midPane.add(midSubPane1);
midPane.add(midSubPane2);
midPane.add(midSubPane3);
midPane.add(midSubPane4);
midPane.add(midSubPane5);
midPane.add(midSubPane6);
midPane.add(midSubPane7);
midPane.add(midSubPane8);
midPane.add(midSubPane9);
midPane.add(midSubPane10);
midPane.add(midSubPane11);
midPane.add(midSubPane12);
midPane.add(editButton);
midPane.add(saveButton);
rightPane.add(new JScrollPane(outputArea));
mainPane.add(leftPane);
mainPane.add(midPane);
mainPane.add(rightPane);
setContentPane(mainPane);
setLocation(10,10);
setSize(800,500);
setVisible(true);
}
}