Beispiel #1
0
        public void addStudent(int id, String name, int grade, int grade2)
        {
            Student s = new UndergraduateStudent(id, name, grade, grade2);

            this.val.validateStudent(s);
            repo.addElement(s);
        }
Beispiel #2
0
 public Presentation()
 {
     InitializeComponent();
     // Instantiate the grad student
     gradStudent = new GraduateStudent("123", "Fesser", "Mike", "251 Keppoch Rd.", "9023671911", "C.I.S. Degree", "Holland College", "Charlottetown, P.E., Canada");
     // Instantiate the undergrad student with a bit of humour.
     undergraduate = new UndergraduateStudent("111", "Horror", "Rocky", "Oakley Court", "9991234567", "Junior", "Furter", "Frank", "Oakly Court", "9991234567");
     // Instantiate the List
     students = new List <Student>();
     // Add students to the List
     students.Add(gradStudent);
     students.Add(undergraduate);
 }
Beispiel #3
0
 public String addStudent(int id, String name, int grade, int grade2)
 {
     try
     {
         Student s = new UndergraduateStudent(id, name, grade, grade2);
         val.validateStudent(s);
         repo.addElement(s);
         return("Student added successfully!");
     }
     catch (MyException ex)
     {
         return(ex.getMessage());
     }
 }
Beispiel #4
0
 public String addStudent(int id, String name, int grade, int grade2)
 {
     try
     {
         Student s = new UndergraduateStudent(id, name, grade, grade2);
         val.validateStudent(s);
         repo.addElement(s);
         foreach (var observer in observers)
         {
             observer.OnNext(this.repo.getAllElements());
         }
         return("Student added successfully!");
     }
     catch (MyException ex)
     {
         return(ex.getMessage());
     }
 }
Beispiel #5
0
        protected void OnClickButton(object sender, EventArgs e)
        {
            String line = tbox.Text;

            String[] tokens = line.Split(' ');
            int      length = tokens.Length;

            try
            {
                switch (length)
                {
                case 3:
                    Student s1 = new Student(Convert.ToInt32(tokens[0]), tokens[1], Convert.ToInt32(tokens[2]));
                    c.repo.addObject(s1);
                    break;

                case 4:
                    UndergraduateStudent s2 = new UndergraduateStudent(Convert.ToInt32(tokens[0]), tokens[1], Convert.ToInt32(tokens[2]), Convert.ToInt32(tokens[3]));
                    c.repo.addObject(s2);
                    break;

                case 6:
                    GraduateStudent s3 = new GraduateStudent(Convert.ToInt32(tokens[0]), tokens[1], tokens[2], Convert.ToInt32(tokens[3]), Convert.ToInt32(tokens[4]), Convert.ToInt32(tokens[5]));
                    c.repo.addObject(s3);
                    break;

                case 7:
                    PhdStudent s4 = new PhdStudent(Convert.ToInt32(tokens[0]), tokens[1], tokens[2], tokens[3], Convert.ToInt32(tokens[4]), Convert.ToInt32(tokens[5]), Convert.ToInt32(tokens[6]));
                    c.repo.addObject(s4);
                    break;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }

            lbox.Items.Clear();
            foreach (Student s in c.getAll())
            {
                lbox.Items.Add(s.ToString());
            }
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            lblStatus.Text = "";

            string aName = txtName.Text;
            string aId   = txtID.Text;
            string major = txtMajor.Text;

            Student newStudent;

            int hours;

            if (!int.TryParse(txtCreditHours.Text, out hours) || hours < 0)
            {
                lblStatus.Text = "Credit hours not valid";
                txtCreditHours.Focus();
                return;
            }

            if (radUndergraduate.Checked)
            {
                string status = txtSpecial.Text;
                //instantiate newStudent
                newStudent = new UndergraduateStudent(aName, aId, major, hours, status);
            }
            else if (radGraduate.Checked)
            {
                string degree = txtSpecial.Text;
                newStudent = new GraduateStudent(aName, aId, major, hours, degree);
            }
            else
            {
                //instantiate newStudent
                newStudent = new AuditStudent(aName, aId, hours);
            }

            students.Add(newStudent);

            lblStatus.Text = "Student has been added";

            ClearInputs();
        }
Beispiel #7
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            students = new List <Student>();

            //Add students to list

            GraduateStudent gradStudent1 = new GraduateStudent("Joe Jones", "123", "BA", 36, "Computer Science");
            GraduateStudent gradStudent2 = new GraduateStudent("Miranda Merkler", "456", "BS", 30, "Computer Science");

            UndergraduateStudent undergradStudent1 = new UndergraduateStudent("Kathy Klum", "234", "BA", 120, "Probation");
            UndergraduateStudent undergradStudent2 = new UndergraduateStudent("Larry Lewis", "345", "BA", 30, "Satisfactory");

            AuditStudent auditStudent1 = new AuditStudent("Norman Nelson", "567", 0);
            AuditStudent auditStudent2 = new AuditStudent("Otto Olson", "678", 6);

            students.Add(gradStudent1);
            students.Add(gradStudent2);
            students.Add(undergradStudent1);
            students.Add(undergradStudent2);
            students.Add(auditStudent1);
            students.Add(auditStudent2);
        }
Beispiel #8
0
        public void readFromFile()
        {
            String line;

            String[] tokens;
            int      length;

            System.IO.StreamReader infile = new System.IO.StreamReader("studentlist.txt");
            while ((line = infile.ReadLine()) != null)
            {
                tokens = line.Split(' ');
                length = tokens.Length;
                switch (length)
                {
                case 3:
                    Student s1 = new Student(Convert.ToInt32(tokens[0]), tokens[1], Convert.ToInt32(tokens[2]));
                    repo.addObject(s1);
                    break;

                case 4:
                    UndergraduateStudent s2 = new UndergraduateStudent(Convert.ToInt32(tokens[0]), tokens[1], Convert.ToInt32(tokens[2]), Convert.ToInt32(tokens[3]));
                    repo.addObject(s2);
                    break;

                case 6:
                    GraduateStudent s3 = new GraduateStudent(Convert.ToInt32(tokens[0]), tokens[1], tokens[2], Convert.ToInt32(tokens[3]), Convert.ToInt32(tokens[4]), Convert.ToInt32(tokens[5]));
                    repo.addObject(s3);
                    break;

                case 7:
                    PhdStudent s4 = new PhdStudent(Convert.ToInt32(tokens[0]), tokens[1], tokens[2], tokens[3], Convert.ToInt32(tokens[4]), Convert.ToInt32(tokens[5]), Convert.ToInt32(tokens[6]));
                    repo.addObject(s4);
                    break;
                }
            }
            infile.Close();
        }
Beispiel #9
0
        public bool addMenu()  //Read parameters until they are correct
        {
            try
            {
                int select = 0;
                Console.WriteLine("Type: \n (1)Student \n (2)Graduate \n (3)Undergraduate \n (4)PHD");
                select = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("ID: ");
                String  sid, thesis, supervisor;
                int     id;
                int     grade2, grade3;
                Student s;
                string  input;
                input = Console.ReadLine();
                int.TryParse(input, out id);
                if (id == 0)
                {
                    throw new MyException("Wrong id");
                }

                Console.WriteLine("Name:");
                String name = Console.ReadLine();

                Console.WriteLine("Grade:");
                int grade = Convert.ToInt32(Console.ReadLine());
                this.valid.validateGrade(grade);
                this.valid.validateId(id);
                this.valid.validateName(name);
                switch (select)
                {
                case 1:
                    s = new Student(id, name, grade);
                    cont.addStudent(s);
                    break;

                case 2:
                    Console.WriteLine("Grade 2");
                    grade2 = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Grade 3");
                    grade3 = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Supervisor");
                    supervisor = Console.ReadLine();
                    this.valid.validateGrade(grade2);
                    this.valid.validateGrade(grade3);
                    s = new GraduateStudent(id, name, supervisor, grade, grade2, grade3);
                    cont.addStudent(s);
                    break;

                case 3:
                    Console.WriteLine("Grade2: ");
                    grade2 = Convert.ToInt32(Console.ReadLine());
                    this.valid.validateGrade(grade2);
                    s = new UndergraduateStudent(id, name, grade, grade2);
                    cont.addStudent(s);
                    break;


                case 4:
                    Console.WriteLine("Grade2: ");
                    grade2 = Convert.ToInt32(Console.ReadLine());
                    this.valid.validateGrade(grade2);
                    Console.WriteLine("Grade3: ");
                    grade3 = Convert.ToInt32(Console.ReadLine());
                    this.valid.validateGrade(grade3);
                    Console.WriteLine("Supervisor: ");
                    supervisor = Console.ReadLine();
                    Console.WriteLine("Thesis: ");
                    thesis = Console.ReadLine();
                    s      = new PhdStudent(id, name, thesis, supervisor, grade, grade2, grade3);
                    cont.addStudent(s);
                    break;
                }
                return(true);
            }
            catch (MyException e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }