package studentsystem
/**
 * 性别 枚举类型
 */
public enum Sex <: ToString {
    | Girl | Boy

    // ToString 接口定义的转换字符串的函数
    public func toString() {
        match (this) {
            case Girl => "女"
            case Boy => "男"
        }
    }
}

/**
 * 学生 类
 */
public class Student <: ToString {

    /**
     * 静态变量 学校名称
     */
    public static let schoolName = "合肥师范学院"

    // 成员变量
    private var id: UInt32          // 学号
    private var name: String        // 姓名
    private var age: UInt8          // 年龄
    private var sex: Sex            // 性别
    private var classBelonged: String // 班级

    // 成员属性 propId(只读)
    prop propId: UInt32 {
        get() {
            id
        }
    }

    // 成员属性 propName(可读写)
    mut prop propName: String {
        get() {
            name
        }
        set(name) {
            this.name = name
        }
    }

    // 成员属性 propAge(可读写)
    mut prop propAge: UInt8 {
        get() {
            age
        }
        set(age) {
            this.age = age
        }
    }

    // 成员属性 propSex(可读写)
    mut prop propSex: Sex {
        get() {
            sex
        }
        set(sex) {
            this.sex = sex
        }
    }

    // 成员属性 propClassBelonged(可读写)
    mut prop propClassBelonged: String {
        get() {
            classBelonged
        }
        set(classBelonged) {
            this.classBelonged = classBelonged
        }
    }

    /**
     * 普通构造函数
     *
     * @param id           学号
     * @param name         姓名
     * @param age          年龄
     * @param sex          性别
     * @param classBelonged 班级
     */
    public init(id: UInt32, name: String, age: UInt8, sex: Sex, classBelonged: String) {
        this.id = id
        this.name = name
        this.age = age
        this.sex = sex
        this.classBelonged = classBelonged
    }

    /**
     * 输出学生信息(ToString 接口定义的转换字符串的函数)
     */
    public func toString() {
        return "学号: ${id} 姓名: ${name} 年龄: ${age} 性别: ${sex} 学校班级: ${schoolName} ${classBelonged}"
    }
}