作业来源:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2213
GitHub地址:https://github.com/pbygakki/testone
调试环境:Intellij IDEA
结对伙伴:张劲 201606120014 博客地址:https://www.cnblogs.com/zjby/
胡雄柏 201606120022 博客地址:https://www.cnblogs.com/trojans/
一、程序基本要求
-
- 自动生成题目,单个题目最多不能超过4个运算符,操作数小于100。
- 用户可以输入答案
- 若用户输入答案正确,则提示正确;若答案错误,则提示错误,并要提示正确答案是多少。
二、四个扩展方向
- 可以出表达式里含有负整数(负整数最小不小于-100)的题目,且负数需要带括号,用户输入的结果不用带括号。如: 2*(-4) = -8(胡雄柏)
- 用户答题结束以后,程序可以显示用户答题所用的时间。(张劲)
- 程序可以出单个整数阶乘的题目:如:4!=24;(张劲) 程序可以设置皮肤功能,可以改变界面的颜色即可。(胡雄柏)
三、时间记录表
Personal Software Process Stages Time Senior Student Time Planning 计划 1 0.5 Estimate 估计这个任务需要多少时间 70 72 Development 开发 60 65 Analysis 需求分析 (包括学习新技术) 1 0.5 Design Spec 生成设计文档 0.5 0.5 Design Review 设计复审 1 1 Coding Standard 代码规范 0.5 0.5 Design 具体设计 2 3 Coding 具体编码 5 4 Code Review 代码复审 3 2 Test 测试(自我测试,修改代码,提交修改) 4 5 Presentation 报告 2 1 Test report 测试报告 3 0.5 Computational effort 计算工作量 0.5 0.5 Propose process improvement plan 并提出过程改进计划 1 0.5
四、结对过程
- 结对照片:
- 结对收获和感想:
我们都是第一次组队,但是在看清楚扩展方向和功能后,就自觉地上网查找资料,然后选择自己的功能实现方向。由于有上一次简单的四则运算的工程下,这次只是添加功能的总体方向。在功能的实现上其实所花的实现并不是很多,更多的时间花费在了功能的整合上,因为用到了不熟悉的界面,而不是简单的控制台程序,大量的阅读资料和查找资料来补充自己的学识。而且重要的是,我们两个在实现代码上的思想是不统一的,在整合到同一程序上的时候,需要两个人互相一边解释自己的程序代码然后按照统一的代码规范写下来,这一点我觉得是可以更加完善的。
五、部分代码
阶乘运算l界面:
////////////////////////阶乘运算 Tab factorialOperate = new Tab("阶乘运算"); VBox factorialVBox = new VBox(); factorialVBox.setStyle("-fx-border-color: black"); factorialVBox.setAlignment(Pos.CENTER); factorialVBox.setSpacing(10); factorialOperate.setContent(factorialVBox); HBox factorialRequireHBox = new HBox(); factorialRequireHBox.setAlignment(Pos.CENTER); factorialRequireHBox.setSpacing(20); Label factorialRequireLabel = new Label(); factorialRequireLabel.setText("阶乘运算。\n\n"); factorialRequireLabel.setFont(Font.font(20)); factorialRequireHBox.getChildren().add(factorialRequireLabel); HBox factorialNumHBox = new HBox(); factorialNumHBox.setMinSize(100, 50); factorialNumHBox.setStyle("-fx-border-color: gray"); factorialNumHBox.setStyle("-fx-background-color: #dddddd"); factorialNumHBox.setAlignment(Pos.CENTER); factorialNumHBox.setSpacing(20); Label factorialNumLabel = new Label(); factorialNumLabel.setText("请输入题目数:"); factorialNumLabel.setFont(Font.font(18)); TextField factorialNumText = new TextField(); factorialNumText.setPrefSize(50, 20); Button factorialSubNumBtn = new Button("确认"); factorialNumHBox.getChildren().addAll(factorialNumLabel, factorialNumText, factorialSubNumBtn); HBox factorialTitleHBox = new HBox(); factorialTitleHBox.setMinSize(100, 50); factorialTitleHBox.setStyle("-fx-border-color: gray"); factorialTitleHBox.setStyle("-fx-background-color: #dddddd"); factorialTitleHBox.setAlignment(Pos.CENTER); factorialTitleHBox.setSpacing(20); Label factorialTitleLabel = new Label(); factorialTitleLabel.setText("请计算:"); TextField factorialTitleText = new TextField(); factorialTitleText.setPrefSize(80, 20); factorialTitleText.setDisable(true); factorialTitleLabel.setFont(new Font(16)); TextField factorialAnsText = new TextField(); factorialAnsText.setPrefSize(200, 20); Button factorialSubmitAnsBtn = new Button("确定答案"); factorialTitleHBox.getChildren().addAll(factorialTitleLabel, factorialTitleText, factorialAnsText, factorialSubmitAnsBtn); HBox factorialAnsHBox = new HBox(); factorialAnsHBox.setMinSize(100, 50); factorialAnsHBox.setStyle("-fx-border-color: gray"); factorialAnsHBox.setStyle("-fx-background-color: #dddddd"); factorialAnsHBox.setAlignment(Pos.CENTER); factorialAnsHBox.setSpacing(20); Label factorialUserAnsLabel = new Label(); factorialUserAnsLabel.setText("您的答案为:"); factorialUserAnsLabel.setFont(new Font(16)); TextField factorialUserAnsText = new TextField(); factorialUserAnsText.setPrefSize(200, 20); factorialUserAnsText.setDisable(true); factorialUserAnsText.minWidth(50); Label factorialRightAnsLabel = new Label(); factorialRightAnsLabel.setText("正确答案为:"); factorialRightAnsLabel.setFont(new Font(16)); TextField factorialRightAnsText = new TextField(); factorialRightAnsText.setPrefSize(200, 20); factorialRightAnsText.setDisable(true); Button factorialNextTitleBtn = new Button("下一题"); factorialNextTitleBtn.setDisable(true); factorialAnsHBox.getChildren().addAll(factorialUserAnsLabel, factorialUserAnsText, factorialRightAnsLabel, factorialRightAnsText, factorialNextTitleBtn); VBox factorialJudgeVBox = new VBox(); factorialJudgeVBox.setAlignment(Pos.CENTER); Label factorialRightRate = new Label(); factorialRightRate.setText("正确率:\t\t" + "得分:"); factorialRightRate.setFont(new Font(20)); Label factorialjudgeTF = new Label(); factorialjudgeTF.setFont(new Font(20)); factorialJudgeVBox.getChildren().addAll(factorialjudgeTF, factorialRightRate); factorialSubNumBtn.setOnMouseClicked(event -> { try { startDoTestTime = System.currentTimeMillis(); titleNum = Integer.parseInt(factorialNumText.getText().trim()); factorialSubNumBtn.setDisable(true); factorialNumText.setDisable(true); factorialRandTitle(); factorialTitleText.setText(titleString); factorialNextTitleBtn.setDisable(false); factorialRightRate.setText("正确率:" + correctRate + "%\t" + "得分:" + correctAnswerNum * 10); } catch (Exception e) { Alert alert = new Alert(Alert.AlertType.WARNING, "要求输入正整数,请按要求输入!"); alert.setTitle("不合法输入"); alert.setHeaderText(""); alert.show(); } }); factorialSubmitAnsBtn.setOnMouseClicked(event -> {////////////////////////////////////////////////////////////////////////////// if (factorialSubNumBtn.isDisabled()) { try { factorialSubmitAnsBtn.setDisable(true); factorialAnsText.setDisable(true); long temp = (Long.parseLong(factorialAnsText.getText().trim())); factorialUserAnsText.setText(temp + ""); factorialRightAnsText.setText(factorialResult + ""); if (temp == factorialResult) { factorialjudgeTF.setText("恭喜你,答对了!"); correctAnswerNum++; correctRate = (float) correctAnswerNum / titleNum * 100; factorialRightRate.setText("正确率:" + correctRate + "%\t" + "得分:" + correctAnswerNum * 10); } else { factorialjudgeTF.setText("答错了,细心答题正确率更高哦!"); factorialRightRate.setText("正确率:" + correctRate + "%\t" + "得分:" + correctAnswerNum * 10); } factorialNextTitleBtn.setDisable(false); } catch (Exception e) { factorialSubmitAnsBtn.setDisable(false); factorialAnsText.setDisable(false); Alert alert = new Alert(Alert.AlertType.WARNING, "输入内容不合法(内容不能为空、不能有字母等)!"); alert.setTitle("不合法输入!"); alert.setHeaderText(""); alert.show(); } } else { Alert alert = new Alert(Alert.AlertType.WARNING, "请先输入题目数并确定!"); alert.setTitle("不合法操作!"); alert.setHeaderText(""); alert.show(); } }); factorialNextTitleBtn.setOnMouseClicked(event -> { if (!factorialSubmitAnsBtn.isDisabled()) { if (i < titleNum) { Alert noAnsTitle = new Alert(Alert.AlertType.CONFIRMATION, "你确定跳过这一题吗?"); noAnsTitle.setTitle("跳过这一题"); noAnsTitle.setHeaderText(""); Optional<ButtonType> result = noAnsTitle.showAndWait(); if (result.get() == ButtonType.OK) { //跳过这一题 factorialAnsText.setText(""); factorialRandTitle(); i++; factorialTitleText.setText(titleString); } } else { ansAll(); factorialRightRate.setText("正确率:" + correctRate + "%\t" + "得分:" + correctAnswerNum * 10 + "\t耗时:" + costTime + "s"); startDoTestTime = 0; endDoTestTime = 0; costTime = 0; factorialNextTitleBtn.setDisable(true); } } else { if (i < titleNum) { factorialRandTitle(); i++; factorialTitleText.setText(titleString); factorialAnsText.setText(""); factorialAnsText.setDisable(false); factorialSubmitAnsBtn.setDisable(false); factorialUserAnsText.setText(""); factorialRightAnsText.setText(""); factorialjudgeTF.setText(""); } else { ansAll(); factorialNextTitleBtn.setDisable(true); factorialRightRate.setText("正确率:" + correctRate + "%\t" + "得分:" + correctAnswerNum * 10 + "\t耗时:" + costTime + "s"); startDoTestTime = 0; endDoTestTime = 0; costTime = 0; } } });
六、程序运行截图
一)表达式含有不小于-100的负整数,负数带括号:
![]() |
二)修改程序背景颜色:
![]() ![]() |
三)用户答题结束提示所用时间:
![]() |
四)阶乘题目:
![]() |
五)容错
输入不合法字符时:
![]() ![]() |
未填写题目数量并点击确定按钮就点击确认答案时:
![]() ![]() |