Write a two class solution that includes data members for the name of the course, current enrollment, and maximum enrollment. Include an instance method that returns the number of students that can still enroll in the course. The To String( ) method should return the name of the course, current enrollment, and the number of open slots. Design your solution using parallel arrays. Declare an array of class objects in your implementation class.
internal class Program
{
class Course
{
public string NameOfTheCurse { get; set; }
public int CurrentEnrollment { get; set; }
public int MaxEnrollment { get; set; }
public Course(string name, int current, int max)
{
NameOfTheCurse = name;
CurrentEnrollment = current;
MaxEnrollment = max;
}
public override string ToString()
{
return $"Name of the curse: {NameOfTheCurse}, Current enrollment: {CurrentEnrollment}, " +
$"Number of available places: {MaxEnrollment - CurrentEnrollment} ";
}
}
static void Main(string[] args)
{
string[] nameOfCurse = new string[] { "Ab", "Ba", "Cw" };
int[] currentEnrollment = new int[] { 50, 61, 57 };
int[] maxEnrollment = new int[] { 100, 100, 100 };
Course[] courses = new Course[3];
for (int i = 0; i < courses.Length; i++)
{
courses[i] = new Course(nameOfCurse[i], currentEnrollment[i], maxEnrollment[i]);
Console.WriteLine(courses[i]);
}
Console.ReadKey();
}
}
Comments
Leave a comment