From 8584e730a85f98cdbbef41673714e2204ed6d5b0 Mon Sep 17 00:00:00 2001 From: zyx <1029606625@qq.com> Date: Sat, 24 Sep 2022 13:38:25 +0800 Subject: [PATCH] =?UTF-8?q?2022/09/24=2013:38=20=E4=BD=9C=E4=B8=9A3?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{Class5 => lesson5}/work/Rectangle.java | 6 +- .../work/RectangleTest.java | 12 +- .../src/{Class5 => lesson5}/work/Student.java | 2 +- .../{Class5 => lesson5}/work/StudentTest.java | 2 +- Week4/src/{Class6 => lesson6}/Employee.java | 2 +- Week4/src/{Class6 => lesson6}/Project.java | 2 +- .../{Class6 => lesson6}/ProjectDriver.java | 2 +- Week4/src/lesson6/work/ClassList.java | 69 ++++++++++++ Week4/src/lesson6/work/Driver.java | 106 ++++++++++++++++++ Week4/src/lesson6/work/Student.java | 45 ++++++++ Week4/src/lesson6/work/Subject.java | 36 ++++++ 11 files changed, 269 insertions(+), 15 deletions(-) rename Week4/src/{Class5 => lesson5}/work/Rectangle.java (83%) rename Week4/src/{Class5 => lesson5}/work/RectangleTest.java (52%) rename Week4/src/{Class5 => lesson5}/work/Student.java (97%) rename Week4/src/{Class5 => lesson5}/work/StudentTest.java (91%) rename Week4/src/{Class6 => lesson6}/Employee.java (98%) rename Week4/src/{Class6 => lesson6}/Project.java (98%) rename Week4/src/{Class6 => lesson6}/ProjectDriver.java (97%) create mode 100644 Week4/src/lesson6/work/ClassList.java create mode 100644 Week4/src/lesson6/work/Driver.java create mode 100644 Week4/src/lesson6/work/Student.java create mode 100644 Week4/src/lesson6/work/Subject.java diff --git a/Week4/src/Class5/work/Rectangle.java b/Week4/src/lesson5/work/Rectangle.java similarity index 83% rename from Week4/src/Class5/work/Rectangle.java rename to Week4/src/lesson5/work/Rectangle.java index 510acd3..59b7606 100644 --- a/Week4/src/Class5/work/Rectangle.java +++ b/Week4/src/lesson5/work/Rectangle.java @@ -1,9 +1,5 @@ -package Class5.work; +package lesson5.work; -/** - * @author : 张宇轩 - * @createTime : 2022/9/21 - 9:17 - */ public class Rectangle { private Double length; private Double width; diff --git a/Week4/src/Class5/work/RectangleTest.java b/Week4/src/lesson5/work/RectangleTest.java similarity index 52% rename from Week4/src/Class5/work/RectangleTest.java rename to Week4/src/lesson5/work/RectangleTest.java index 3fd15af..ddef265 100644 --- a/Week4/src/Class5/work/RectangleTest.java +++ b/Week4/src/lesson5/work/RectangleTest.java @@ -1,13 +1,15 @@ -package Class5.work; +package lesson5.work; -/** - * @author : 张宇轩 - * @createTime : 2022/9/21 - 9:20 - */ public class RectangleTest { public static void main(String[] args) { Rectangle rectangle = new Rectangle(3.0,4.0); System.out.println("矩形的面积:" + rectangle.calculateArea()); System.out.println("矩形的周长:" + rectangle.calculatePerimeter()); + + System.out.println(); + + Rectangle rectangle1 = new Rectangle(); + System.out.println("矩形的面积:" + rectangle1.calculateArea()); + System.out.println("矩形的周长:" + rectangle1.calculatePerimeter()); } } diff --git a/Week4/src/Class5/work/Student.java b/Week4/src/lesson5/work/Student.java similarity index 97% rename from Week4/src/Class5/work/Student.java rename to Week4/src/lesson5/work/Student.java index 4b100d9..23c4593 100644 --- a/Week4/src/Class5/work/Student.java +++ b/Week4/src/lesson5/work/Student.java @@ -1,4 +1,4 @@ -package Class5.work; +package lesson5.work; /** * @author : 张宇轩 diff --git a/Week4/src/Class5/work/StudentTest.java b/Week4/src/lesson5/work/StudentTest.java similarity index 91% rename from Week4/src/Class5/work/StudentTest.java rename to Week4/src/lesson5/work/StudentTest.java index 24b5f52..9851efa 100644 --- a/Week4/src/Class5/work/StudentTest.java +++ b/Week4/src/lesson5/work/StudentTest.java @@ -1,4 +1,4 @@ -package Class5.work; +package lesson5.work; /** * @author : 张宇轩 diff --git a/Week4/src/Class6/Employee.java b/Week4/src/lesson6/Employee.java similarity index 98% rename from Week4/src/Class6/Employee.java rename to Week4/src/lesson6/Employee.java index 12405d8..90fafd9 100644 --- a/Week4/src/Class6/Employee.java +++ b/Week4/src/lesson6/Employee.java @@ -1,4 +1,4 @@ -package Class6; +package lesson6; /** * @author : 张宇轩 diff --git a/Week4/src/Class6/Project.java b/Week4/src/lesson6/Project.java similarity index 98% rename from Week4/src/Class6/Project.java rename to Week4/src/lesson6/Project.java index 27e6354..7bbbfec 100644 --- a/Week4/src/Class6/Project.java +++ b/Week4/src/lesson6/Project.java @@ -1,4 +1,4 @@ -package Class6; +package lesson6; /** * @author : 张宇轩 diff --git a/Week4/src/Class6/ProjectDriver.java b/Week4/src/lesson6/ProjectDriver.java similarity index 97% rename from Week4/src/Class6/ProjectDriver.java rename to Week4/src/lesson6/ProjectDriver.java index 6c88344..2e523a1 100644 --- a/Week4/src/Class6/ProjectDriver.java +++ b/Week4/src/lesson6/ProjectDriver.java @@ -1,4 +1,4 @@ -package Class6; +package lesson6; /** * @author : 张宇轩 diff --git a/Week4/src/lesson6/work/ClassList.java b/Week4/src/lesson6/work/ClassList.java new file mode 100644 index 0000000..07eba7f --- /dev/null +++ b/Week4/src/lesson6/work/ClassList.java @@ -0,0 +1,69 @@ +package lesson6.work; + +public class ClassList { + private Integer semester; + private Integer year; + private Subject subj; + private Student s1; + private Student s2; + + public ClassList() { + } + + public ClassList(Integer semester, Integer year, Subject subj, Student s1, Student s2) { + this.semester = semester; + this.year = year; + this.subj = subj; + this.s1 = s1; + this.s2 = s2; + } + + public Integer getSemester() { + return semester; + } + + public void setSemester(Integer semester) { + this.semester = semester; + } + + public Integer getYear() { + return year; + } + + public void setYear(Integer year) { + this.year = year; + } + + public Subject getSubj() { + return subj; + } + + public void setSubj(Subject subj) { + this.subj = subj; + } + + public Student getS1() { + return s1; + } + + public void setS1(Student s1) { + this.s1 = s1; + } + + public Student getS2() { + return s2; + } + + public void setS2(Student s2) { + this.s2 = s2; + } + + @Override + public String toString() { + return year + "年第" + semester + "学期\n" + + "================\n" + + subj + + "================\n" + + "学号\t姓名\n" + s1 + "\n" + s2; + } +} diff --git a/Week4/src/lesson6/work/Driver.java b/Week4/src/lesson6/work/Driver.java new file mode 100644 index 0000000..7c83428 --- /dev/null +++ b/Week4/src/lesson6/work/Driver.java @@ -0,0 +1,106 @@ +package lesson6.work; + +import java.util.Scanner; + +public class Driver { + static ClassList classList1 = null; + static ClassList classList2 = null; + static int classListCount = 0; + + public static void main(String[] args) { + while (true) { + int opt = menu(); + switch (opt) { + case 1: + if (classListCount == 0) { + System.out.println("创建第一张班级出勤表:"); + classList1 = inputClassList(); + classListCount++; + } else if (classListCount == 1) { + System.out.println("创建第二张班级出勤表:"); + classList2 = inputClassList(); + classListCount++; + } else { + System.out.println("已经创建了两张班级出勤表,无法创建更多"); + } + break; + case 2: + if (classListCount == 0) { + System.out.println("不存在任何班级出勤表!请先使用功能1"); + } else { + System.out.println("班级出勤表1:"); + System.out.println(classList1 + "\n"); + if (classList2 != null) { + System.out.println("班级出勤表2:"); + System.out.println(classList2); + } + } + break; + default: + return; + } + System.out.println(); + } + } + + public static int menu(){ + System.out.println("1.创建班级出勤名单"); + System.out.println("2.输出班级出勤名单"); + System.out.println("3.退出系统"); + int opt = -1; + Scanner scanner = new Scanner(System.in); + while (opt == -1) { + opt = checkInput(scanner, 1, 3); + } + return opt; + } + + public static Subject inputSubject() { + Scanner scanner = new Scanner(System.in); + System.out.print("请输入课程号:"); + String subjectID = scanner.nextLine(); + System.out.print("请输入课程名:"); + String subjectName = scanner.nextLine(); + return new Subject(subjectID, subjectName); + } + + public static Student inputStudent() { + Scanner scanner = new Scanner(System.in); + System.out.print("请输入学生学号:"); + String studentID = scanner.nextLine(); + System.out.print("请输入学生的名:"); + String firstName = scanner.nextLine(); + System.out.print("请输入学生的姓:"); + String lastName = scanner.nextLine(); + return new Student(studentID, firstName, lastName); + } + + public static ClassList inputClassList() { + Scanner scanner = new Scanner(System.in); + System.out.print("请输入学期数:"); + int semester = scanner.nextInt(); + System.out.print("请输入学年数:"); + int year = scanner.nextInt(); + System.out.println("===========\n请输入课程:"); + Subject subject = inputSubject(); + System.out.println("===========\n请输入第一个学生:"); + Student student1 = inputStudent(); + System.out.println("===========\n请输入第二个学生:"); + Student student2 = inputStudent(); + return new ClassList(semester, year, subject, student1, student2); + } + + public static int checkInput(Scanner scanner, int low, int high) { + if (scanner.hasNextInt()) { + int opt = scanner.nextInt(); + if (opt >= low && opt <= high) { + return opt; + } + System.out.println("输入超限,请输入" + low + "-" + high + "的数字"); + } else { + System.out.println("输入数据类型错误,请输入" + low + "-" + high + "的数字"); + scanner.next(); + } + return -1; + } +} diff --git a/Week4/src/lesson6/work/Student.java b/Week4/src/lesson6/work/Student.java new file mode 100644 index 0000000..be26bac --- /dev/null +++ b/Week4/src/lesson6/work/Student.java @@ -0,0 +1,45 @@ +package lesson6.work; + +public class Student { + private String studentID; + private String firstName; + private String lastName; + + public Student() { + } + + public Student(String studentID, String firstName, String lastName) { + this.studentID = studentID; + this.firstName = firstName; + this.lastName = lastName; + } + + public String getStudentID() { + return studentID; + } + + public void setStudentID(String studentID) { + this.studentID = studentID; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @Override + public String toString() { + return studentID + "\t" + lastName + " " + firstName; + } +} diff --git a/Week4/src/lesson6/work/Subject.java b/Week4/src/lesson6/work/Subject.java new file mode 100644 index 0000000..473516d --- /dev/null +++ b/Week4/src/lesson6/work/Subject.java @@ -0,0 +1,36 @@ +package lesson6.work; + +public class Subject { + private String subjectID; + private String subjectName; + + public Subject() { + } + + public Subject(String subjectID, String subjectName) { + this.subjectID = subjectID; + this.subjectName = subjectName; + } + + public String getSubjectID() { + return subjectID; + } + + public void setSubjectID(String subjectID) { + this.subjectID = subjectID; + } + + public String getSubjectName() { + return subjectName; + } + + public void setSubjectName(String subjectName) { + this.subjectName = subjectName; + } + + @Override + public String toString() { + return "课程号:" + subjectID + "\n" + + "课程名:" + subjectName + "\n"; + } +}