Annotation of capa/capa51/JavaTools/TScore.java, revision 1.1
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();
! 87: SF_ratio[idx] = (float) ((float)S[idx] / (float)F[idx]);
! 88: int tmp_i = (int) (10000 * SF_ratio[idx] );
! 89: SF_percent[idx]= (float)tmp_i / (float)100.0;
! 90: if( idx == (Entry_cnt - 1) ) { // final exam
! 91: Sum_ratio[idx] = SF_ratio[idx];
! 92: Sum_percent[idx] = SF_percent[idx];
! 93: }
! 94: }
! 95: }
! 96: 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]));
! 97: int tmp_i = (int)(10000 * Sum_ratio[0]);
! 98: Sum_percent[0] = (float)tmp_i / (float)100.0;
! 99: Sum_ratio[0] = Sum_percent[0] / (float)100.0;
! 100: Sum_ratio[1] = (float)(S[1] + (R[1]*F[1]*SF_ratio[1]/C[1])) / (float)(F[1]*(1.0 + R[1]/C[1]));
! 101: tmp_i = (int)(10000 * Sum_ratio[1]);
! 102: Sum_percent[1] = (float)tmp_i / (float)100.0;
! 103: Sum_ratio[1] = Sum_percent[1] / (float)100.0;
! 104:
! 105:
! 106: // if exam 1 is not given, use homework as default to extrapolate
! 107: // if epc 1 is not given, use exam 1 as epc 1
! 108: // if exam 2 is not given, use exam 1 to extrapolate
! 109: // if exam 3 is not given, use exam 2 to extrapolate
! 110: //
! 111:
! 112: float exam_sum = (float)0.0;
! 113: for(idx=0;idx<Exam_cnt;idx++) {
! 114: if( X[(idx+1)*2] == 1 ) {
! 115: // taken from homework
! 116: Raw_exam_ratio[idx] = SF_ratio[0];
! 117: } else {
! 118: Raw_exam_ratio[idx] = SF_ratio[(idx+1)*2];
! 119: }
! 120: if( X[(idx+1)*2 + 1] == 1 ) {
! 121: Raw_epc_ratio[idx] = Raw_exam_ratio[idx];
! 122: } else {
! 123: Raw_epc_ratio[idx] = SF_ratio[(idx+1)*2 + 1];
! 124: }
! 125:
! 126: if( Raw_epc_ratio[idx] > Raw_exam_ratio[idx] ) {
! 127: Exam_ratio[idx] = Raw_exam_ratio[idx] + W[4]*( Raw_epc_ratio[idx] - Raw_exam_ratio[idx] ) ;
! 128: } else {
! 129: Exam_ratio[idx] = Raw_exam_ratio[idx];
! 130: }
! 131:
! 132: Sum_ratio[2*(idx+1)] = Exam_ratio[idx];
! 133: tmp_i = (int)(10000 * Exam_ratio[idx] );
! 134: Sum_percent[2*(idx+1)] = (float)tmp_i / (float)100.0;
! 135: Sum_ratio[2*(idx+1)] = Sum_percent[2*(idx+1)] / (float)100.0;
! 136: exam_sum += Exam_ratio[idx];
! 137: }
! 138: exam_sum = (float)exam_sum / (float)Exam_cnt;
! 139:
! 140: Term_score = Sum_ratio[0] * W[0] + Sum_ratio[1] * W[1] + exam_sum * W[2] + Sum_ratio[Entry_cnt - 1] * W[3];
! 141:
! 142: tmp_i = (int)(10000 * Term_score);
! 143: Term_score = (float)tmp_i / (float)100.0;
! 144:
! 145:
! 146: // call to setup User Interface
! 147:
! 148: initGUI();
! 149:
! 150: }
! 151: public void initGUI() {
! 152: int row_cnt = Exam_cnt + 4;
! 153: int idx;
! 154: String [] title = {"Homework", "Quizz" };
! 155: HQpanel = new ExpPanel[2];
! 156: EXpanel = new ExmPanel[Exam_cnt+2];
! 157:
! 158: setLayout(new GridLayout(row_cnt,0,4,4));
! 159:
! 160: String t_str = "Term Score Extrapolation Applet";
! 161: TitleL = new Label(t_str, Label.CENTER);
! 162: add(TitleL);
! 163:
! 164: for(idx = 0; idx < 2; idx++) {
! 165: HQpanel[idx] = new ExpPanel(this,title[idx],X[idx],
! 166: S[idx],F[idx],C[idx],R[idx]);
! 167: add(HQpanel[idx]);
! 168: }
! 169: // Midterm Exam
! 170: for(idx =0; idx < Exam_cnt; idx++) {
! 171: EXpanel[idx] = new ExmPanel(this,idx+1,X[2*(idx+1)],1,X[2*idx+3],
! 172: S[2*(idx+1)],F[2*(idx+1)],W[4],S[2*idx+3],F[2*idx+3],Sum_ratio[2*(idx+1)]);
! 173: add(EXpanel[idx]);
! 174: }
! 175: // Final Exam
! 176: EXpanel[Exam_cnt] = new ExmPanel(this,0,X[Entry_cnt-1],0,0,
! 177: S[Entry_cnt-1],F[Entry_cnt-1],W[3],S[Entry_cnt-1],F[Entry_cnt-1],Sum_ratio[Entry_cnt-1]);
! 178: add(EXpanel[Exam_cnt]);
! 179:
! 180: String eq_str = "Term score=" + Sum_percent[0] + "*" + W[0] ;
! 181: eq_str = eq_str + "+" + Sum_percent[1] + "*" + W[1] ;
! 182: eq_str = eq_str + "+" + "(" ;
! 183: for(idx =1;idx<=Exam_cnt;idx++) {
! 184: if(idx>1) {
! 185: eq_str = eq_str + "+ ";
! 186: }
! 187: eq_str = eq_str + Sum_percent[2*idx] ;
! 188: }
! 189: eq_str = eq_str + ") *" + W[2] + "/" + Exam_cnt + "+";
! 190: eq_str = eq_str + Sum_percent[2*idx] + "*" + W[3] + " = ";
! 191: eq_str = eq_str + " " + Term_score + "%";
! 192: // EqL = new Label(eq_str, Label.LEFT);
! 193: // add(EqL);
! 194:
! 195: }
! 196: public void recalcTermScore() {
! 197: float score[];
! 198: int idx;
! 199: float term_summ, exam_summ;
! 200:
! 201: score = new float[Exam_cnt+3];
! 202: term_summ = (float)0.0;
! 203: exam_summ = (float)0.0;
! 204: for(idx=0;idx<2;idx++) {
! 205: score[idx] = HQpanel[idx].getSubTotal();
! 206: term_summ = term_summ + score[idx] * W[idx];
! 207: }
! 208: for(idx =0; idx < Exam_cnt; idx++) {
! 209: score[idx+2] = EXpanel[idx].getSubTotal();
! 210: exam_summ = exam_summ + score[idx+2];
! 211: }
! 212: score[Exam_cnt+2] = EXpanel[Exam_cnt].getSubTotal();
! 213: exam_summ = exam_summ * W[2] / Exam_cnt;
! 214: term_summ = term_summ + exam_summ + score[Exam_cnt+2] * W[3];
! 215: int tmp_i = (int) ((float)100.0*term_summ);
! 216: term_summ = (float)(tmp_i / (float)100.0);
! 217: String eq_str = "Term score=" + score[0] + "*" + W[0] ;
! 218: eq_str = eq_str + "+" + score[1] + "*" + W[1] ;
! 219: eq_str = eq_str + "+" + "(" ;
! 220: for(idx=0;idx<Exam_cnt;idx++) {
! 221: if(idx>0) {
! 222: eq_str = eq_str + "+ ";
! 223: }
! 224: eq_str = eq_str + score[idx+2] ;
! 225: }
! 226: eq_str = eq_str + ") *" + W[2] + "/" + Exam_cnt + "+";
! 227: eq_str = eq_str + score[Exam_cnt+2] + "*" + W[3] + " = ";
! 228: eq_str = eq_str + " " + term_summ + " %";
! 229: // TitleL.setText("TTT");
! 230: TitleL.setText(eq_str);
! 231: }
! 232: public void paint(Graphics g) {
! 233: Dimension d = getSize();
! 234: g.drawRect(0,0, d.width - 1, d.height - 1);
! 235: }
! 236: public void run() { }
! 237: public void start() {
! 238: recalcTermScore();
! 239: }
! 240: public void stop() { }
! 241:
! 242: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>