存储类对象的响应[C#]

时间:2018-09-27 04:17:59

标签: c# c#-4.0 constructor c#-3.0

我一直在尝试找到一种正确的方法来将讲师的姓名和号码存储到各自的班级对象中

老师_老师; 学生[]学生;

它们在名为Course的类中。

一旦我收集了所有必要的响应,那么我需要实例化一个Course对象,使其与Course构造函数相匹配。我无法确定要传递构造函数所需的正确数据类型。

class Course
{
    // Fields for a course - title, description, teacher, students
    private string _title;
    private string _description;
    private Teacher _teacher = null;
    private Student[] _students;

    public Course(string title, string description, Teacher teacher, Student[] student)
    {
        _title = title;
        _description = description;
        _teacher = teacher;
        _students = student;
    }

    public string Title
    {
        get { return _title; }
        set { _title = value; }
    }

    public string Description
    {
        get { return _description; }
        set { _description = value; }
    }

    public Teacher Instructor
    {
        get { return _teacher; }
        set { _teacher = value; }
    }

    public Student[] Students
    {
        get { return _students; }
        set { _students = value; }
    }
}

}

    public static void CreateCourse(Course _currentCourse)
    {
        Console.Clear();
        Console.WriteLine("test");

        if (_currentCourse !=  null )
        {
            Console.WriteLine("* Create Course *\r\n");

            Console.WriteLine("Enter the course title: ");
            string title = Console.ReadLine();
            Validation.EmptyValidation(title,
                "Please, do not leave the course title field empty!" +
                "\r\nEnter the course title: ");


            Console.WriteLine("Enter the course description: ");
            string description = Console.ReadLine();
            Validation.EmptyValidation(title,
            "Please, do not leave the course description field empty!" +
            "\r\nEnter the course description: ");

            Console.WriteLine("Enter the course instructor: ");
            string instructor = Console.ReadLine();

            Console.WriteLine("Enter the number of students in the course: ");
            string students = Console.ReadLine();
            int.TryParse(students, out int stu);

        }
    }

class Student : Person
{
    // Field for a student grade.
    int _grade;

    // Student constructor
    public Student(string name, string description, int age, int grade ) : base(name, description, age)
    {
        _grade = grade;
    }

    // Accessor & Mutator for the Student grade.
    public int Grade
    {
        get { return _grade; }
        set { _grade = value; }
    }
}

class Teacher : Person
{
    // Field for the teacher knowledge
    private string[] _teacherKnowledge;

    // Teacher constructor
    public Teacher(string name, string description, int age, string[] teacherKnowledge) : base(name, description, age)
    {
        _teacherKnowledge = teacherKnowledge;
    }

    // Accessor & Mutator for the the Teacher knowledge
    public string[] Knowledge
    {
        get { return _teacherKnowledge; }
        set { _teacherKnowledge = value; }
    }
}

有什么建议吗?

0 个答案:

没有答案