制作一個評選優秀老師和學生的系統,系統根據提示輸入類別(老師或學生),
如果是老師則輸入姓名和論文數,學生則輸入姓名和考試成績,輸入若干人員信息后使用結束符完成輸入,程序根據輸入的數據列出優秀老師和優秀學生
(判定優秀的標準是老師3篇論文以上和學生90分以上)
package com
.entity
;public class Teacher {private String name
;private int num
;public int getNum() {return num
;}public void setNum(int num
) {this.num
= num
;}public String
getName() {return name
;}public void setName(String name
) {this.name
= name
;}
}
package co
.entity
;public class Students {private String name
;private double score
;public void setName(String name
) {this.name
= name
;}public String
getName() {return name
;}public double getScore() {return score
;}public void setScore(double score
) {this.score
= score
;}
}
package com
.test
;import com
.iotek
.entity
.Students
;
import com
.iotek
.entity
.Teacher
;import java
.util
.Scanner
;public class Excellent {public static void main(String
[] args
) {Scanner input
= new Scanner(System
.in
);char c
= ' ';Students
[] stu
= new Students[10];Students
[] students
=java
.util
.Arrays
.copyOf(stu
,5);Teacher
[] teach
= new Teacher[10];Teacher
[] teachers
=java
.util
.Arrays
.copyOf(teach
,5);while (true) {System
.out
.println("輸入教師(t),學生(s) ");c
= input
.next().charAt(0);if(c
!='t'&&c
!='s'){System
.out
.println("------------------------");break;}if (c
== 't') {Teacher teacher
= new Teacher();System
.out
.print("姓名 ");teacher
.setName(input
.next());System
.out
.print("論文數 ");teacher
.setNum(input
.nextInt());save(teachers
,teacher
);}if (c
== 's') {Students student
= new Students();System
.out
.print("姓名 ");student
.setName(input
.next());System
.out
.print("成績 ");student
.setScore(input
.nextDouble());save(students
,student
);}}System
.out
.println("優秀教師,學生的名單如下:");for (Teacher teacher
: teachers
) {if(teacher
.getNum()>3){System
.out
.println("老師" + teacher
.getName() + " 論文" + teacher
.getNum());}}for (Students student
: students
) {if(student
.getScore()>90){System
.out
.println("學生" + student
.getName() + " 成績" + student
.getScore());}}}public static void save(Students
[] arr
, Students student
){if (arr
[arr
.length
- 1] != null
) {System
.out
.println("已經存滿");return;}for (int i
= 0; i
< arr
.length
; i
++) {if (arr
[i
] == null
) {arr
[i
] = student
;break;}}}public static void save(Teacher
[] arr
, Teacher teachers
){if (arr
[arr
.length
- 1] != null
) {System
.out
.println("已經存滿");return;}for (int i
= 0; i
< arr
.length
; i
++) {if (arr
[i
] == null
) {arr
[i
] = teachers
;break;}}}
}
總結
以上是生活随笔為你收集整理的制作一个评选优秀老师和学生的系统,系统根据提示输入类别(老师或学生), 如果是老师则输入姓名和论文数,学生则输入姓名和考试成绩,输入若干人员信息后使用结束符完成输入,程序根据输入的数据列出优秀老师和优的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。