Consider the following scenario: A landscape service has hired you to create a n
ID: 3798054 • Letter: C
Question
Consider the following scenario: A landscape service has hired you to create a new tracking system. They have 2 types of appointments: morning and afternoon. There are 5 appointments for morning and 5 for afternoon. Using an array, create a C# application that prompts the user for the appointment type (morning or afternoon) then reserves a slot of that type. The first 5 array slots are morning and the second 5 slots are afternoon. If there is no appointment of that type available, show a message telling the user that there is no appointment available. Your screenshot must show the appointment type request and the slot# assigned. Your application must test using the test cases shown below. Run all of the test cases in one execution of your application. Include the test prompts in your screenshot. At the beginning of your program, display your name and the assignment due date. Test cases:
1 Afternoon 2 Morning 3 Afternoon 4 Afternoon 5 Afternoon 6 Afternoon 7 Afternoon 8 Morning
Explanation / Answer
Code:
using System.IO;
using System;
class Program
{
static void Main()
{
//Console.WriteLine("Hello, World!");
int[] array=new int[10];
int mng=0,aft=5;
int slot;
string time;
while(true){
Console.WriteLine("Enter slot number and slot time(hit -1 & none to exit)");
slot=Convert.ToInt32(Console.ReadLine());
time=Console.ReadLine();
if(slot==-1)
break;
if(time == "Afternoon")
{
if(aft+1<11)
array[aft++]=slot;
else
Console.WriteLine("No slot available for this time");
}
else {
if(mng+1<5)
array[mng++]=slot;
else
Console.WriteLine("No slot available for this time");
}
}
}
}
Output:
Enter slot number and slot time(hit -1 & none to exit)
1
Afternoon
Enter slot number and slot time(hit -1 & none to exit)
2
Morning
Enter slot number and slot time(hit -1 & none to exit)
3
Afternoon
Enter slot number and slot time(hit -1 & none to exit)
4
Afternoon
Enter slot number and slot time(hit -1 & none to exit)
5
Afternoon
Enter slot number and slot time(hit -1 & none to exit)
6
Afternoon
Enter slot number and slot time(hit -1 & none to exit)
7
Afternoon
No slot available for this time
Enter slot number and slot time(hit -1 & none to exit)
8
Morning
Enter slot number and slot time(hit -1 & none to exit)
-1
none