Annotation of capa/capa51/JavaTools/TScore.java, revision 1.5

1.4       albertel    1: /* old score extrapolator widget
                      2:    Copyright (C) 1992-2000 Michigan State University
                      3: 
                      4:    The CAPA system is free software; you can redistribute it and/or
1.5     ! albertel    5:    modify it under the terms of the GNU General Public License as
1.4       albertel    6:    published by the Free Software Foundation; either version 2 of the
                      7:    License, or (at your option) any later version.
                      8: 
                      9:    The CAPA system is distributed in the hope that it will be useful,
                     10:    but WITHOUT ANY WARRANTY; without even the implied warranty of
                     11:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1.5     ! albertel   12:    General Public License for more details.
1.4       albertel   13: 
1.5     ! albertel   14:    You should have received a copy of the GNU General Public
1.4       albertel   15:    License along with the CAPA system; see the file COPYING.  If not,
                     16:    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
                     17:    Boston, MA 02111-1307, USA.
                     18: 
                     19:    As a special exception, you have permission to link this program
                     20:    with the TtH/TtM library and distribute executables, as long as you
                     21:    follow the requirements of the GNU GPL in regard to all of the
                     22:    software in the executable aside from TtH/TtM.
                     23: */
                     24: 
1.1       albertel   25: import java.applet.*;
                     26: import java.awt.*;
                     27: import java.lang.*;
                     28: import java.util.*;
                     29: import java.net.*;
                     30: import java.awt.event.*;
                     31: 
                     32: public class TScore extends Applet implements Runnable {
                     33:   public float   W[];
                     34:   public int     Entry_cnt,  Exam_cnt;
                     35:   public float   S[], F[];
                     36:   public int     X[], C[], R[];
                     37:   public float   SF_ratio[],  SF_percent[];
                     38:   public float   Sum_ratio[], Sum_percent[];
                     39:   public float   Exam_ratio[], Raw_exam_ratio[], Raw_epc_ratio[];
                     40:   public float   Term_score;
                     41:      
                     42:   ExpPanel     []  HQpanel;
                     43:   ExmPanel     []  EXpanel;
                     44:   Label            TitleL;
                     45:   Label            EqL;
                     46: 
                     47: public void init() {
                     48:    String      p;
                     49:    int         fs;
                     50:    int         idx;
                     51: 
                     52:    C       = new int[2];
                     53:    R       = new int[2];
                     54:    W       = new float[5];
                     55: 
                     56: //  final exam set number   
                     57:    p=getParameter("FS"); 
                     58:    fs = (p==null)?1:Integer.valueOf(p).intValue();
                     59: // how many entries 
                     60:    Entry_cnt= ((fs == 0)? 2 : 1 +  2*fs); 
                     61: // how many exams
                     62:    Exam_cnt = (Entry_cnt - 3 ) / 2; 
                     63: 
                     64:    S      = new float[Entry_cnt];
                     65:    F      = new float[Entry_cnt];
                     66:    X      = new int[Entry_cnt];
                     67:    SF_ratio  = new float[Entry_cnt];
                     68:    SF_percent= new float[Entry_cnt];
                     69:    Sum_ratio = new float[Entry_cnt];
                     70:    Sum_percent = new float[Entry_cnt];
                     71:    Raw_exam_ratio = new float[Exam_cnt];
                     72:    Raw_epc_ratio  = new float[Exam_cnt];
                     73:    Exam_ratio = new float[Exam_cnt];
                     74: 
                     75:    p=getParameter("HW_W");
                     76:    W[0] =(p==null)?1:Float.valueOf(p).floatValue(); 
                     77:    p=getParameter("QZ_W");
                     78:    W[1] =(p==null)?1:Float.valueOf(p).floatValue();
                     79:    p=getParameter("EX_W");
                     80:    W[2] =(p==null)?1:Float.valueOf(p).floatValue();
                     81:    p=getParameter("FE_W");
                     82:    W[3] =(p==null)?1:Float.valueOf(p).floatValue();
                     83:    p=getParameter("PC_W");
                     84:    W[4] =(p==null)?1:Float.valueOf(p).floatValue();
                     85:    
                     86:    p=getParameter("HW_C");
                     87:    C[0] =(p==null)?1:Integer.valueOf(p).intValue();
                     88:    p=getParameter("HW_R");
                     89:    R[0] =(p==null)?1:Integer.valueOf(p).intValue();
                     90:    p=getParameter("QZ_C");
                     91:    C[1] =(p==null)?1:Integer.valueOf(p).intValue();
                     92:    p=getParameter("QZ_R");
                     93:    R[1] =(p==null)?1:Integer.valueOf(p).intValue();
                     94: 
                     95:    for(idx=0;idx<Entry_cnt;idx++) {
                     96:      p=getParameter("X"+idx);
                     97:      X[idx]=(p==null)?1:Integer.valueOf(p).intValue();
                     98:      if( (idx>1) && (X[idx]==1) ) {  // midterm exam, final extrapolated
                     99:        SF_ratio[idx]  = (float)0.0;
                    100:        SF_percent[idx]= (float)0.0;
                    101:        if( idx == (Entry_cnt - 1) ) {  // final exam extrapolated, from hw
                    102:          Sum_ratio[idx] = SF_ratio[0]; 
                    103: 	 Sum_percent[idx] = SF_percent[0];
                    104:        } 
                    105:      } else {
                    106:  // homework, quiz extrapolated or not;exam,final not extrapolated 
                    107:        p=getParameter("S"+idx);
                    108:        S[idx]=(p==null)?1:Float.valueOf(p).floatValue();
                    109:        p=getParameter("F"+idx);
                    110:        F[idx] =(p==null)?1:Float.valueOf(p).floatValue();
1.2       albertel  111:        if ((float)F[idx] < 0.00000001) {
                    112: 	   SF_ratio[idx] = (float) 0.0;
                    113:        } else {
                    114: 	   SF_ratio[idx] = (float) ((float)S[idx] / (float)F[idx]);
                    115:        }
1.1       albertel  116:        int tmp_i = (int) (10000 * SF_ratio[idx] );
                    117:        SF_percent[idx]= (float)tmp_i / (float)100.0;
                    118:        if( idx == (Entry_cnt - 1) ) {         // final exam
                    119:          Sum_ratio[idx]   = SF_ratio[idx];
                    120: 	 Sum_percent[idx] = SF_percent[idx];
                    121:        }
                    122:      }
                    123:    }
                    124:    Sum_ratio[0] = (float)(S[0] + ((float)R[0]*F[0]*SF_ratio[0]/(float)C[0])) / (float)(F[0]*(1.0 + (float)R[0]/(float)C[0]));
                    125:      int tmp_i = (int)(10000 * Sum_ratio[0]);
                    126:      Sum_percent[0] =  (float)tmp_i / (float)100.0;
                    127:      Sum_ratio[0]   = Sum_percent[0] / (float)100.0;
                    128:      Sum_ratio[1] = (float)(S[1] + (R[1]*F[1]*SF_ratio[1]/C[1])) / (float)(F[1]*(1.0 + R[1]/C[1]));
                    129:      tmp_i = (int)(10000 * Sum_ratio[1]);
                    130:      Sum_percent[1] =  (float)tmp_i / (float)100.0;
                    131:      Sum_ratio[1]   =  Sum_percent[1] / (float)100.0;
                    132: 
                    133: 
                    134:    // if exam 1 is not given, use homework as default to extrapolate 
                    135:    //    if epc 1 is not given, use exam 1 as epc 1
                    136:    // if exam 2 is not given, use exam 1 to extrapolate
                    137:    // if exam 3 is not given, use exam 2 to extrapolate
1.3       albertel  138:    // I am lying, I only use the homework score
1.1       albertel  139: 
                    140:    float exam_sum = (float)0.0;
                    141:    for(idx=0;idx<Exam_cnt;idx++) {
                    142:      if( X[(idx+1)*2] == 1 ) {
                    143: //      taken from homework 
                    144:         Raw_exam_ratio[idx] = SF_ratio[0]; 
                    145:      } else {
                    146:         Raw_exam_ratio[idx] = SF_ratio[(idx+1)*2];
                    147:      }
                    148:      if( X[(idx+1)*2 + 1] == 1 ) {
                    149:         Raw_epc_ratio[idx] = Raw_exam_ratio[idx];
                    150:      } else {
                    151:         Raw_epc_ratio[idx] = SF_ratio[(idx+1)*2 + 1];
                    152:      }
                    153:      
                    154:      if( Raw_epc_ratio[idx] > Raw_exam_ratio[idx] ) {
                    155:          Exam_ratio[idx] = Raw_exam_ratio[idx] + W[4]*( Raw_epc_ratio[idx] - Raw_exam_ratio[idx] ) ;
                    156:      } else {
                    157:          Exam_ratio[idx] = Raw_exam_ratio[idx];
                    158:      }
1.3       albertel  159:      //System.out.print("idx="+idx+":Exam_ratio="+Exam_ratio[idx]+"\n");
1.1       albertel  160:      Sum_ratio[2*(idx+1)] = Exam_ratio[idx];
                    161:      tmp_i = (int)(10000 * Exam_ratio[idx] );
                    162:      Sum_percent[2*(idx+1)] = (float)tmp_i / (float)100.0;
                    163:      Sum_ratio[2*(idx+1)]   = Sum_percent[2*(idx+1)] / (float)100.0;
                    164:      exam_sum += Exam_ratio[idx];
                    165:    }
                    166:    exam_sum = (float)exam_sum / (float)Exam_cnt;
                    167: 
                    168:    Term_score = Sum_ratio[0] * W[0] + Sum_ratio[1] * W[1] + exam_sum * W[2] + Sum_ratio[Entry_cnt - 1] * W[3];
                    169: 
                    170:    tmp_i = (int)(10000 * Term_score);
                    171:    Term_score = (float)tmp_i / (float)100.0;
                    172: 
                    173: 
                    174: //    call to setup User Interface
                    175: 
                    176:    initGUI();
                    177: 
                    178:     }
                    179: public void initGUI() {
                    180:        int     row_cnt = Exam_cnt + 4;
                    181:        int     idx;
                    182:        String  [] title = {"Homework", "Quizz" }; 
                    183:        HQpanel = new ExpPanel[2];
                    184:        EXpanel = new ExmPanel[Exam_cnt+2];
                    185: 
                    186:        setLayout(new GridLayout(row_cnt,0,4,4));
                    187: 
                    188:        String t_str = "Term Score Extrapolation Applet";
                    189:        TitleL    = new Label(t_str, Label.CENTER);
                    190:        add(TitleL);
                    191: 
                    192:        for(idx = 0; idx < 2; idx++) {
                    193:          HQpanel[idx] = new ExpPanel(this,title[idx],X[idx],
                    194:                                S[idx],F[idx],C[idx],R[idx]);
                    195:          add(HQpanel[idx]);
                    196:        }
                    197:        // Midterm Exam
                    198:        for(idx =0; idx < Exam_cnt; idx++) {
                    199:          EXpanel[idx] = new ExmPanel(this,idx+1,X[2*(idx+1)],1,X[2*idx+3],
                    200:              S[2*(idx+1)],F[2*(idx+1)],W[4],S[2*idx+3],F[2*idx+3],Sum_ratio[2*(idx+1)]);
                    201:          add(EXpanel[idx]);
                    202:        }
                    203:        // Final Exam
                    204:        EXpanel[Exam_cnt] = new ExmPanel(this,0,X[Entry_cnt-1],0,0,
                    205:              S[Entry_cnt-1],F[Entry_cnt-1],W[3],S[Entry_cnt-1],F[Entry_cnt-1],Sum_ratio[Entry_cnt-1]);
                    206:        add(EXpanel[Exam_cnt]);
                    207: 
                    208:        String eq_str = "Term score=" + Sum_percent[0] + "*" + W[0] ;
                    209:        eq_str = eq_str + "+" + Sum_percent[1] + "*" + W[1] ;
                    210:        eq_str = eq_str + "+" + "(" ; 
                    211:        for(idx =1;idx<=Exam_cnt;idx++) {
                    212:           if(idx>1) {
                    213:              eq_str = eq_str + "+ ";
                    214:            }
                    215:            eq_str = eq_str + Sum_percent[2*idx] ;
                    216:        } 
                    217:        eq_str = eq_str + ") *" + W[2] + "/" + Exam_cnt + "+";
                    218:        eq_str = eq_str + Sum_percent[2*idx] + "*" + W[3] + " = ";
                    219:        eq_str = eq_str + " " + Term_score + "%";
                    220:        // EqL    = new Label(eq_str, Label.LEFT);
                    221:        // add(EqL);
                    222: 
                    223:   }
                    224: public void recalcTermScore() {
                    225:        float  score[];
                    226:        int    idx;
                    227:        float  term_summ, exam_summ;
                    228:  
                    229:        score = new float[Exam_cnt+3];
                    230:        term_summ = (float)0.0;
                    231:        exam_summ = (float)0.0;
                    232:        for(idx=0;idx<2;idx++) {
                    233:          score[idx] = HQpanel[idx].getSubTotal();
                    234:          term_summ = term_summ + score[idx] * W[idx];
                    235:        }
                    236:        for(idx =0; idx < Exam_cnt; idx++) {
                    237:          score[idx+2] = EXpanel[idx].getSubTotal();
                    238:          exam_summ = exam_summ + score[idx+2];
                    239:        }
                    240:        score[Exam_cnt+2] = EXpanel[Exam_cnt].getSubTotal();
                    241:        exam_summ = exam_summ * W[2] / Exam_cnt;
                    242:        term_summ = term_summ + exam_summ + score[Exam_cnt+2] * W[3];
                    243:        int  tmp_i = (int) ((float)100.0*term_summ);
                    244:        term_summ  = (float)(tmp_i / (float)100.0);
                    245:        String eq_str = "Term score=" + score[0] + "*" + W[0] ;
                    246:        eq_str = eq_str + "+" + score[1] + "*" + W[1] ;
                    247:        eq_str = eq_str + "+" + "(" ; 
                    248:        for(idx=0;idx<Exam_cnt;idx++) {
                    249:           if(idx>0) {
                    250:              eq_str = eq_str + "+ ";
                    251:            }
                    252:            eq_str = eq_str + score[idx+2] ;
                    253:         } 
                    254:         eq_str = eq_str + ") *" + W[2] + "/" + Exam_cnt + "+";
                    255:         eq_str = eq_str + score[Exam_cnt+2] + "*" + W[3] + " = ";
                    256:         eq_str = eq_str + " " + term_summ + "  %";
                    257:         // TitleL.setText("TTT");
                    258:         TitleL.setText(eq_str);
                    259:   }
                    260: public void paint(Graphics g) {
                    261:         Dimension d = getSize();
                    262:         g.drawRect(0,0, d.width - 1, d.height - 1);
                    263:   }
                    264: public void run()   {  }
                    265: public void start() {
                    266:         recalcTermScore();
                    267:   }
                    268: public void stop()  {  }
                    269: 
                    270: }
1.2       albertel  271: class ExpPanel extends Panel
                    272:                      implements ActionListener,
                    273:                                  AdjustmentListener {
                    274:     TScore     controller;
                    275:     TextField  exT;
                    276:     Scrollbar  sB;
                    277:     Label      sumL;
                    278:     int        max = 100;
                    279:     int        block = 1;
                    280:     float      ff,ss;
                    281:     int        rr,cc;
                    282: 
                    283:     ExpPanel(TScore u,String t,
                    284:              int x,float a,float b,int m,int n) {
                    285:         GridBagConstraints   c = new GridBagConstraints();
                    286:         GridBagLayout        gridbag = new GridBagLayout();
                    287:         setLayout(gridbag);
                    288:         int tmp_i;
                    289: 
                    290:         controller = u;
                    291:         ss = a; ff = b; cc = m; rr = n;
                    292:         float sf_ratio =  (float)ss / (float)ff;
                    293:         tmp_i = (int)(10000 * sf_ratio);
                    294:         float sf_percent =  (float)tmp_i / (float)100.0;
1.3       albertel  295:         float sum_ratio = (float)(ss + ((float)rr*ff*sf_ratio/(float)(cc+rr))) / (float)(ff*(1.0 + (float)rr/(float)(cc+rr)));
                    296: 	//System.out.print("ss ="+ss+":rr="+rr+":ff="+ff+":sf_ratio="+sf_ratio+":cc="+cc+":sum_ratio="+sum_ratio+"\n");
1.2       albertel  297:         tmp_i = (int)(10000 * sum_ratio);
                    298:         float sum_percent =  (float)tmp_i / (float)100.0;
                    299: 
                    300:         String cs = " " + ss + "/"  + ff; 
                    301:         cs = cs + " = " + sf_percent + "%";
                    302:         String r = "remaining " + rr + " sets at (%) ";
                    303:         String s = " " + sum_percent + "%";
                    304: 
                    305:         //Set up default layout constraints.
                    306:         c.fill = GridBagConstraints.NONE;
                    307: 
                    308:         Label tL = new Label(t, Label.LEFT);
                    309:         // c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row.
                    310:         c.gridwidth = 1;
                    311:         c.gridx = 0;
                    312:         c.gridy = 0;
                    313:         gridbag.setConstraints(tL, c);
                    314:         add(tL);
                    315:         
                    316:         Label cL = new Label(cs, Label.CENTER);
                    317:         c.gridwidth = 2;
                    318:         c.gridx = 1;
                    319:         c.gridy = 0;
                    320:         gridbag.setConstraints(cL, c);
                    321:         add(cL);
                    322: 
                    323:         Label sL = new Label("subtotal=", Label.RIGHT);
                    324:         c.gridwidth = 1;
                    325:         c.gridx = 3;
                    326:         c.gridy = 0;
                    327:         gridbag.setConstraints(sL, c);
                    328:         add(sL);
                    329: 
                    330:         sumL = new Label(s, Label.RIGHT);
                    331:         c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row.
                    332:         c.gridx = 4;
                    333:         c.gridy = 0;
                    334:         gridbag.setConstraints(sumL, c);
                    335:         add(sumL);
                    336:         if(x==1) { 
                    337:           Label rL = new Label(r, Label.RIGHT);
                    338:           c.gridwidth = 2;
                    339:           c.gridx = 0;
                    340:           c.gridy = 1;
                    341:           gridbag.setConstraints(rL, c);
                    342:           add(rL);
                    343: 
                    344:           exT = new TextField("0", 3);
                    345:           c.anchor = GridBagConstraints.EAST;
                    346:           c.gridwidth = 1; //The default value.
                    347:           c.gridx = 2;
                    348:           c.gridy = 1;
                    349:           gridbag.setConstraints(exT, c);
                    350:           add(exT);
                    351:           exT.addActionListener(this);
                    352:           c.anchor = GridBagConstraints.CENTER;  // default
                    353: 
                    354:         //Add the slider.  It's horizontal, and it has the maximum
                    355:         //value specified by the instance variable max.  Its initial
                    356:         //and minimum values are the default (0).  A click increments
                    357:         //the value by block units.
                    358:           sB = new Scrollbar(Scrollbar.HORIZONTAL);
                    359:           sB.setMaximum(max + 10);
                    360:           sB.setBlockIncrement(block);
                    361:           // c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row.
                    362:           c.fill = GridBagConstraints.HORIZONTAL;
                    363:           c.gridwidth = 2;
                    364:           c.gridx = 3;
                    365:           c.gridy = 1;
                    366:           gridbag.setConstraints(sB, c);
                    367:           add(sB);
                    368:           sB.addAdjustmentListener(this);
                    369:           exT.setText(String.valueOf(sf_percent));
                    370:           sB.setValue((int)sf_percent);
                    371:         }
                    372: 
                    373:     }
                    374:     // Draws a box around this panel. 
                    375:     public void paint(Graphics g) {
                    376:         Dimension d = getSize();
                    377:         g.drawRect(0,0, d.width - 1, d.height - 1);
                    378:     }
                    379:     public Insets getInsets() {
                    380:         return new Insets(5,5,5,8);
                    381:     }
                    382:     float  getSubTotal() {
                    383:         String s_str = sumL.getText().replace('%','\0').trim();
                    384:         float  s_real = Float.valueOf(s_str).floatValue();
                    385:         return (s_real);
                    386:     }
                    387:     double getValue() {
                    388:         double f;
                    389:         try {
                    390:             f = (double)Double.valueOf(exT.getText()).doubleValue();
1.3       albertel  391: 	    if (f > max) {f=max;}
1.2       albertel  392:         } catch (java.lang.NumberFormatException e) {
                    393:             f = 0.0;
                    394:         }
                    395:         return f;
                    396:     }
                    397:     // entered into exT
                    398:     public void actionPerformed(ActionEvent e) {
                    399:         int tf = (int) getValue();
                    400:         if (tf > max)
                    401:             tf = max;
                    402:         if (tf < 0)
                    403:             tf = 0;
                    404:         sB.setValue(tf);
                    405:         exT.setText(String.valueOf((int)tf));
                    406:         recalcSumm(tf);
                    407:     }    
                    408:     //  slider sB changed
                    409:     public void adjustmentValueChanged(AdjustmentEvent e) {
                    410:         Scrollbar source = (Scrollbar)e.getSource();
                    411:            int   my_i =  (int)source.getValue();
                    412:            exT.setText(String.valueOf(e.getValue()));
                    413:            recalcSumm(my_i);
                    414:     }
                    415:     void  recalcSumm(int tf) {
                    416:         float my_r = (float) tf / (float)100.0;
1.3       albertel  417:         int  tmp_i= (int)(10000*(ss+((float)rr*ff*my_r/(cc+rr)))/(float)(ff*(1.0+(float)rr/(cc+rr))));
                    418: 	//System.out.print("ss ="+ss+":rr="+rr+":ff="+ff+":my_r="+my_r+":cc="+cc+":tmp_i="+((float)tmp_i/10000.0)+"\n");
1.2       albertel  419:         float sum  = (float)tmp_i / (float)100.0;
                    420:         sumL.setText(sum + "%");
                    421:         controller.recalcTermScore();
                    422:     }
                    423:     // Set the values in the slider and text field. 
                    424:     void setValue(double f) {
                    425:         setSliderValue(f);
                    426:         exT.setText(String.valueOf((float)f));
                    427:     }
                    428:     void setSliderValue(double f) {
                    429:         int sliderValue = (int)f;
                    430: 
                    431:         if (sliderValue > max)
                    432:                sliderValue = max;
                    433:         if (sliderValue < 0)
                    434:             sliderValue = 0;
                    435:         sB.setValue(sliderValue);
                    436:         
                    437:     }
                    438: }
                    439: class ExmPanel extends Panel
                    440:                      implements ActionListener,
                    441:                                 AdjustmentListener {
                    442:     TScore     controller;
                    443:     TextField  exT_ex, exT_pc;
                    444:     Scrollbar  sB_ex,  sB_pc;
                    445:     Label      sumL;
                    446:     int        max = 100;
                    447:     int        block = 1;
                    448:     int        show_pc, exam_ex, epc_ex;
                    449:     float      s_ex, f_ex, s_pc, f_pc;
                    450:     float      c_factor;
                    451: 
                    452:     // exam_type  0  Final
                    453:     //            1, 2, 3, 4 
                    454:     ExmPanel(TScore u,int exam_type,int exam_x,int show_epc,int epc_x,
                    455:              float a,float b,float w,float m,float n,float ex_default) {
                    456:         GridBagConstraints   c = new GridBagConstraints();
                    457:         GridBagLayout        gridbag = new GridBagLayout();
                    458:         setLayout(gridbag);
                    459:         Label  tL;
                    460:         float  exam_ratio, epc_ratio;
                    461:         float  sum;
                    462:         int    tmp_i;
                    463: 
                    464:         controller = u; 
                    465:         c_factor   = w;
                    466:         show_pc = show_epc;
                    467:         exam_ex = exam_x;
                    468:         epc_ex  = epc_x;
                    469:         s_ex = a; f_ex = b; s_pc = m; f_pc = n;
                    470:         //Set up default layout constraints.
                    471:         c.fill = GridBagConstraints.NONE;
                    472: 
                    473:         //Add the label.  It displays this panel's title, centered.
                    474:         if(exam_type == 0 ) { // Final exam
                    475:            tL = new Label("Final", Label.LEFT);
                    476:         } else {
                    477:            tL = new Label("Exam " + exam_type, Label.LEFT);
                    478:         }
                    479:         c.anchor = GridBagConstraints.WEST;
                    480:         c.gridwidth = 1;
                    481:         c.gridx = 0;
                    482:         c.gridy = 0;
                    483:         gridbag.setConstraints(tL, c);
                    484:         add(tL);
                    485:         c.anchor = GridBagConstraints.CENTER;
                    486: 
                    487:         if( exam_x == 0 ) {
                    488:           // exam not extrapolated
1.3       albertel  489: 	  if ((float)f_ex < 0.00000001) {
                    490: 	      exam_ratio = (float) 0.0;
                    491: 	  } else {
                    492: 	      exam_ratio = (float)s_ex / (float)f_ex;
                    493: 	  }
1.2       albertel  494:           tmp_i = (int) (10000 * exam_ratio );
                    495:           float percent = (float)tmp_i / (float)100.0;
                    496:           String cs =  " " + a + "/" + b + " = " + percent + " %";
                    497:           Label  cL = new Label(cs, Label.CENTER);
                    498:           c.gridwidth = 2;
                    499:           c.gridx = 1;
                    500:           c.gridy = 0;
                    501:           gridbag.setConstraints(cL, c);
                    502:           add(cL);
                    503:         } else {
                    504:           // extrapolate exam
                    505:           exam_ratio = ex_default;
                    506:           exT_ex = new TextField("0", 3);
                    507:           exT_ex.setName("EXAM");
                    508:           c.gridwidth = 1; //The default value.
                    509:           c.gridx = 2;
                    510:           c.gridy = 0;
                    511:           gridbag.setConstraints(exT_ex, c);
                    512:           add(exT_ex);
                    513:           exT_ex.addActionListener(this);
                    514: 
                    515:           sB_ex = new Scrollbar(Scrollbar.HORIZONTAL);
                    516:           sB_ex.setName("EXAMS");
                    517:           sB_ex.setMaximum(max + 10);
                    518:           sB_ex.setBlockIncrement(block);
                    519:           c.gridwidth = 2;
                    520:           c.gridx = 3;
                    521:           c.gridy = 0;
                    522:           gridbag.setConstraints(sB_ex, c);
                    523:           add(sB_ex);
                    524:           sB_ex.addAdjustmentListener(this);
                    525:         }
                    526:         epc_ratio = exam_ratio;
                    527:         if(show_pc == 1) {
                    528:           if(epc_x == 1) {
                    529:             epc_ratio = exam_ratio;
                    530:           } else {
                    531:             epc_ratio = (float)s_pc / (float)f_pc;
                    532:           }
                    533:           if( epc_ratio > exam_ratio ) {
                    534:             tmp_i= (int)(10000 * (exam_ratio + c_factor * (epc_ratio - exam_ratio)));
                    535:             sum  = (float)tmp_i / (float)100.0;
                    536:           } else {
                    537:             tmp_i= (int)(10000 * exam_ratio);
                    538:             sum  = (float)tmp_i / (float)100.0;
                    539:           }
                    540:         } else { 
                    541:           tmp_i= (int)(10000 * exam_ratio);
                    542:           sum  = (float)tmp_i / (float)100.0;
                    543:         }
                    544: 
                    545:         Label sL = new Label("subtotal=", Label.RIGHT);
                    546:         c.gridwidth = 1;
                    547:         c.gridx = 5;
                    548:         c.gridy = 0;
                    549:         gridbag.setConstraints(sL, c);
                    550:         add(sL);
                    551: 
                    552:         String  s = " " + sum + "%";
                    553:         sumL = new Label(s, Label.CENTER);
                    554:         c.anchor = GridBagConstraints.EAST; 
                    555:         c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row.
                    556:         c.gridx = 6;
                    557:         c.gridy = 0;
                    558:         gridbag.setConstraints(sumL, c);
                    559:         add(sumL);
                    560:         c.anchor = GridBagConstraints.CENTER; 
                    561: 
                    562:         if( show_epc == 1 ) {
                    563:            Label eL = new Label("Correction " + exam_type, Label.LEFT);
                    564:            c.gridwidth = 1;
                    565:            c.gridx = 0;
                    566:            c.gridy = 1;
                    567:            gridbag.setConstraints(eL, c);
                    568:            add(eL);
                    569:            if( epc_x == 0 ) {
1.3       albertel  570: 	     float ratio;
                    571: 	     if ((float)f_pc < 0.00000001) {
                    572: 		 ratio = (float) 0.0;
                    573: 	     } else {
                    574: 		 ratio = (float) ( s_pc / f_pc);
                    575: 	     }
1.2       albertel  576:              tmp_i = (int) (10000 * ratio );
                    577:              float percent = (float)tmp_i / (float)100.0;
                    578:              String cs =  " " + s_pc + "/" + f_pc + " = " + percent + " %";
                    579:              Label  cL = new Label(cs, Label.CENTER);
                    580:              c.gridwidth = 2;
                    581:              c.gridx = 1;
                    582:              c.gridy = 1;
                    583:              gridbag.setConstraints(cL, c);
                    584:              add(cL);
                    585:            } else {
                    586:              exT_pc = new TextField("0", 3);
                    587:              exT_pc.setName("PC");
                    588:              c.anchor = GridBagConstraints.EAST;
                    589:              c.gridwidth = 1; //The default value.
                    590:              c.gridx = 2;
                    591:              c.gridy = 1;
                    592:              gridbag.setConstraints(exT_pc, c);
                    593:              add(exT_pc);
                    594:              exT_pc.addActionListener(this);
                    595: 
                    596:              sB_pc = new Scrollbar(Scrollbar.HORIZONTAL);
                    597:              sB_pc.setName("PCS");
                    598:              sB_pc.setMaximum(max + 10);
                    599:              sB_pc.setBlockIncrement(block);
                    600:              c.gridwidth = GridBagConstraints.REMAINDER;
                    601:              c.anchor = GridBagConstraints.CENTER;
                    602:              c.fill = GridBagConstraints.HORIZONTAL;
                    603:              // c.gridwidth = 2;
                    604:              c.gridx = 3;
                    605:              c.gridy = 1;
                    606:              gridbag.setConstraints(sB_pc, c);
                    607:              add(sB_pc);
                    608:              sB_pc.addAdjustmentListener(this);
                    609:            }
                    610:         }
                    611:         setExValue(exam_ratio,epc_ratio);
                    612:     }
                    613:     // Draws a box around this panel. 
                    614:     public void paint(Graphics g) {
                    615:         Dimension d = getSize();
                    616:         g.drawRect(0,0, d.width - 1, d.height - 1);
                    617:     }
                    618:     public Insets getInsets() {
                    619:         return new Insets(5,5,5,8);
                    620:     }
                    621:     float  getSubTotal() {
                    622:         String s_str = sumL.getText().replace('%','\0').trim();
                    623:         float  s_real = Float.valueOf(s_str).floatValue();
                    624:         return (s_real);
                    625:     }
                    626:     // entered into exT
                    627:     public void actionPerformed(ActionEvent e) {
                    628:         TextField source = (TextField)e.getSource();
                    629:         String name = source.getName();
                    630:         int tf = (int)Integer.valueOf(source.getText()).intValue();
                    631:         if (tf > max)
                    632:             tf = max;
                    633:         if (tf < 0)
                    634:             tf = 0;
                    635:         if( name.equals(String.valueOf("EXAM")) ) {
                    636:           sB_ex.setValue(tf);
                    637:           exT_ex.setText(String.valueOf((int)tf));
                    638:         } else {
                    639:           sB_pc.setValue(tf);
                    640:           exT_pc.setText(String.valueOf((int)tf));
                    641:         }
                    642:         recalcSumm();
                    643:     }    
                    644:     //  slider sB changed
                    645:     public void adjustmentValueChanged(AdjustmentEvent e) {
                    646:         Scrollbar source = (Scrollbar)e.getSource();
                    647:         String    name = source.getName();
                    648:            int    my_i =  (int)source.getValue();
                    649:         
                    650:         if( name.equals(String.valueOf("EXAMS")) ) {
                    651:           sB_ex.setValue(my_i);
                    652:           exT_ex.setText(String.valueOf((int)my_i));
                    653:         } else {
                    654:           sB_pc.setValue(my_i);
                    655:           exT_pc.setText(String.valueOf((int)my_i));
                    656:         }
                    657:         recalcSumm();
                    658:     }
                    659:     void  recalcSumm() {
                    660:         int   tmp_i;
                    661:         float exam , epc, sum;
                    662:         
                    663:         if( exam_ex == 1 ) {
                    664:            tmp_i = (int)Integer.valueOf(exT_ex.getText()).intValue();
                    665:            exam = (float) tmp_i / (float)100.0;
                    666:         } else {
                    667:            exam = (float)s_ex / (float)f_ex;
                    668:         }
                    669:         if( show_pc == 1 ) {
                    670:           if(epc_ex == 1) {
                    671:             tmp_i = (int)Integer.valueOf(exT_pc.getText()).intValue();
                    672:             epc = (float) tmp_i / (float)100.0;
                    673:           } else {
                    674:             epc = (float)s_pc / (float)f_pc;
                    675:           }
                    676:           if( epc > exam ) {
                    677:             tmp_i= (int)(10000 * (exam + c_factor * (epc - exam)));
                    678:             sum  = (float)tmp_i / (float)100.0;
                    679:           } else {
                    680:             tmp_i= (int)(10000 * exam);
                    681:             sum  = (float)tmp_i / (float)100.0;
                    682:           }
                    683:         } else {
                    684:           tmp_i= (int)(10000 * exam);
                    685:           sum  = (float)tmp_i / (float)100.0;
                    686:         }
                    687:         sumL.setText(sum + "%");
                    688:         controller.recalcTermScore();
                    689:     }
                    690:     void setExValue (float a, float b) {
                    691:         int  exm, epc;
                    692:         exm = (int) (a*100.0); 
                    693:         epc = (int) (b*100.0); 
                    694:         if (exm > max)
                    695:             exm = max;
                    696:         if (exm < 0)
                    697:             exm = 0;
                    698:         if (epc > max)
                    699:             epc = max;
                    700:         if (epc < 0)
                    701:             epc = 0;
                    702:         if( exam_ex ==1 ) {
                    703:           sB_ex.setValue(exm);
                    704:           exT_ex.setText(String.valueOf(exm));
                    705:         }
                    706:         if( (show_pc == 1) && (epc_ex==1) ) {
                    707:           sB_pc.setValue(epc);
                    708:           exT_pc.setText(String.valueOf(epc));
                    709:         }
                    710:      }
                    711: }
                    712: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.