Question: C SHARP For this task you are provided with an EnrolmentManager class. The class is fully functional and will work if only valid data is

C SHARP

For this task you are provided with an EnrolmentManager class. The class is fully functional and will work if only valid data is passed to it. Your task is to take this program and make it throw some useful exceptions in those cases.

The following is a description of each method in EnrolmentManager, as well as the exceptions that it should throw (but currently doesn't):

public EnrolmentManager(int numClasses, int placesPerClass)

The constructor sets up enrolment for numClasses classes of up to placesPerClass students each. All of these classes will start out empty.

This constructor must throw an ArgumentOutOfRangeException if either parameter is less than or equal to 0.

public void EnrolStudent(string studentName, int classNum)

This method enrols the student with the name studentName in the class with the code classNum. Classes are indexed starting from 0, so valid class numbers go from 0 to numClasses - 1.

This constructor must throw an ArgumentOutOfRangeException when attempting to enrol a student in an invalid class number, and an ArgumentException when attempting to enrol a student in a class that is already full.

public int GetNumClasses()

This method returns the number of classes in the EnrolmentManager.

It should not throw any exceptions.

public int GetClassSize()

This method returns the maximum number of students that can be enrolled in any class.

It should not throw any exceptions.

public int GetNumEnrolments(int classNum)

This method returns the number of students currently enrolled in the given class.

This method must throw an ArgumentOutOfRangeException when given an invalid class number.

public string GetStudent(int classNum, int studentNum)

This method returns the name of student studentNum in class classNum. Both of these values are indexed starting from 0, so GetStudent(0, 0) retrieves the first student from the first class;

This method must throw an ArgumentOutOfRangeException when given an invalid class number, an ArgumentOutOfRangeException when given a negative student number, or an ArgumentException when given a student number that is invalid because there are insufficient students enrolled in the class for that number to be valid.

public void ListStudents(int classNum)

This method prints out a list of all the students in the given class, together with the total number of students in that class.

This method must throw an ArgumentOutOfRangeException when given an invalid class number.

public int GetFreeClass()

This method returns the number of classes in the EnrolmentManager.

It should not throw any exceptions.

For this exercise, you are not provided with a Main() method; you should write your own to test the modifications you've made to the EnrolmentManager class. Only the Enrolmentmanager class will be tested by AMS.

HERE IS THE PROVIDED CLASS.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Enrolment { public class EnrolmentManager { private List[] classes; private int maxClassSize;

public EnrolmentManager(int numClasses, int placesPerClass) { classes = new List[numClasses]; for (int classNum = 0; classNum < numClasses; classNum++) { classes[classNum] = new List(placesPerClass); } maxClassSize = placesPerClass; }

public void EnrolStudent(string studentName, int classNum) { classes[classNum].Add(studentName); } public int GetNumClasses() { return classes.Length; }

public int GetClassSize() { return maxClassSize; }

public int GetNumEnrolments(int classNum) { return classes[classNum].Count; }

public string GetStudent(int classNum, int studentNum) { return classes[classNum][studentNum]; }

public void ListStudents(int classNum) { Console.WriteLine("Students in class {0}:", classNum); foreach (string studentName in classes[classNum]) { Console.WriteLine("- {0}", studentName); } Console.WriteLine("Total of {0} students.", classes[classNum].Count); }

public int GetFreeClass() { for (int classNum = 0; classNum < classes.Length; classNum++) { if (classes[classNum].Count < maxClassSize) { return classNum; } } return -1; } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!