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