简体   繁体   中英

How to assign the values entered by the user to a specific array

There are two modules. The head teacher, and the informer. The head teacher allows you to create a timetable for teachers for a particular day of the week, how many lessons there will be, what lessons will be, and what room will be there. The informer module generates the timetable for the selected teacher for the selected day of the week. That is, the user has created a timetable for the teacher for a particular day of the week, entered there the number of lessons, classes, and the informer must display this information in the "Informer" module.

How to assign selected lessons, and how many of them, as well as classrooms, to a particular teacher?

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
                }

            }

        }

I would leverage OOP objects by creating an object for a Schedule Entry and one for Teacher. The Schedule Entry object would have basic scheduling data such as classroom, lesson, start time, end time, etc. The teacher would hold basic demographics like Name and ID and a list of schedule entries.

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;}
}

Then, in your Main program, each time you run through the scheduling creator, you create a new ScheduleEntry . At the end of the scheduler script, you add the Schedule Entry to your Teacher object.

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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM