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.....,cumulati ve". 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.eve nt.*;
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.setLay out(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.addA ctionListener(n ew ActionListener( ){
public void actionPerformed (ActionEvent z){
try{
counter = 0;
String[] line;
BufferedReader inFile2 = new BufferedReader( new FileReader("stu dents.csv"));
inFile2.readLin e();
while(inFile2.r eady()){
inFile2.readLin e();
counter++;
}
inFile2.close() ;
line = new String[counter];
students = new Data[counter];
BufferedReader inFile = new BufferedReader( new FileReader("stu dents.csv"));
inFile.readLine ();
for(int i=0;i<counter;i ++){
line[i] = inFile.readLine ();
}
inFile.close();
p = new PrintStream(new FileOutputStrea m("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.getTe xt();
id = Integer.parseIn t(idField.getTe xt());
sex = sexField.getTex t();
bday = bdayField.getTe xt();
q = Double.parseDou ble(nine1Field. getText());
w = Double.parseDou ble(nine2Field. getText());
e = Double.parseDou ble(ten1Field.g etText());
r = Double.parseDou ble(ten2Field.g etText());
t = Double.parseDou ble(elev1Field. getText());
y = Double.parseDou ble(elev2Field. getText());
u = Double.parseDou ble(twelve1Fiel d.getText());
o = Double.parseDou ble(twelve2Fiel d.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(stude nts[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(IOExcept ion e){
System.err.prin tln("Error");
}
}//end of actionPerformed
}//end of inner class
);//end of argument
editButton.addA ctionListener(n ew ActionListener( ){
public void actionPerformed (ActionEvent e){
try{
String[] blah = new String[12];
f = JOptionPane.sho wInputDialog("E nter ID Number of student you wish to edit");
id1 = Integer.parseIn t(f);
int comma;
int id2 = 0;
String txt,txt2;
BufferedReader inFile3 = new BufferedReader( new FileReader("stu dents.csv"));
inFile3.readLin e();
do{
txt = inFile3.readLin e();
comma = txt.indexOf("," );
txt2 = txt.substring(c omma+1,comma+6) ;
id2 = Integer.parseIn t(txt2);
}while(id1!=id2 );
for(int index=0;index<b lah.length;inde x++){
comma = txt.indexOf("," );
blah[index] = txt.substring(0 ,comma);
txt = txt.substring(c omma+1);
}
nameField.setTe xt(blah[0]);
idField.setText (blah[1]);
sexField.setTex t(blah[2]);
bdayField.setTe xt(blah[3]);
nine1Field.setT ext(blah[4]);
nine2Field.setT ext(blah[5]);
ten1Field.setTe xt(blah[6]);
ten2Field.setTe xt(blah[7]);
elev1Field.setT ext(blah[8]);
elev2Field.setT ext(blah[9]);
twelve1Field.se tText(blah[10]);
twelve2Field.se tText(blah[11]);
// student = new Data(
}
catch(IOExcepti on e4){
}
}//end of actionPerformed
}//end of inner class
);//end of argument
viewButton.addA ctionListener(n ew ActionListener( ){
public void actionPerformed (ActionEvent e1){
}//end of actionPerformed
}//end of inner class
);//end of argument
rankButton.addA ctionListener(n ew ActionListener( ){
public void actionPerformed (ActionEvent e1){
IM STUCK HERE :S
}
}//end of actionPerformed
}//end of inner class
);//end of argument
saveButton.addA ctionListener(n ew ActionListener( ){
public void actionPerformed (ActionEvent e1){
}//end of actionPerformed
}//end of inner class
);//end of argument
resetButton.add ActionListener( new ActionListener( ){
public void actionPerformed (ActionEvent e1){
setVisible(fals e);
new Create();
}//end of actionPerformed
}//end of inner class
);//end of argument
quitButton.addA ctionListener(n ew ActionListener( ){
public void actionPerformed (ActionEvent e1){
Create.this.dis pose();
System.exit(0);
}//end of actionPerformed
}//end of inner class
);//end of argument
leftPane.setBor der(BorderFacto ry.createTitled Border("Program Options"));
midPane.setBord er(BorderFactor y.createTitledB order("Input")) ;
rightPane.setBo rder(BorderFact ory.createTitle dBorder("Output "));
leftPane.add(vi ewButton);
leftPane.add(ra nkButton);
leftPane.add(re setButton);
leftPane.add(qu itButton);
midSubPane1.set Border(BorderFa ctory.createTit ledBorder("Name (Last. First)"));
midSubPane2.set Border(BorderFa ctory.createTit ledBorder("ID #"));
midSubPane3.set Border(BorderFa ctory.createTit ledBorder("Birt hday(MM/DD/YY)"));
midSubPane4.set Border(BorderFa ctory.createTit ledBorder("Sex( M/F)"));
midSubPane5.set Border(BorderFa ctory.createTit ledBorder("Grad e 9 - 1"));
midSubPane6.set Border(BorderFa ctory.createTit ledBorder("Grad e 9 - 2"));
midSubPane7.set Border(BorderFa ctory.createTit ledBorder("Grad e 10 - 1"));
midSubPane8.set Border(BorderFa ctory.createTit ledBorder("Grad e 10 - 2"));
midSubPane9.set Border(BorderFa ctory.createTit ledBorder("Grad e 11 - 1"));
midSubPane10.se tBorder(BorderF actory.createTi tledBorder("Gra de 11 - 2"));
midSubPane11.se tBorder(BorderF actory.createTi tledBorder("Gra de 12 - 1"));
midSubPane12.se tBorder(BorderF actory.createTi tledBorder("Gra de 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.ad d(elev2Field);
midSubPane11.ad d(twelve1Field) ;
midSubPane12.ad d(twelve2Field) ;
midPane.add(mid SubPane1);
midPane.add(mid SubPane2);
midPane.add(mid SubPane3);
midPane.add(mid SubPane4);
midPane.add(mid SubPane5);
midPane.add(mid SubPane6);
midPane.add(mid SubPane7);
midPane.add(mid SubPane8);
midPane.add(mid SubPane9);
midPane.add(mid SubPane10);
midPane.add(mid SubPane11);
midPane.add(mid SubPane12);
midPane.add(edi tButton);
midPane.add(sav eButton);
rightPane.add(n ew JScrollPane(out putArea));
mainPane.add(le ftPane);
mainPane.add(mi dPane);
mainPane.add(ri ghtPane);
setContentPane( mainPane);
setLocation(10, 10);
setSize(800,500 );
setVisible(true );
}
}