设计并实现信息管理系统:使用打印机打印教师、学生、学校的信息,并实现查询和修改学生信息的功能,introducible接口、定义方法detail(),具有自我介绍功能,教师类包含教师姓名、年龄、所教课程等属性,实现introduceble接口,具有自我介绍情况的功能。学生类包含学生姓名、性别、学号、Java\python\语文\数学等各科学科,实现introduceble接口,具有自我介绍的能力,能够输出平均成绩等信息。利用接口的知识,编写代码实现该需求,并编写测试类创建教师数组、学生数组,并通过键盘输入教师、学生的信息,实现查询学生某一科成绩查询的功能。并在每个代码块下面写下内容注释🙏
希望对您有所帮助
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入学生数量:");
int stuNum = scanner.nextInt();
Student[] students = new Student[stuNum];
int index = 0;
System.out.println("请输入学生信息:");
while (index < stuNum) {
Student student = new Student();
System.out.println("请输入学生姓名:");
student.setName(scanner.nextLine());
System.out.println("请输入学生性别:");
student.setSex(scanner.nextLine());
System.out.println("请输入学生学号:");
student.setStuno(scanner.nextLine());
System.out.println("请输入学生java成绩:");
student.setJavaScore(scanner.nextInt());
System.out.println("请输入学生python成绩:");
student.setPythonScore(scanner.nextInt());
System.out.println("请输入学生语文成绩:");
student.setChinieseScore(scanner.nextInt());
System.out.println("请输入学生数学成绩:");
student.setMathScore(scanner.nextInt());
students[index] = student;
}
System.out.println("请输入教师数量:");
int teacherNum = scanner.nextInt();
Teacher[] teachers = new Teacher[teacherNum];
int i = 0;
while (i < teacherNum) {
Teacher teacher = new Teacher();
System.out.println("请输入教师姓名:");
teacher.setName(scanner.nextLine());
System.out.println("请输入教师年龄:");
teacher.setAge(scanner.nextInt());
System.out.println("请输入教师所教课程:");
teacher.setCourse(scanner.nextLine());
teachers[i] = teacher;
}
//根据学号查询学生信息并输出
System.out.println("请输入学生学号查询学生信息");
String stuNo = scanner.nextLine();
for (int j = 0; j < students.length; j++) {
Student student = students[j];
if (student.getStuno().equals(stuNo)) {
student.detail();
break;
}
}
//查询学生某一科成绩
System.out.println("请输入学生学号和科目查询该学生该科目成绩");
System.out.println("java科目请输入1,python科目请输入2,语文请输入3,数学请输入4");
while (true) {
System.out.println("请输入学号");
String stuNo1 = scanner.nextLine();
System.out.println("请输入科目数字");
String course = scanner.nextLine();
for (int j = 0; j < students.length; j++) {
Student student = students[j];
if (student.getStuno().equals(stuNo)) {
//查询该学生对应科目成绩
if ("1".equals(course)){
System.out.println("java成绩:" + student.getJavaScore() + "分");
}
if ("2".equals(course)){
System.out.println("python成绩:" + student.getPythonScore() + "分");
}
if ("3".equals(course)){
System.out.println("语文成绩:" + student.getChinieseScore() + "分");
}
if ("4".equals(course)){
System.out.println("数学成绩:" + student.getMathScore() + "分");
}
break;
}
}
System.out.println("是否继续查询,yes继续,no退出");
String continueQuery = scanner.nextLine();
if ("no".equals(continueQuery)) {
break;
}
}
}
}
public interface Introducible {
void detail();
}
public class Teacher implements Introducible{
private String name;
private int age;
private String course;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
@Override
public void detail() {
System.out.println("我是" + this.name + ",今年" + this.age +"岁,教的课程是:" + this.course);
}
}
public class Student implements Introducible{
private String name;//姓名
private String sex;//性别
private String stuno;//学号
private String javaCourse;//java课
private int javaScore;//java成绩
private String pythonCourse;//python课
private int pythonScore;//python成绩
private String chinieseCourse;//语文课
private int chinieseScore;//语文成绩
private String mathCourse;//数学课
private int mathScore;//数学成绩
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getStuno() {
return stuno;
}
public void setStuno(String stuno) {
this.stuno = stuno;
}
public String getJavaCourse() {
return javaCourse;
}
public void setJavaCourse(String javaCourse) {
this.javaCourse = javaCourse;
}
public int getJavaScore() {
return javaScore;
}
public void setJavaScore(int javaScore) {
this.javaScore = javaScore;
}
public String getPythonCourse() {
return pythonCourse;
}
public void setPythonCourse(String pythonCourse) {
this.pythonCourse = pythonCourse;
}
public int getPythonScore() {
return pythonScore;
}
public void setPythonScore(int pythonScore) {
this.pythonScore = pythonScore;
}
public String getChinieseCourse() {
return chinieseCourse;
}
public void setChinieseCourse(String chinieseCourse) {
this.chinieseCourse = chinieseCourse;
}
public int getChinieseScore() {
return chinieseScore;
}
public void setChinieseScore(int chinieseScore) {
this.chinieseScore = chinieseScore;
}
public String getMathCourse() {
return mathCourse;
}
public void setMathCourse(String mathCourse) {
this.mathCourse = mathCourse;
}
public int getMathScore() {
return mathScore;
}
public void setMathScore(int mathScore) {
this.mathScore = mathScore;
}
@Override
public void detail() {
System.out.println("我是" + this.name + ",性别" + this.sex +",所学的课程有:"
+ this.javaCourse + "," + this.pythonCourse + "," + this.chinieseCourse
+ "," + this.mathCourse);
System.out.print("java考了" + this.javaScore + "分;");
System.out.print("python考了" + this.pythonScore + "分;");
System.out.print("语文考了" + this.chinieseScore + "分;");
System.out.print("数学考了" + this.mathScore + "分");
avgScore();
}
//输出平均分
public void avgScore() {
double avgScore = (double)(this.mathScore+this.javaScore+this.pythonScore+this.chinieseScore)/4;
System.out.println("平均分:" + avgScore);
}
}
20做这么大的项目,不科学啊
还好
你这个接口到底是 introducible 还是 introduceble啊,还是说这是俩接口?