急求Java编程!设计三个类 (我会追加分的)
1.按以下描述设计类(第四章类和对象)学生类属性:姓名,性别,年龄,登录名,密码,学号,年级,专业方法:构造函数(空构造函数和全构造函数),所有属性的set,get方法,...
1.按以下描述设计类(第四章 类和对象) 学生类 属性:姓名,性别,年龄,登录名,密码,学号,年级,专业 方法:构造函数(空构造函数和全构造函数),所有属性的set,get方法,打印全部信息 老师类 属性:姓名,性别,年龄,登录名,密码,工号,级别 方法:构造函数(空构造函数和全构造函数),所有属性的set,get方法,打印全部信息 测试类 功能:完成学生类和老师类的测试 2.按以下描述设计类(第五章 继承) 人类 属性:姓名,性别,年龄,登录名,密码 方法:构造函数(空构造函数和全构造函数),所有属性的set,get方法,打印全部信息 学生类(继承人类) 属性:学号,年级,专业 方法:构造函数(空构造函数和全构造函数),所有属性的set,get方法,打印全部信息 老师类(继承人类) 属性:工号,级别 方法:构造函数(空构造函数和全构造函数),所有属性的set,get方法,打印全部信息 测试类 功能:完成学生类和老师类的测试 3.按以下描述设计类(第五章 接口) 登录接口 方法:登录方法 学生登录类 方法:实现登录方法 教师登录类 方法:实现登录方法
展开
1个回答
展开全部
第一题: class Student { private String name; // 姓名 private char sex; // 性别 private int age; // 年龄 private String account; // 登录名 private String password; // 密码 private String studentNo; // 学号 private int grade; // 年级 private String major; // 专业 public Student() { } public Student(String name, char sex, int age, String account, String password, String studentNo, int grade, String major) { this.name = name; this.sex = sex; this.age = age; this.account = account; this.password = password; this.studentNo = studentNo; this.grade = grade; this.major = major; } public void setName(String name) { this.name = name; } public String getName() { return this.name; } public void setAge(int age) { this.age = age; } public int getAge() { return this.age; } public void setSex(char sex) { this.sex = sex; } public char getSex() { return this.sex; } public void setAccount(String account) { this.account = account; } public String getAccount() { return this.account; } public void setPassword(String password) { this.password = password; } public String getPassword() { return this.password; } public void setStudentNo(String studentNo) { this.studentNo = studentNo; } public String getStudentNo() { return this.studentNo; } public void setGrade(int grade) { this.grade = grade; } public int getGrade() { return this.grade; } public void setMajor(String major) { this.major = major; } public String getMajor() { return this.major; } public void printInfo() { System.out.println("============================[学生信息]"); System.out.println("姓名:" + this.name); System.out.println("性别:" + this.sex); System.out.println("年龄:" + this.age); System.out.println("账号:" + this.account); System.out.println("密码:" + this.password); System.out.println("学号:" + this.studentNo); System.out.println("年级:" + this.grade); System.out.println("专业:" + this.major); } } class Teacher { private String name; // 姓名 private char sex; // 性别 private int age; // 年龄 private String account; // 登录名 private String password; // 密码 private String workNo; // 工号 public Teacher() { } public Teacher(String name, char sex, int age, String account, String password, String workNo) { this.name = name; this.sex = sex; this.age = age; this.account = account; this.password = password; this.workNo = workNo; } public void setName(String name) { this.name = name; } public String getName() { return this.name; } public void setAge(int age) { this.age = age; } public int getAge() { return this.age; } public void setSex(char sex) { this.sex = sex; } public char getSex() { return this.sex; } public void setAccount(String account) { this.account = account; } public String getAccount() { return this.account; } public void setPassword(String password) { this.password = password; } public String getPassword() { return this.password; } public void setWorkNo(String workNo) { this.workNo = workNo; } public String getWorkNo() { return this.workNo; } public void printInfo() { System.out.println("============================[老师信息]"); System.out.println("姓名:" + this.name); System.out.println("性别:" + this.sex); System.out.println("年龄:" + this.age); System.out.println("账号:" + this.account); System.out.println("密码:" + this.password); System.out.println("工号:" + this.workNo); } } public class Test { public static void main(String[] args) { Student stu1 = new Student(); stu1.setName("小a"); stu1.setSex('男'); stu1.setAge(12); stu1.setAccount("aaa"); stu1.setPassword("123456"); stu1.setStudentNo("2009001"); stu1.setGrade(2009); stu1.setMajor("计算机科学与技术"); stu1.printInfo(); Student stu2 = new Student("小红", '女', 20, "test", "111111", "2009002", 2009, "计算机科学"); stu2.printInfo(); Teacher teacher1 = new Teacher(); teacher1.setName("林老师"); teacher1.setSex('男'); teacher1.setAge(40); teacher1.setAccount("aaa"); teacher1.setPassword("123456"); teacher1.setWorkNo("32111"); teacher1.printInfo(); Teacher teacher2 = new Teacher("而老师", '女', 30, "test", "111111", "32154"); teacher2.printInfo(); } }
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询