Answer to Question #337810 in C# for SITHEMBELE

Question #337810

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. Test your application with the following data:


1
Expert's answer
2022-05-06T15:36:23-0400
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 int GetNumberFreePlace()
            {
                return MaxEnrollment - CurrentEnrollment;
            }


            public override string ToString()
            {
                return $"Name of the curse: {NameOfTheCurse}, Current enrollment {CurrentEnrollment}, Number of available places : {GetNumberFreePlace()} ";
            }
        }
        static void Main(string[] args)
        {
            string[] nameOfCurse = new string[] { "A", "B", "C" };
            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();
        }
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS