Answer to Question #340293 in C# for Naveen

Question #340293

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.



1
Expert's answer
2022-05-14T16:42:04-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 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();
        }
    }

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