Commit ef032b71 authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

Updated with classes

parent c553c510
Loading
Loading
Loading
Loading

.idea/uiDesigner.xml

0 → 100644
+124 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="Palette2">
    <group name="Swing">
      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
      </item>
      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
      </item>
      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
      </item>
      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
      </item>
      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
        <initial-values>
          <property name="text" value="Button" />
        </initial-values>
      </item>
      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
        <initial-values>
          <property name="text" value="RadioButton" />
        </initial-values>
      </item>
      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
        <initial-values>
          <property name="text" value="CheckBox" />
        </initial-values>
      </item>
      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
        <initial-values>
          <property name="text" value="Label" />
        </initial-values>
      </item>
      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
          <preferred-size width="150" height="-1" />
        </default-constraints>
      </item>
      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
          <preferred-size width="150" height="-1" />
        </default-constraints>
      </item>
      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
          <preferred-size width="150" height="-1" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
      </item>
      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
          <preferred-size width="200" height="200" />
        </default-constraints>
      </item>
      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
          <preferred-size width="200" height="200" />
        </default-constraints>
      </item>
      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
      </item>
      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
      </item>
      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
      </item>
      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
      </item>
      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
          <preferred-size width="-1" height="20" />
        </default-constraints>
      </item>
      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
      </item>
      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
      </item>
    </group>
  </component>
</project>
 No newline at end of file
+52 −0
Original line number Diff line number Diff line
package edu.bu.quizzes;

import edu.bu.quizzes.grades.LetterGrade;
import edu.bu.quizzes.grades.NumberGrade;
import edu.bu.quizzes.grades.basic_grade;
import edu.bu.quizzes.students.Student;

import java.util.Date;

/**
 * Represents a grade assigned to a student
 */
public class AssignedGrade {
    /**
     * Assigns a grade to a student.
     * @param theStudName The name of the student.
     * @param theStudID The ID of the student.
     * @param theGrade A string representing the grade of the student.
     * @throws CannotAssignException if the grade cannot be assigned to the student.
     */
    public AssignedGrade(String theStudName, Long theStudID, String theGrade) throws CannotAssignException {

        stud = new Student()
                .setName(theStudName)
                .setID(theStudID)
                .setEnrolled(new Date());

        basic_grade tempGrade;
        // try to read the grade as a letter grade
        try {
            tempGrade = LetterGrade.fromString(theGrade);
        } catch (basic_grade.CannotCreate e) {
            // ... that didn't work; try to read the grade as a number grade
            try {
                tempGrade = NumberGrade.fromString(theGrade);
            } catch (basic_grade.CannotCreate ex) {
                throw new CannotAssignException();
            }
        }
        grade = tempGrade;
    }

    /**
     * Indicates that grade assignment failed.
     */
    public class CannotAssignException extends Throwable {
    }

    final public Student stud;
    final public basic_grade grade;

}
+75 −0
Original line number Diff line number Diff line
package edu.bu.quizzes;

import edu.bu.quizzes.grades.basic_grade;

import java.util.Vector;

/**
 * Represents a classroom of students with assigned grades.
 */
public class ClassRoom {
    final static ClassRoom theClass = new ClassRoom();

    /**
     * Constructs a class.
     */
    private ClassRoom() {
    }

    static public ClassRoom getClassRoom() {
        return theClass;
    }

    /**
     * Assigns a student to a grade.
     * @param studName The name of the student.
     * @param studID The ID number of the student.
     * @param studGrade The grade of the student.
     * @return true iff the assignment succeeded.
     */
    public boolean addGrade(String studName, Long studID, String studGrade) {
        try {
            assignedGrades.add(new AssignedGrade(studName, studID, studGrade));
        } catch (AssignedGrade.CannotAssignException e) {
            return false;
        }
        return true;
    }

    /**
     * @param studName The name of the student to find.
     * @return The grade of the given student
     * @throws StudentNotFoundException If the student is not found in this classroom.
     */
    public basic_grade getGrade(String studName) throws StudentNotFoundException {
        for (AssignedGrade ag: assignedGrades) {
            // does the name match to the name in the assigned grades?
            if (ag.stud.getName().compareTo(studName) == 0)
                return ag.grade;
        }
        throw new StudentNotFoundException();
    }

    /**
     * @param studID The ID of the student to find.
     * @return The grade of the given student
     * @throws StudentNotFoundException If the student is not found in this classroom.
     */
    public basic_grade getGrade(Long studID) throws StudentNotFoundException {
        for (AssignedGrade ag: assignedGrades) {
            // does the name match to the name in the assigned grades?
            if (ag.stud.getID() == studID)
                return ag.grade;
        }
        throw new StudentNotFoundException();
    }

    /**
     * Notes that a student was not found.
     */
    public class StudentNotFoundException extends Throwable {
    }

    Vector<AssignedGrade> assignedGrades = new Vector<>();

}
+11 −1
Original line number Diff line number Diff line
@@ -2,6 +2,16 @@ package edu.bu.quizzes;

public class Main {
    static public void main(String[] args) {
        System.out.println("Hello World");
        ClassRoom CR = ClassRoom.getClassRoom();
        CR.addGrade("Joe",1111111111L, "A");
        CR.addGrade("Jen",2222222222L, "100");
        CR.addGrade("Jane",3333333333L, "79");

        try {
            System.out.println("Jane got " + CR.getGrade("Jane"));
            System.out.println("Student " + 1111111111L + " got " + CR.getGrade(1111111111L));
        } catch (ClassRoom.StudentNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
+14 −0
Original line number Diff line number Diff line
package edu.bu.quizzes.grades;

public class GradeMaker {
    static basic_grade makeGrade(GradeType theGT, Object theGrade) {
        switch (theGT) {
            case Letter:
                return new LetterGrade((char) theGrade);
            case Number:
                return new NumberGrade((int) theGrade);
            default:
                throw new RuntimeException("Sorry, I cannot create that type of grade yet.");
        }
    }
}
 No newline at end of file
Loading