实验内容
1. 根据目前所学课堂内容,用java逐步编程实现下述类图,遵循Java编程规范,并为撰写的类提供相应的Javadoc注释。
2. 在FushiSystem.java中已提供部分辅助函数,该类的其它方法,请按上述类图中的要求全部编程实现,最终保证程序在步骤1-7中的执行中,按要求完成功能。
程序运行时可供用户选择要实现的功能,如下图。(此功能已经给出,无需更改)
步骤1:选择1(addStudentToCatalog方法实现的功能):
添加学生,逐步让用户输入以下内容,包括学生的id 和name,添加成功会提示用户相应信息。
步骤2:选择2(displayStudentCatalog方法实现的功能):
显示学生目录,包括学生的id和name,格式如下:
步骤3:选择3(displayExamPaper方法实现的功能):
根据用户输入的学生id,显示该学生的试卷信息,格式如下:
当用户输入不存在的学生id时,提示错误并请用户重新输入。
如果还未为该学生生成试卷,会提示用户“还没有为该学生生成相应的试卷”。
步骤6:选择6(lookupTotalScore方法实现的功能):
根据用户输入的学生id,显示学生复试试卷的总得分,格式如下:
当用户输入不存在的学生id时,提示错误并请用户重新输入。
如果还未为该学生生成试卷,会提示用户“还没有为该学生生成相应的试卷”。
步骤7:选择7(lookupTestScore方法实现的功能):
- 根据用户输入的学生id,显示学生复试试卷的每道题目得分,格式如下:
当用户输入不存在的学生id时,提示错误并请用户重新输入。
如果还未为该学生生成试卷,会提示用户“还没有为该学生生成相应的试卷”。
代码资源
这里免费提供主程序的代码实现,和演示视频,其余内容请【点击此处】付费查看
请注意,源码仅供参考,由抄袭导致的任何后果将由读着自行承担!
主程序代码实现:
import TestUtil.TestDataBase;
import TestUtil.TestItem;
import TestUtil.Tests.EnglishTest;
import TestUtil.Tests.MathTest;
import TestUtil.Tests.ProfessionalTest;
import TestUtil.Tests.Test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.Random;
public class FushiSystem {
private StudentCatalog studentCatalog= new StudentCatalog();
private TestDataBase testDataBase = new TestDataBase();
public void addStudentToCatalog(String id) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.err.print("Student name> ");
//下一行输入就是学生的名称
Student student = new Student(id, br.readLine());
studentCatalog.addStudent(student);
}
public void displayStudentCatalog(){
int count = studentCatalog.getNumberOfStudent();
for(int i=0;i<count;i++){
System.out.println(studentCatalog.getStudent(i));
}
}
public void displayExamPaper(String id) throws Exception{
Student student = lookupStudent(id);
System.out.println(student.getExamPaper());
}
/**
* 这个方法是老师实现的,做了些许修改以适应我们的代码
* @param id
* @throws Exception
*/
public void generateExamPaper(String id) throws Exception {
Student student = lookupStudent(id);
if (testDataBase.getNumberOfTests() < 10) {
System.err.println("There are less than ten test questions in the test question bank, "
+ "and the test paper cannot be generated.");
} else {
int[] testTypeNums = new int[3];
for (String code : testDataBase.getTests().keySet()) {
Test test = testDataBase.getTest(code);
if (test instanceof EnglishTest) {
testTypeNums[0]++;
} else if (test instanceof MathTest) {
testTypeNums[1]++;
} else if (test instanceof ProfessionalTest) {
testTypeNums[2]++;
}
}
if (testTypeNums[0] < 3 || testTypeNums[1] < 3 || testTypeNums[2] < 4) {
System.err.println("There are not enough English questions or math questions or professional "
+ "questions in the test database.");
return;
}
//采用随机生成试卷
Random random = new Random();
ExamPaper examPaper = new ExamPaper();
for (int i = 0; i < testTypeNums.length; i++) {
testTypeNums[i] = 0;
}
int allTestCount = testDataBase.getNumberOfTests();
boolean[] testIsChoose = new boolean[allTestCount];
while (examPaper.getNumberOfTestItems() < 10) {
int target = random.nextInt(allTestCount);
Test test = testDataBase.getTest(target);
if (test instanceof EnglishTest) {
if (testTypeNums[0] < 3 && (!testIsChoose[target])) {
testTypeNums[0]++;
examPaper.addTestItem(new TestItem(test, 0));
testIsChoose[target] = true;
}
} else if (test instanceof MathTest) {
if (testTypeNums[1] < 3 && (!testIsChoose[target])) {
testTypeNums[1]++;
examPaper.addTestItem(new TestItem(test, 0));
testIsChoose[target] = true;
}
} else if (test instanceof ProfessionalTest) {
if (testTypeNums[2] < 4 && (!testIsChoose[target])) {
testTypeNums[2]++;
examPaper.addTestItem(new TestItem(test, 0));
testIsChoose[target] = true;
}
}
}
student.setExamPaper(examPaper);
System.out.println("Test papers have been generated for this student!");
}
}
/**
* 这个方法是老师实现的,做了些许修改以适应我们的代码
* @param id
*/
public void entryScore(String id) throws Exception{
Student student = lookupStudent(id);
int index = 1;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for(TestItem ti:student.getExamPaper().testItems){
System.out.println(String.format("The score of item %d is: ",index));
int score;
while(true) {
try {
score = Integer.parseInt(br.readLine());
break;
} catch (Exception e) {
e.printStackTrace();
}
}
if (score > 10 || score < 0) {
System.err.println("The score of each test is no more than 10 or less than 0. Please re-enter!");
} else {
ti.setScore(score);
}
++index;
}
}
public void lookupTotalScore(String id) throws Exception{
Student student = lookupStudent(id);
Double score = student.getExamPaper().getTotalScore();
if(score!=null){
System.out.println(String.format("The total score of the student is: %f",score));
}else {
System.err.println("The student doesn't get a test paper yet. Please complete it.");
}
}
public void lookupTestScore(String id) throws Exception{
Student student = lookupStudent(id);
int test_items = student.getExamPaper().getNumberOfTestItems();
if(test_items==0){
System.err.println("The student doesn't get a test paper yet. Please complete it.");
}else {
for (int i = 0; i < test_items; i++) {
System.out.println(String.format("The score of item %d is:%f", i + 1, student.getExamPaper().getTestItem(i).getScore()));
}
}
}
private Student lookupStudent(String id) throws Exception{
Student student = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while((student = studentCatalog.getStudent(id))==null){
System.err.println("Error, current student is not exist!");
System.err.print("Student id> ");
id = br.readLine();
}
return student;
}
private void init(){
testDataBase.addTest(new EnglishTest("E001", "Translate the following text into English.", 2,
"Smooth, fluent and without language problems or wrong words", "C-E"));
testDataBase.addTest(new EnglishTest("E002", "Translate the following article content.", 3,
"Clear logic and no language problems", "E-C"));
testDataBase.addTest(new EnglishTest("E003", "Choose the correct answer based on the content being played.", 3,
"Correct answer", "Hearing"));
testDataBase.addTest(new EnglishTest("E004", "Translate the following Chinese in English.", 2,
"No grammatical errors", "C-E"));
testDataBase.addTest(
new EnglishTest("E005", "Translate the following English in Chinese.", 2, "Sentence fluent", "E-C"));
testDataBase.addTest(new EnglishTest("E006", "Choose the correct answer based on contextual dialogue", 2,
"Right", "Hearing"));
testDataBase.addTest(
new EnglishTest("E007", "Translate the following article content.", 3, "Smooth and fluent", "C-E"));
testDataBase.addTest(new EnglishTest("E008", "Translate to Chinese", 3, "Complete translation", "E-C"));
testDataBase.addTest(new EnglishTest("E009", "Listen to the dialogue and choose Xiao Ming’s weekend schedule.",
3, "Correct answer", "Hearing"));
testDataBase.addTest(new EnglishTest("E010", "Translate the following text into English.", 2,
"Use the correct words and smooth", "C-E"));
testDataBase.addTest(new MathTest("M001", "Find the inflection points of the following functions.", 2, "Right",
"no image", "no"));
testDataBase
.addTest(new MathTest("M002", "Which of the following series converge?", 3, "Right", "no image", "no"));
testDataBase.addTest(new MathTest("M003", "Find the differential equation of the following function.", 3,
"Necessary problem-solving process", "no image",
"The first step is to find the integral. The second step is to find the value of the constant c."));
testDataBase.addTest(new MathTest("M004", "Find the angle between the two planes A and B.", 2, "Correct answer",
"http://image.com/m004", "no"));
testDataBase.addTest(new MathTest("M005", "Several extreme points in the figure below.", 3, "Right",
"http://image.com/m005", "no"));
testDataBase.addTest(new MathTest("M006", "Find the inflection points of the following functions.", 2, "Right",
"no image", "no"));
testDataBase.addTest(new MathTest("M007", "Find the differential equation of the following function.", 3,
"Clear problem solving process and correct value", "no image",
"Find the value of the constant b and the differential equation"));
testDataBase
.addTest(new MathTest("M008", "The area enclosed by the following curve and the coordinate axis is?", 1,
"Correct answer", "http://image.com/m008", "no"));
testDataBase.addTest(new MathTest("M009", "Find general solutions of differential equations.", 2,
"The parameters are correct", "no image", "Find the value of the parameter"));
testDataBase
.addTest(new MathTest("M010", "Find the function f(x).", 2, "Right", "http://image.com/m009", "no"));
testDataBase.addTest(new ProfessionalTest("P001", "What are the characteristics of JAVA language?", 1, "Right",
"Name at least three of the characteristics", "no", "no image"));
testDataBase.addTest(new ProfessionalTest("P002",
"Fill in the following blanks to realize the calculation of the sum of the numbers between 1-200 that are not divisible by 5.",
2, "Correct result at run", "Fill in the code in the blank.", "no", "http://image.com/p002"));
testDataBase.addTest(new ProfessionalTest("P003", "The time complexity of the algorithm refers to?", 1,
"Correct answer", "no", "no", "no image"));
testDataBase.addTest(new ProfessionalTest("P004", "The number sequence bai is: 1,1,1,2,3,4,6,...", 3,
"Correct result at run", "Calculation formula when filling in n.",
"int main()\n" + "{int a[21]={0,1,1},i;\n" + " for(i=1;i<21;i++)\n"
+ " if(i<3) printf(\"%d \",a[i]);\n" + " else printf(\"%d \",______);\n"
+ " printf(\"\\n when n is 20:%d\\n\",a[20]);\n" + " return 0;\n" + "}",
"no image"));
testDataBase.addTest(new ProfessionalTest("P005",
"The design of the database includes two aspects of design content, they are?", 2, "Similar in meaning",
"no", "no", "no image"));
testDataBase.addTest(new ProfessionalTest("P006", "The difference between java and c.", 2,
"At least three points", "At least three points", "no", "no image"));
testDataBase.addTest(new ProfessionalTest("P007", "The difference between process and thread.", 3,
"At least three points", "At least three points", "no", "no image"));
testDataBase.addTest(new ProfessionalTest("P008", "The time complexity of the following code is?", 1, "Right",
"no", "no", "http://image.com/p008"));
testDataBase.addTest(new ProfessionalTest("P009", "Benefits of thread pool.", 3, "Can name the key benefits",
"no", "no", "no image"));
testDataBase.addTest(new ProfessionalTest("P010", "Enter 5 numbers to find their maximum and average.", 3,
"Correct result at run", "Time complexity cannot exceed n.)", "no", "no image"));
studentCatalog.addStudent(new Student("2019213001", "吴广胜"));
studentCatalog.addStudent(new Student("2019213002", "陈盛典"));
studentCatalog.addStudent(new Student("2019213003", "刘子豪"));
studentCatalog.addStudent(new Student("2019213004", "仇历"));
studentCatalog.addStudent(new Student("2019213005", "郑西泽"));
studentCatalog.addStudent(new Student("2019213006", "李梦琪"));
studentCatalog.addStudent(new Student("2019213007", "王志"));
studentCatalog.addStudent(new Student("2019213008", "张天一"));
studentCatalog.addStudent(new Student("2019213009", "周琳琳"));
studentCatalog.addStudent(new Student("2019213010", "周爽"));
studentCatalog.addStudent(new Student("2019213011", "张涵"));
studentCatalog.addStudent(new Student("2019213012", "李依然"));
studentCatalog.addStudent(new Student("2019213013", "孟子涛"));
studentCatalog.addStudent(new Student("2019213014", "腊志翱"));
studentCatalog.addStudent(new Student("2019213015", "张一鸣"));
studentCatalog.addStudent(new Student("2019213016", "李华"));
studentCatalog.addStudent(new Student("2019213017", "冷子晴"));
studentCatalog.addStudent(new Student("2019213018", "金灿"));
studentCatalog.addStudent(new Student("2019213019", "朱文杰"));
studentCatalog.addStudent(new Student("2019213020", "刘美含"));
}
public static void main(String[] args) throws Exception{
FushiSystem fushiSystem = new FushiSystem();
fushiSystem.init();
StringBuilder sb = new StringBuilder();
sb.append("[0] quit").append('\n')
.append("[1] Add Students to the system").append('\n')
.append("[2] Display All Students").append('\n')
.append("[3] Display Exam Paper through student identification code").append('\n')
.append("[4] Generate random retests papers for designed students").append('\n')
.append("[5] Enter the retests score of the designed student").append('\n')
.append("[6] Display the total score of the specified student's retest exam").append('\n')
.append("[7] Display the score of each question of the designated student's re-examination exam");
System.out.println(sb.toString());
System.err.print("choice> ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int choice = Integer.parseInt(br.readLine());
while(true) {
switch (choice) {
case 0:{br.close();System.exit(0);break;}
case 1:{
System.err.print("Student id> ");
fushiSystem.addStudentToCatalog(br.readLine());
break;
}
case 2:{
fushiSystem.displayStudentCatalog();
break;
}
case 3:{
System.err.print("Student id> ");
fushiSystem.displayExamPaper(br.readLine());
break;
}
case 4:{
System.err.print("Student id> ");
fushiSystem.generateExamPaper(br.readLine());
break;
}
case 5:{
System.err.print("Student id> ");
fushiSystem.entryScore(br.readLine());
break;
}
case 6:{
System.err.print("Student id> ");
fushiSystem.lookupTotalScore(br.readLine());
break;
}
case 7:{
System.err.print("Student id> ");
fushiSystem.lookupTestScore(br.readLine());
break;
}
}
System.err.print("choice> ");
choice = Integer.parseInt(br.readLine());
}
}
}