如何将用户输入的值分配给特定的数组

  • 本文关键字:分配 数组 用户 c#
  • 更新时间 :
  • 英文 :


有两个模块。校长和告密者。班主任允许您为教师创建一周中某一天的时间表,将有多少节课,将有什么课,以及将有哪个教室。通知模块为所选教师生成一周中所选日期的时间表。也就是说,用户为老师创建了一周中某一天的时间表,在那里输入了课程、班级的数量,告密者必须在"告密者"中显示这些信息。模块。

如何分配选定的课程,以及将多少课程和教室分配给特定的教师?

static void Main(string[] args)
{
List<string> teachersForDirector = new List<string> { "Матвеева Н.В", "Ивашина А.С", "Изюмов Р.Н.", "Жиделев А.С.", "Карпов М.Д", "Петрова О.А", "Таран Г.Г.", "Овчарова Д.Е.", "Андреев Д.Е.", "Долгих Н.О." };
List<string> lessons = new List<string> { "Английский язык", "Математика", "Физ-ра", "ОБЖ", "Русский язык", "История", "Обществознание", "Физика", "Литература", "Биология" };
List<string> klass = new List<string> { "10-А", "10-Б", "10-В", "10-Г", "10-Д", "11-А", "11-Б", "11-В", "11-Г", "11-Д" };
List<string> cabinet = new List<string> { "205", "101", "109", "237", "319", "202", "240", "303", "117", "244" };
List<string> rings = new List<string> { "08:00 - 08:40 ", "8:50 - 09:30", "09:40 - 10:20", "10:35 - 11:15", "11:30 - 12:10", "12:20 - 13:00", "13:05 - 13:45", "14:00 - 14:45", "14:55 - 15:40", "15:50 - 16:35" };
List<string> days = new List<string> { "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота" };
while (true)
{
Console.WriteLine("Choose a role:");
Console.WriteLine("HeadTeacher (1), Informer (2)");
int ZavuchOrInformer = int.Parse(Console.ReadLine());
if (ZavuchOrInformer == 1)
{
Console.WriteLine("You are the head teacher, you can create a schedule for teachers");
Console.WriteLine("for which teacher do you want to set the schedule?");
for (int i = 0; i < teachersForDirector.Count; i++)
{
Console.WriteLine(teachersForDirector[i]);
}
int userInput = int.Parse(Console.ReadLine());
if (userInput == 0) // changes for the first teacher
{
Console.WriteLine("What day do you want to set the schedule for?");
for (int i = 0; i < days.Count; i++)
{
Console.WriteLine(days[i]);
}
int userDay = int.Parse(Console.ReadLine());

Console.WriteLine("How many lessons will there be?");
int howMuchLessons = int.Parse(Console.ReadLine());

for (int i = 0; i < howMuchLessons; i++)
{
Console.WriteLine("What's the lesson going to be?");
for (int l = 0; l < lessons.Count; l++)
{
Console.WriteLine(lessons[i]);
}
int userLesson = int.Parse(Console.ReadLine());
Console.WriteLine("Which office will it be?");
for (int j = 0; j < cabinet.Count; j++)
{
Console.WriteLine(cabinet[j]);
}
int userCabinet = int.Parse(Console.ReadLine());
}

}
}
if (ZavuchOrInformer == 2)
{
Console.WriteLine($"Schedule for the first teacher for the day {userDay}"); // THE TIMETABLE FOR THE FIRST TEACHER FOR THE DAY SELECTED BY THE USER,
// WHICH CONTAINS THE NUMBER OF LESSONS, THE LESSONS THEMSELVES, AND THE ROOMS ASSIGNED BY THE USER
}
}
}

我将通过为Schedule Entry创建一个对象和为Teacher创建一个对象来利用OOP对象。Schedule Entry对象将具有基本的调度数据,例如教室、课程、开始时间、结束时间等。教师将持有基本的人口统计数据,如姓名和ID,以及时间表条目列表。

public class Teacher {
public string Name {get;set;}
public string ID {get;set;}

public List<ScheduleEntry> Schedule {get;set;} = new List<ScheduleEntry>();
}
public class ScheduleEntry {
public string ClassroomID {get; set;}
public DateTime StartTime {get; set;}
public DateTime EndTime {get; set;}
public string LessonID {get;set;}
public int Day {get;set;}
}

然后,在主程序中,每次运行调度创建程序时,创建一个新的ScheduleEntry。在调度程序脚本的末尾,将Schedule Entry添加到Teacher对象。

static void Main() {
//Create a variable to hold all the teachers and their schedules.
List<Teacher> TeacherSchedules = new List<Teacher>();
//Chose the role

//If HeadTeacher, create a scheduling object.

//Create a teacher object and populate with name.
Teacher t = new Teacher();

int teacherID = int.Parse(Console.ReadLine());
t.ID = teacherID;

while ([we are in scheduling mode]) {

//Create a scheduling object and populate with entered data.
ScheduleEntry se = new ScheduleEntry();
int userDay = int.Parse(Console.ReadLine());
se.Day = userDay;
int userLesson = int.Parse(Console.ReadLine());
se.LessonID = userLesson;
int userCabinet = int.Parse(Console.ReadLine());
se.ClassroomID = userCabinet;
t.Schedule.Add(se);
}

//When you exit scheduling mode, add the teacher to a collection of teachers.
//If the teacher already exists, add the new schedule entries to the exising teacher.
if (TeacherSchedules.Any(ts => ts.ID = t.ID)) {
Teacher tExisting = TeacherSchedules.Where(ts => ts.ID = t.ID).FirstOrDefault();
tExisting.Schedule.AddRange(t.Schedule);
} else {
//Teacher doesn't exist... add it to the schedules.
TeacherSchedules.Add(t);
}
}