Java实现-创建Teacher、Student、Office三个类,实现教师、学生间的一些相关操作。

代码实现

        (注意:三个类 必须 包含在 同一包中 才可互相调用)

        1.Office类

import java.util.Scanner;
public class Office {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Teacher teacher = new Teacher();
        Student student = new Student();
        System.out.println("请选择您要进行的操作:0-退出;1-查看教师信息、" +
                "2-查看学生信息、3-按教师编号查找教师、4-按学号查找学生、5-查看课程表");
        int i = input.nextInt();
        while (i != 0) {
            switch (i){
                case 1: teacher.initTeacher();break;
                case 2:student.initStudent();break;
                case 3:teacher.checkTeacher();break;
                case 4:student.checkStudent();break;
                case 5:courseList();break;
                default:
                    System.out.println("您输入的选择数字不正确,请重新输入:");
            }
            System.out.println("请继续选择:0-退出;1-查看教师信息、2-查看学生信息、" +
                    "3-按教师编号查找教师、4-按学号查找学生、5-查看课程表");
            i = input.nextInt();
        }

    }
    //课程表
    public static void courseList(){
        String[][] course = new String[9][6];
        course[0][0]="  星期  ";course[0][1]="  周一  ";course[0][2]="   周二  ";course[0][3]="   周三  ";course[0][4]="   周四  ";course[0][5]="   周五  ";
        course[1][0]=" 第一节";course[1][1]=" 写自己的";course[1][2]=" 写自己的";course[1][3]=" 写自己的";course[1][4]=" 写自己的";course[1][5]=" 写自己的";
        course[2][0]=" 第二节";course[2][1]=" 写自己的";course[2][2]=" 写自己的";course[2][3]=" 写自己的";course[2][4]=" 写自己的";course[2][5]=" 写自己的";
        course[3][0]=" 第三节";course[3][1]=" 写自己的";course[3][2]=" 写自己的";course[3][3]=" 写自己的";course[3][4]=" 写自己的 ";course[3][5]="写自己的 ";
        course[4][0]=" 第四节";course[4][1]=" 写自己的";course[4][2]=" 写自己的";course[4][3]=" 写自己的";course[4][4]=" 写自己的";course[4][5]=" 写自己的 ";
        course[5][0]=" 第五节";course[5][1]=" 写自己的";course[5][2]=" 写自己的";course[5][3]=" 写自己的";course[5][4]=" 写自己的";course[5][5]=" 写自己的";
        course[6][0]=" 第六节";course[6][1]=" 写自己的";course[6][2]=" 写自己的";course[6][3]=" 写自己的";course[6][4]=" 写自己的";course[6][5]=" 写自己的";
        course[7][0]=" 第七节";course[7][1]=" 写自己的";course[7][2]=" 写自己的";course[7][3]=" 写自己的";course[7][4]=" 写自己的 ";course[7][5]="写自己的";
        course[8][0]=" 第八节";course[8][1]=" 写自己的";course[8][2]=" 写自己的";course[8][3]=" 写自己的";course[8][4]=" 写自己的";course[8][5]=" 写自己的";
        for(int i = 0;i < course.length; i++){
            for(int j = 0;j < course[i].length; j++){
                if(j % 6== 0){
                    System.out.println();
                }
                System.out.print(course[i][j] + " ");
            }
        }
        System.out.println();
    }

}

        2.Student类

import java.util.Scanner;
public class Student {
    //姓名、性别、年龄、学历、学号、班级、年级、QQ、电话、邮箱
    String name;//姓名
    String gender;//性别
    int age;//年龄
    String title;//学历
    int studentNumber;//学号
    String classRoom;//班级
    String grade;//年级
    int qq;//QQ
    String telephone;//电话
    String e_mail;//邮箱

    //定义无返回值构造函数,避免编译出错
    public Student(){

    }
    public Student(String name, String gender, int age, String title,int studentNumber, String classRoom, String grade,
                   int qq, String telephone, String e_mail) {
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.title = title;
        this.studentNumber = studentNumber;
        this.classRoom = classRoom;
        this.grade = grade;
        this.qq = qq;
        this.telephone = telephone;
        this.e_mail = e_mail;
        System.out.print(name + " ");
        System.out.print(gender + " ");
        System.out.print(age + " ");
        System.out.print(title + " ");
        System.out.print(studentNumber + " ");
        System.out.print(classRoom + " ");
        System.out.print(grade + " ");
        System.out.print(qq + " ");
        System.out.print(telephone + " ");
        System.out.println(e_mail + " ");
    }
    void initStudent(){
        new Student("学生A", "male", 21, "本科生", 1,
                "1班", "大一", 123,"456","xxx@163.com");
        new Student("学生B", "female", 21, "本科生",2,
                "计科1班", "大一", 123,"456","xxx@163.com");
        new Student("学生D", "female", 20, "本科生",3,
                "1班", "大一", 123,"456","xxx@163.com");
        new Student("学生C","male", 22, "本科生",4,
                "2班", "大一", 123,"456","xxx@163.com");
        new Student("学生E", "female", 21, "本科生",5,
                "2班", "大一", 123,"456","xxx@163.com");
    }
    void checkStudent(){
        Scanner input = new Scanner(System.in);
        System.out.println("请输入学号:");
        int i = input.nextInt();
        switch (i){
            case 1:
                System.out.println("学生A,male,21,本科生,1,1班,大一,123,456,xxx@163.com");break;
            case 2:
                System.out.println("学生B,female,21,本科生,2,1班,大一,123,456,xxx@163.com");break;
            case 3:
                System.out.println("学生D,female,20,本科生,3,1班,大一,123,456,xxx@163.com");break;
            case 4:
                System.out.println("学生C,male,22,本科生,4,2班,大一,123,456,xxx@163.com");break;
            case 5:
                System.out.println("学生E,female,21,本科生,5,2班,大一,123,456,xxx@163.com");break;
            default:
                System.out.println("您输入的学号不正确,请重新输入");
        }
    }
}

        3.Teacher类

import java.util.Scanner;
public class Teacher {
    //姓名、性别、年龄、教师编号、学历、职称、课程名称、邮箱
    String name;//姓名
    String gender;//性别
    int age;//年龄
    int teacherId;//教师编号
    String education;//学历
    String title;//职称
    String courseName;//课程名称
    String e_mail;//邮箱

    //定义无返回值构造函数,避免编译出错
    public Teacher() {

    }
    public Teacher(String name, String gender, int age, int teacherId,String education, String title, String courseName, String e_mail) {
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.teacherId = teacherId;
        this.education = education;
        this.title = title;
        this.courseName = courseName;
        this.e_mail = e_mail;
        System.out.print(name + " ");
        System.out.print(gender + " ");
        System.out.print(age + " ");
        System.out.print(teacherId + " ");
        System.out.print(education + " ");
        System.out.print(title + " ");
        System.out.print(courseName + " ");
        System.out.println(e_mail + " ");
    }
    void initTeacher(){
        new Teacher("张三","male",31,1134,"研究生",
                "副教授", "编译原理", "xxx@163.com");
        new Teacher("李四","male",37,1128,"博士",
                "教授", "计算机应用基础","xxx@163.com");
        new Teacher("王二","male",27,1131,"研究生",
                "专职教师","大学语文","xxx@163.com");
    }
    void checkTeacher(){
        Scanner input = new Scanner(System.in);
        System.out.println("请输入教师编号:");
        int i = input.nextInt();
        switch (i){
            case 1134:
                System.out.println("张三,male,31,1134,研究生,副教授,编译原理,xxx@163.com");break;
            case 1128:
                System.out.println("李四,male,37,1128,博士, 教授,计算机应用基础,xxx@163.com");break;
            case 1131:
                System.out.println("王二,male,27,1131,研究生, 专职教师,大学语文,xxx@163.com");break;
            default:
                System.out.println("您输入的教师编号不正确,请重新输入");
        }
    }
}

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

等日出看彩虹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值