瓜大面向对象实验 unit4 复试系统
源码可以上我的微信公众号 :编程研究学社 下载
题目1:文件读写
本次实验需要将Unit3-2中的复试系统改为从文件中读取试题信息并将部分学生试卷信息输出到文件中。
准备工作:在开始本练习之前,您需要精通以下知识:
• Java API - StringTokenizer 类的相关知识;
• 文件读写的相关知识:
怎样从文件中读取数据
怎样向文件中写入数据
目的:增强使用文件读写的能力
背景:在此作业中,您将创建另一个版本的复试系统。在以前的版本中,试题库的试题数据在应用程序中进行了硬编码。 在此版本中,将从文件中加载数据。 而且,用户将能够以以下三种格式之一将学生试卷信息写入文件:纯文本,HTML或XML。部分工作已为您完成,并在学生资料中提供。您将实现加载试题库的试题数据并保存学生试卷信息的代码。
数据文件
试题类型主要分为三种:英语题、数学题和专业课题。testCatalog.dat文件存储着试题库数据。testCatalog.dat中的每一行只包含一个试题。
字段由下划线分割,假定字段本身不包含任何下划线。
英语题数据的格式
EnglishTest_code_title_difficultyDegree_scoreCriteria_type
其中:EnglishTest是标识该行试题类型的前缀;code(string)表示英语题的代码;title(string)表示英语题的题干;difficultyDegree(int)表示英试题的难度系数,其后两项均为string类型,分别表示英试题的得分标准和类型。
数学题数据的格式
MathTest_code_title_difficultyDegree_scoreCriteria_photoURL_calculationProcess
其中:MathTest是标识该行试题类型的前缀;code(string)表示数学题代码;title(string)表示数学题题干;difficultyDegree(int)表示数学题的难度系数,其后三项均为string类型,分别表示数学题的得分标准、图片地址和计算过程。
专业题数据的格式
ProfessionalTest_code_title_difficultyDegree_scoreCriteria_programInstruction_programming_photoURL
其中:ProfessionalTest是标识该行试题类型的前缀;code(string)表示专业
题代码;title(string)表示专业题题干;difficultyDegree(int)表示专业题的难度系数,其后四项均为string类型,分别表示专业题的得分标准、程序说明、程序体和图片地址。
类图
下面是复试系统类图的一部分,显示了用于加载试题库的类图元素。
部分类与接口说明
其中部分类已经出,可以直接使用。
接口FushiTestDatabaseLoader
接口FushiTestDatabaseLoader声明用于生成试题库的方法。
方法:
//将指定文件中的信息加载到试题库中并返回试题库。
Catalog loadTestDatabase(String fileName)
throws FileNotFoundException,
IOException,
DataFormatException
类DataFormatException
当正在分析的文件中有一行出现以下错误时,将抛出异常。
1)该行没有预期数量的字段;
2)应包含数字的字段却没有包含数字。
类FileFushiTestDatabaseLoader
类FileFushiTestDatabaseLoader实现接口FushiTestDatabaseLoader.它用于从文件中获取试题库。
方法:
此方法读取一行英语试题数据。它使用StringTokenizer类提取指定行中的英语试题数据。如果该行没有错误,则此方法返回一个封装英语试题数据的EnglishTest对象。如果该行有错误,则该方法引发一个DataFormatException,其中包含格式错误的数据行。
private EnglishTest readEnglishTest(String line)
throws DataFormatException
此方法读取一行数学试题数据。 它使用StringTokenizer类提取指定行中的数学试题数据。 如果该行没有错误,则此方法返回一个封装数学试题数据的MathTest对象。如果该行有错误,则该方法引发一个DataFormatException,其中包含格式错误的数据行。
private MathTest readMathTest (String line)
throws DataFormatException
此方法读取一行专业题数据。 它使用StringTokenizer类提取指定行中的专业题数据。 如果该行没有错误,则此方法返回一个封装专业题数据的ProfessionalTest对象。如果该行有错误,则该方法引发一个DataFormatException,其中包含格式错误的数据行。
private ProfessionalTest readProfessionalTest(String line)
throws DataFormatException
此方法将指定文件中的信息加载到试题库中并试题库。它首先打开文件然后读取并处理文件中的每一行。使用方法String.startsWith确定每行数据的行类型。
1)如果行类型是EnglishTest,则调用方法readEnglishTest。
2)如果行类型是MathTest,则调用方法readMathTest。
3)如果行类型是ProfessionalTest,则调用方法readProfessionalTest。
处理完该行后,loadTestDatabase将试题添加到试题库中。此方法可能引发以下异常:
FileNotFoundException — 如果指定的文件不存在。
IOException — 如果读取指定文件中的信息时出错。
DataFormatException — 如果文件中的某行有错误(异常应包含格式错误的数据行)。
public TestDatabase loadTestDatabase (String filename)
throws FileNotFoundException,
IOException,
DataFormatException
类FushiSystem
writeFile方法使用指定的名称创建一个新文件,将指定的字符串写入该文件,然后关闭该文件。
其他方法可直接在实验Unit3-2上进行更改或直接沿用Unit3-2中的方法。
任务:
- 根据题目需求实现复试系统,请添加必要的注释。
- 将试题数据文件路径配置到程序运行参数中。
- 与Unit3-2相同,系统会提示选项列表,供用户选择需要输出的格式。当用户选择特定的格式后,系统会创建相应的包含学生试卷信息的文件。
- 实验需要写一个简单的说明文档,其中包括必要的运行说明及运行结果截图。其中包括系统对不同错误的处理反馈。
- 实验提交内容:项目文件及说明文档。
- 实验的输出结果必须和下面展示的结果一致。(此处学生试卷信息与Unit3-2不同,请注意!)
纯文本
如果用户以纯文本保存学生试卷信息(包含学生试卷的试题编号),则应创建包含以下内容的文件:
Student Catalog
2019213001_Wu Guangsheng_P008_P007_P004_E008_E010_P003_E001_M006_M007_M005
2019213002_Chen Shengdian_E008_E005_M003_P003_E002_P004_M010_P007_M007_P008
2019213003_Liu Zihao_M007_P002_P010_M005_E007_M006_P009_E004_P006_E008
2019213004_Chou Li_E009_E007_M008_M010_P004_M001_E002_P005_P003_P002
2019213005_Zheng Xize_E007_E004_M002_P008_P005_E006_M009_M010_P003_P002
2019213006_Li Mengqi_M005_E009_P006_M004_M009_P010_E006_E002_P005_P004
2019213007_Wang Zhi_E005_M002_E009_M009_P004_P006_M007_P002_E002_P007
…
HTML
如果用户以HTML保存学生试卷信息,则应创建包含以下内容的文件:
2019213001 Wu Guangsheng
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
E008|Translate to Chinese|3|Complete translation|E-C
M010|Find the function f(x).|2|Right|http://image.com/m009|no
E003|Choose the correct answer based on the content being played.|3|Correct answer|Hearing
P008|The time complexity of the following code is?|1|Right|no|no|http://image.com/p008
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.
E010|Translate the following text into English.|2|Use the correct words and smooth|C-E
P005|The design of the database includes two aspects of design content, they are?|2|Similar in meaning|no|no|no image
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
P010|Enter 5 numbers to find their maximum and average.|3|Correct result at run|Time complexity cannot exceed n.)|no|no image
2019213002 Chen Shengdian
E004|Translate the following Chinese in English.|2|No grammatical errors|C-E
P005|The design of the database includes two aspects of design content, they are?|2|Similar in meaning|no|no|no image
M005|Several extreme points in the figure below.|3|Right|http://image.com/m005|no
M009|Find general solutions of differential equations.|2|The parameters are correct|no image|Find the value of the parameter
P001|What are the characteristics of JAVA language?|1|Right|Name at least three of the characteristics|no|no image
E006|Choose the correct answer based on contextual dialogue|2|Right|Hearing
E008|Translate to Chinese|3|Complete translation|E-C
P008|The time complexity of the following code is?|1|Right|no|no|http://image.com/p008
M002|Which of the following series converge?|3|Right|no image|no
P009|Benefits of thread pool.|3|Can name the key benefits|no|no|no image
...
XML
如果用户以XML保存学生试卷信息,则应创建包含以下内容的文件:
The time complexity of the following code is?
The difference between process and thread.
The idea of dynamic programming
Translate to Chinese
Translate the following text into English.
The time complexity of the algorithm refers to?
Translate the following text into English.
Find the inflection points of the following functions.
Find the differential equation of the following function.
Several extreme points in the figure below.
Translate to Chinese
Translate the following English in Chinese.
Find the differential equation of the following function.
The time complexity of the algorithm refers to?
Translate the following article content.
The idea of dynamic programming
Find the function f(x).
The difference between process and thread.
Find the differential equation of the following function.
The time complexity of the following code is?
…
题目2:GUI界面
准备工作
在开始本练习之前,您需要精通以下知识:
• 图形用户界面:
Swing组件和容器的知识
Swing事件处理知识
了解JFileChooser对话框
目的:通过事件处理增强您创建GUI的能力
结果:您将掌握以下技能:
• 生产使用Swing GUI的交互式应用程序
背景
在此作业中,您将为复试系统创建一个全面的GUI。部分工作已为您完成,并在学生档案中提供。您将实现处理按钮事件的代码。
描述
类FushiSystemGUI实现了Fushi System的GUI。此GUI使用户可以查看所有学生,为学生生成试卷并显示所有学生的试卷信息:
图1 执行FushiSystemGUI
GUI分为两个面板:学生目录,学生试卷信息:
• “学生目录”面板包含学生的id和name。该面板正下方是一个按钮,用于为列表中选中的学生生成试卷。
• “学生试卷信息”面板包含一个文本区域,用于显示消息和学生试卷信息。 命令按钮显示和保存学生试卷信息; 和单选按钮以指定学生试卷信息在显示或保存时的格式。
当用户单击以下命令按钮之一时,FushiSystemGUI将按如下所述处理关联的事件:
• generateExamPaperButton。 为所选学生生成试卷。如果所选学生已经为其生成过试卷,显示提示信息。
• displayExamPaperButton。 显示所有学生的试卷信息。
• saveExamPaperButton。 将所有学生的试卷信息保存在文件中,没有试卷的学生会显示,“该学生还没有为其生成试卷!”
当用户单击以下单选按钮之一时,FushiSystemGUI将按如下所述处理关联的事件:
• plainRadioButton。 将学生试卷信息的格式更改为纯文本。
• HTMLRadioButton。 将学生试卷信息的格式更改为HTML。
• XMLRadioButton。 将学生试卷信息的格式更改为XML。
当用户在以下列表中选择一个元素时,FushiSystemGUI将按如下所述处理关联的事件:
• catalogList。 返回所选学生对象,获得学生的信息。
FushiSystemGUI定义了以下Swing组件:
• catalogList。 显示学生列表中每个学生的id和name。
• generateExamPaperButton。 为学生生成试卷按钮。
• displayExamPaperButton。 显示学生试卷信息按钮。
• saveExamPaperButton。 保存学生试卷信息按钮。
• statusTestArea。 显示学生试卷信息文本框。
• fileChooser。 一个JFileChooser对象。允许用户指定将保存学生试卷信息的文件的名称和位置。单击“Save ExamPaper”按钮时,将显示此对话框。
FushiSystemGUI定义以下实例变量:
• studentCatalog。包含所有学生的目录对象。
• testDatabase。一个包含所有Test的对象。
• studentsFormatter。一个StudentsFormatter对象,指定显示或保存学生试卷信息时要使用的格式。
按钮事件是使用类FushiSystemGUI中的命名内部类处理的。 以下内部类是完整的,不应修改:
• •DisplayStudentListener。 学生列表的侦听器
• •GenerateExamPaperListener。 按钮“Generate ExamPaper”的侦听器
• •PlainListener。 单选按钮“ Plain”的侦听器
• •HTMLListener。 单选按钮“ HTML”的侦听器
• •XMLListener。 单选按钮“ XML”的侦听器
• •DisplayExamPaperListener。 按钮“Display ExamPaper”的侦听器
• •SaveExamPaperListener。 按钮“Save ExamPaper”的侦听器
在此分配中,您应该完成以下内部类的实现:
• •DisplayExamPaperListener。按钮“Display ExamPaper”的监听器
• •SaveExamPaperListener。 按钮“Save ExamPaper”的监听器
文件
需要以下文件来完成此任务:
• •示例/FushiSystemGUI.jar。下载此文件。它是示例可执行文件。
• •student-files。下载此文件。该档案包含以下内容:
o Class文件
TestDatabase.class
FushiTestDatabaseLoader.class
StudentCatalog.class
Test.class
DataFormatException.class
FileFushiTestDatabaseLoader.class
HTMLStudentsFormatter.class
ExamPaper.class
PlainTextStudentsFormatter.class
TestItem.class
EnglishTest.class
MathTest.class
ProfessionalTest.class
Student.class
StudentFormatter.class
XMLStudentsFormatter.class
o Java文件
FushiSystemGUI.java。 使用此模板可完成您的实现。
o 用于测试驱动程序的数据文件
o testCatalog.dat。 试题库中包含每道试题的试题信息文件
任务
完成DisplayExamPaperListener和SaveExamPaperListener的实现。这些内部类在状态区域中显示的消息应与示例可执行文件显示的消息匹配。
遵循Sun的代码约定。 以下步骤将指导您完成此作业。 逐步工作并测试每个增量。经常保存。
- 通过在命令提示符处发出以下命令来运行示例可执行文件:
java -jar FushiSystemGUI.jar - 添加外部类文件夹。
- 然后在内部类DisplayExamPaperListener中实现方法actionPerformed:在statustextarea中显示学生试卷信息。信息应以单选按钮选择指示的格式显示。您将在类别StudentsFormatter中使用formatStudents。
- 接下来,在内部类SaveExamPaperListener中实现方法actionPerformed:将学生试卷信息保存在文件中。首先打开文件选择器,以便用户可以指定将保存学生试卷信息的文件的名称和位置。接下来,将学生试卷信息保存在指定的文件中。该文件应以单选按钮选择指示的格式保存。最后,在状态区域中显示状态消息。
- 最后编译并执行类FushiSystemGUI。
提交
完成后,仅提交以下内容。 - FushiSystemGUI.java
Eclipse 填写运行参数的方法
鼠标双击 Java Application 下方出现FushiSystemGUI,点击Arguments选项卡。
在Program arguments输入框内填写数据文件名称,该数据文件拷贝到工程项目目录文件下(注意不要拷贝到src目录下)



