For this task you are given a partially-complete program- a program designed to show the number of enrolment positions open for each class, or display that the class is full if that is the case.
To finish this program, you must finish the DisplayClassEnrolment method.
The completed method should first display the text "Number of places still available for each class." followed by a blank line. Following this blank line, it should display one line of text for each class. That line should be of the following format:
"(class name) has (number of places left) places left."
The number of places left in each class is the maximum enrolment minus the current enrolment. If there are no places left (the current enrolment is the same as the maximum enrolment) this line should instead be displayed:
"(class name) is full."
A framework has been provided for your convenience in writing the program. The comments direct you to where you should insert your own code.
It is important that you display the exact same messages as in the example. If your program displays something else you may fail the exercise even if your program calculates the class enrolment correctly.
Sample code:
/* This program uses three parallel
* arrays to display the class name
* and how many places are left in that
* class.
*/
using System;
namespace ClassEnrolment {
class ClassEnrolment {
public static void Main() {
// A single test case is provided here for you, but you should consider trying some other test cases.
string[] classNames = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
int[] currentEnrolments = new int[] { 13, 8, 17, 16, 8 };
int[] maximumEnrolments = new int[] { 29, 23, 29, 22, 27 };
DisplayClassEnrolment(classNames, currentEnrolments, maximumEnrolments);
ExitProgram();
}
/// < summary>
/// Displays the number of places still available in an array of classes.
/// < /summary>
/// < param name="classNames">Names of the classes< /param>
/// < param name="currentEnrolments">Current enrolment in the classes, in an array aligned to classNames< /param>
/// < param name="maximumEnrolments">Maximum enrolment possible in the classes, in an array aligned to classNames< /param>
public static void DisplayClassEnrolment(string[] classNames, int[] currentEnrolments, int[] maximumEnrolments) {
Console.WriteLine("Number of places still available for each class.n");
// Write a "for" loop here, using the className.Length property.
// ...
// ...
// ...
}
/// < summary>
/// Prompts the user to press 'enter' to exit and waits for this.
/// < /summary>
public static void ExitProgram() {
Console.Write("Press enter to continue ...");
Console.ReadLine();
}
}
}