////////////////////////////////////////////// // // Grades.java // // LIS 533 Spring 1998 // // Calculates grades for LIS503 and LIS528 // /////////////////////////////////////////////// import java.awt.*; import java.applet.*; public class Grades extends Applet { ////////////////////////////////////////////// // // Labels and weights for each course ////////////////////////////////////////////// // // 503 double w1 = 1.0; String s1 = "1st Quiz "; double w2 = 1.0; String s2 = "2nd Quiz "; double w3 = 2.0; String s3 = "Final "; double w4 = 1.0; String s4 = "Project "; ///////////////////////////////////////////// // // 528 double w5 = 1.0; String s5 = "DataStar "; double w6 = 1.0; String s6 = "WWW "; double w7 = 1.0; String s7 = "Gold Std "; double w8 = 1.0; String s8 = "Targ/FS "; ////////////////////////////////////////////////// // // Grade Scales for each course ////////////////////////////////////////////////// // // 503 public static String _503_Scale(double score) { String grade = "Default"; if (score <= 2.0) grade = "4.0"; if (score >= 3.0 && score <= 4.0) grade = "3.9"; if (score >= 5.0 && score <= 6.0) grade = "3.8"; if (score >= 7.0 && score <= 8.0) grade = "3.7"; if (score >= 9.0 && score <= 10.0) grade = "3.6"; if (score >= 11.0 && score <= 12.00) grade = "3.5"; if (score >= 13.0 && score <= 14.00) grade = "3.4"; if (score >= 15.0 && score <= 16.00) grade = "3.3"; if (score >= 17.0 && score <= 18.00) grade = "3.2"; if (score >= 19.0 && score <= 20.00) grade = "3.1"; if (score >= 21.0 && score <= 22.00) grade = "3.0"; if (score >= 23.0 && score <= 24.00) grade = "2.9"; if (score >= 25.0 && score <= 26.00) grade = "2.8"; if (score >= 27.00 && score <= 28.00) grade = "2.7"; if (score >= 29.00 && score <= 30.00) grade = "2.6"; if (score >= 31.00 && score <= 33.00) grade = "2.5"; if (score >= 34.00 && score <= 37.00) grade = "2.4"; if (score >= 38.00 && score <= 41.00) grade = "2.3"; if (score >= 42.00 && score <= 45.00) grade = "2.2"; if (score >= 46.00 && score <= 49.00) grade = "2.1"; if (score >= 50.0) grade = "2.0"; return grade; } // _503_Scale ///////////////////////////////////////////////////// // // 528 scale public static String _528_Scale(double score) { String grade = "Default"; if (score <= 3.0) grade = "4.0"; if (score > 3.0 && score <= 5.0) grade = "3.8"; if (score > 5.0 && score <= 8.0) grade = "3.6"; if (score > 8.0 && score <= 11.0) grade = "3.4"; if (score > 11.0 && score <= 15.0) grade = "3.1"; if (score > 15.0) grade = "3.0"; return grade; } // _528_Scale /////////////////////////////////////////////////// // // Method to change User_input to a double public double convertTodouble(String User_input) { double converted; try { Double d = Double.valueOf(User_input); converted = d.doubleValue(); } catch(NumberFormatException e) // User has entered { // something other than converted = 0.0; // a number d = true; } return converted; } // convertToDouble /////////////////////////////////////////////////////// // // Method to change User_input to an integer public int convertToInteger(String User_input) { int i; try { i = Integer.parseInt(User_input); } catch(NumberFormatException e) // User has entered { // something other than i = 0; // a number d = true; } return i; } // convertToInteger ///////////////////////////////////////////////////// // // Declarations Panel BackPanel = new Panel(); Panel aPanel = new Panel(); Panel bPanel = new Panel(); Button set503, set528, compute, clear; String course = "none"; boolean d = false; Label one, two, four, five, total, grade; TextField t1, t2, t3, t4; //////////////////////////////////////////////////// // // init public void init() { setLayout(new BorderLayout()); BackPanel.setLayout(new FlowLayout()); BackPanel.setBackground(Color.cyan); add("Center",BackPanel); aPanel.setLayout(new GridLayout(2,2)); set503 = new Button("503 Labels"); aPanel.add(set503); set528 = new Button("528 Labels"); aPanel.add(set528); compute = new Button("Compute"); compute.disable(); aPanel.add(compute); clear = new Button("Clear"); aPanel.add(clear); BackPanel.add(aPanel); bPanel.setLayout(new GridLayout(2,6)); one = new Label(""); one.setAlignment(Label.RIGHT); one.setBackground(Color.cyan); bPanel.add(one); t1 = new TextField("0",5); bPanel.add(t1); two = new Label(""); two.setAlignment(Label.RIGHT); two.setBackground(Color.cyan); bPanel.add(two); t2 = new TextField("0",5); bPanel.add(t2); Label three = new Label("Total "); three.setAlignment(Label.RIGHT); three.setBackground(Color.cyan); bPanel.add(three); total = new Label("0"); total.setAlignment(Label.RIGHT); total.setBackground(Color.cyan); bPanel.add(total); four = new Label(""); four.setAlignment(Label.RIGHT); four.setBackground(Color.cyan); bPanel.add(four); t3 = new TextField("0",5); bPanel.add(t3); five = new Label(""); five.setAlignment(Label.RIGHT); five.setBackground(Color.cyan); bPanel.add(five); t4 = new TextField("0",5); bPanel.add(t4); Label six = new Label("Grade "); six.setAlignment(Label.RIGHT); six.setBackground(Color.cyan); bPanel.add(six); grade = new Label("0"); grade.setAlignment(Label.RIGHT); grade.setBackground(Color.cyan); bPanel.add(grade); bPanel.setBackground(Color.cyan); BackPanel.add(bPanel); } // init public boolean action(Event e, Object arg) { ////////////////////////////////////////////////// // // User requests 503 labels if ("503 Labels".equals(arg)) { one.setText(s1); two.setText(s2); four.setText(s3); five.setText(s4); validate(); course = "503"; compute.enable(); return true; } // 503 /////////////////////////////////////////////////////// // // User requests 528 labels if ("528 Labels".equals(arg)) { one.setText(s5); two.setText(s6); four.setText(s7); five.setText(s8); validate(); course = "528"; compute.enable(); return true; } // 528 /////////////////////////////////////////////////// // // User requests clearing of entries if ("Clear".equals(arg)) { t1.setText("0"); t2.setText("0"); t3.setText("0"); t4.setText("0"); total.setText("0"); grade.setText("0"); d = false; grade.setBackground(Color.cyan); grade.setAlignment(Label.RIGHT); validate(); return true; } //clear //////////////////////////////////////////////////////// // // Doing the computations String User_input; double Result; int Sum; ////////////////////////////////////////////////////// // // 503 if ("Compute".equals(arg) && course.equals("503")) { Sum = 0; User_input = t1.getText(); Result = convertTodouble(User_input) * w1; Sum = convertToInteger(User_input); User_input = t2.getText(); Result += convertTodouble(User_input) * w2; Sum += convertToInteger(User_input); User_input = t3.getText(); Result += convertTodouble(User_input) * w3; Sum += convertToInteger(User_input); User_input = t4.getText(); Result += convertTodouble(User_input) * w4; Sum += convertToInteger(User_input); if (d) { total.setText(""); grade.setBackground(Color.red); grade.setAlignment(Label.CENTER); grade.setText("Default"); } else { total.setText(String.valueOf(Sum)); grade.setText(_503_Scale(Result)); } return true; } // Compute 503 grade ///////////////////////////////////////////////////////// // // 528 if ("Compute".equals(arg) && course.equals("528")) { Sum = 0; User_input = t1.getText(); Result = convertTodouble(User_input) * w5; Sum = convertToInteger(User_input); User_input = t2.getText(); Result = Result + convertTodouble(User_input) * w6; Sum += convertToInteger(User_input); User_input = t3.getText(); Result = Result + convertTodouble(User_input) * w7; Sum += convertToInteger(User_input); User_input = t4.getText(); Result = Result + convertTodouble(User_input) * w8; Sum += convertToInteger(User_input); if (d) { total.setText(""); grade.setBackground(Color.red); grade.setAlignment(Label.CENTER); grade.setText("Default"); } else { total.setText(String.valueOf(Sum)); grade.setText(_528_Scale(Result)); } return true; } // Compute 528 grade return false; } // action } // Grades