2022/09/24 13:38 作业3修改

This commit is contained in:
zyx 2022-09-24 13:38:25 +08:00
parent 4f7689439b
commit 8584e730a8
11 changed files with 269 additions and 15 deletions

View File

@ -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;

View File

@ -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());
}
}

View File

@ -1,4 +1,4 @@
package Class5.work;
package lesson5.work;
/**
* @author : 张宇轩

View File

@ -1,4 +1,4 @@
package Class5.work;
package lesson5.work;
/**
* @author : 张宇轩

View File

@ -1,4 +1,4 @@
package Class6;
package lesson6;
/**
* @author : 张宇轩

View File

@ -1,4 +1,4 @@
package Class6;
package lesson6;
/**
* @author : 张宇轩

View File

@ -1,4 +1,4 @@
package Class6;
package lesson6;
/**
* @author : 张宇轩

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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";
}
}