结对编程1-基于GUI的四则运算生成器
201421123016郑怀勇 201421123017康建灿
一、需求分析
- 记录用户的对错总数。
- 程序退出再启动的时候,能把以前的对错数量保存并在此基础上增量计算。
- 有计时功能,能显示用户开始答题后的消耗时间。
- 具有GUI界面
二、功能设计

三、代码展示:
读取记录:
boolean has = false;
int t=0,f=0;
File file = new File("D:/text.txt");
String line =null;
try {
BufferedReader br = new BufferedReader(new FileReader(file));
try {
while((line = br.readLine()) != null){
String[] num = line.split("#");
f=Integer.parseInt(num[1]);
t=Integer.parseInt(num[3]);
}} catch (IOException ex) {
}
}catch (Exception e) {
e.printStackTrace();
}
if(!has)
tagLabel1.setText("无记录");
文件数据保存:
public class pro {
int t = 0, f = 0;
void file(int d, int count) {
File file = new File("D:/text.txt");
String line = null;
try {
BufferedReader br = new BufferedReader(new FileReader(file));
try {
while ((line = br.readLine()) != null) {
String[] num = line.split("#");
t = Integer.parseInt(num[1]);
f = Integer.parseInt(num[3]);
}
} catch (IOException ex) {
}
} catch (FileNotFoundException ex) {
get(d, count);
}
get(d, count);
}
public void get(int d, int count) {
FileOutputStream fop = null;
File file;
String content = "错误#" + (d + t) + "#正确#" + (count + f) + "#";
try {
file = new File("D:/text.txt");
fop = new FileOutputStream(file);
if (!file.exists()) {
file.createNewFile();
}
byte[] contentInBytes = content.getBytes();
fop.write(contentInBytes);
fop.flush();
fop.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fop != null) {
fop.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
随机生成四则运算及正确答案:
int a[][]=null;
a=new int [1000][3];
String[] b=null;
b=new String [1000];
String stil[]=null;
stil=new String[1000];
int i = 0; for(;i<m;i++){
int h=(int)(0+Math.random()*(1-0+1));
if(h==1){
Zhengshu(i,b,c);
}
else
{
Fenshu(i,b,a,c);
}
answerEdit[i] = new JTextField();
panel.add(new JLabel(b[i]));
panel.add(answerEdit[i]);
} ``` public static String Fenshu(int i, String b[], int a[][], String c[]) {
int x = (int) (0 + Math.random() * (9 - 0 + 1));
int y = (int) (0 + Math.random() * (9 - 0 + 1));
while (x >= y || y == 0 || x == 0) {
x = (int) (0 + Math.random() * (9 - 0 + 1));
y = (int) (0 + Math.random() * (9 - 0 + 1));
}
int k = (int) (0 + Math.random() * (9 - 0 + 1));
int t = (int) (0 + Math.random() * (9 - 0 + 1));
while (k >= t || t == 0 || k == 0) {
k = (int) (0 + Math.random() * (9 - 0 + 1));
t = (int) (0 + Math.random() * (9 - 0 + 1));
}
int o = (int) (0 + Math.random() * (3 - 0 + 1));
if (o == 0) {
b[i] = "(" + x + "/" + y + ")+(" + k + "/" + t + ")=";
a[i][0] = x * t + k * y;
a[i][1] = y * t;
int n = divisor(a[i][0], a[i][1]);
c[i] = a[i][0] / n + "/" + a[i][1] / n;
}
if (o == 1) {
b[i] = "(" + x + "/" + y + ")-(" + k + "/" + t + ")=";
a[i][0] = x * t - k * y;
a[i][1] = y * t;
int n = divisor(a[i][0], a[i][1]);
c[i] = a[i][0] / n + "/" + a[i][1] / n;
}
if (o == 2) {
b[i] = "(" + x + "/" + y + ")*(" + k + "/" + t + ")=";
a[i][0] = x * k;
a[i][1] = y * t;
int n = divisor(a[i][0], a[i][1]);
c[i] = a[i][0] / n + "/" + a[i][1] / n;
}
if (o == 3) {
b[i] = "(" + x + "/" + y + ")÷(" + k + "/" + t + ")=";
a[i][0] = x * t;
a[i][1] = k * y;
int n = divisor(a[i][0], a[i][1]);
c[i] = a[i][0] / n + "/" + a[i][1] / n;
}
return b[i] + c[i];
}; public static String Zhengshu(int i, String b[], String c[]) {
int x = (int) (0 + Math.random() * (100 - 0 + 1));
int y = (int) (0 + Math.random() * (100 - 0 + 1));
int z = (int) (0 + Math.random() * (3 - 0 + 1));
if (z == 0) {
b[i] = x + "+" + y + "=";
c[i] = x + y + "";
}
if (z == 1) {
b[i] = x + "-" + y + "=";
c[i] = x - y + "";
}
if (z == 2) {
b[i] = x + "*" + y + "=";
c[i] = x * y + "";
}
if (z == 3) {
b[i] = x + "÷" + y + "=";
int n = divisor(x, y);
c[i] = x / n + "/" + y / n;
}
return b[i] + c[i];
} public static int divisor(int i, int j)// 最大公约数
{
int k = 1, s;
for (s = 1; s <= i && s <= j; s++) {
if (i % s == 0 && j % s == 0)
k = s;
}
return k; }
计时器:
JLabel timeText = new JLabel();
now.setHours(0);
now.setMinutes(0);
now.setSeconds(0);
final Timer timer = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
Date now2 = new Date(now.getTime() + 1000);
now = now2;
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
timeText.setText(formatter.format(now));
}
});
timer.start();
timeText.setText("用时 :" + timeText.getText());
// timeText.setText("time");
commitBtn = new JButton("确定");
commitBtn.addActionListener(this);
commitBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
timer.stop();
```
}
显示结果:
public result(int m2, int count2,double g2,String time2) {
// TODO Auto-generated constructor stub
this.setBounds(500, 250, 450, 200);
this.setResizable(true);
this.m=m2;
this.count=count2;
this.g=g2;
this.time=time2;
this.setTitle("四则运算");
jg();
}
private void jg(){
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout(5,5));
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(2,2));
panel.add(new JLabel("本次共出"+m+"题,答对"+count+"题,正确率为:"+g+",用时 :"+time));
JPanel panel2 = new JPanel();
mainPanel.add("Center",panel);
mainPanel.add("South",panel2);
add(mainPanel);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
四、测试运行截图:
主界面:

生成四则运算:

结果:

存储于文本:

五、PSP
| PSP2.1 | Personal Software Process Stages | Estimated time(h) | actual time(h) |
| Planning | 计划 | 1 | 1.5 |
| · Estimate | 估计这个任务需要多少时间 | 24 | 40 |
| Development | 开发 | 24 | 34 |
| · Analysis | 需求分析 (包括学习新技术) | 1 | 1.2 |
| · Design Spec | 生成设计文档 | 7 | 10 |
| · Design Review | 设计复审 | 0.5 | 0.5 |
| · Coding Standard | 代码规范 | 0.5 | 0.8 |
| · Design | 具体设计 | 1.5 | 1.5 |
| · Coding | 具体编码 | 20 | 30 |
| · Code Review | 代码复审 | 10 | 15 |
| · Test | 测试(自我测试,修改代码,提交修改) | 1 | 3 |
| Reporting | 报告 | 20 | 25 |
| · | 测试报告 | 1 | 1.5 |
| · | 计算工作量 | 0.5 | 1 |
| · | 并提出过程改进计划 | 2 | 4 |
六、总结
此次与康建灿一起完成结队作业,先对功能进行分析,最后选取了存储功能以及计时器功能,并以康建灿的代码作为基础代码进行扩展延伸。由于2个人的编程能力都不是很强,过程中一直磕磕碰碰,有很多不懂,尤其是在图形界面方面,可以说2个人都很薄弱,一直在巩固以前学习的Java知识。
而结队无疑提高了我们的效率,俗话说三个臭皮匠顶个诸葛亮,在编程过程中,能够达到互相监督,互相学习的效果。正所谓旁观者清,当其中一个人在编程,另一个人就能在旁边更直观地发现错误。
汉堡包点评:
先来一片面包:我们有着共同的目标,都想写好一个代码,能给对方予以依靠;
再把肉放上:就算2个人的编程能力都不是很好,但也不能自暴自弃,更不能嫌弃对方,而是应该互相鼓励,强调我们可以做到更好;
然后再来一片面包:最后,思路与方向都清晰了,这时,更应该互相激励,努力做到更好。
七,综上,附上合照一张

结对编程1-基于GUI的四则运算生成器的更多相关文章
- 结对编程1 —— 基于GUI和Swing的四则运算题目生成器
合作伙伴 201421123102 王艳秋 201421123106 陈 雄 代码地址 题目描述 我们在个人作业1中,用各种语言实现了一个命令行的四则运算小程序.进一步,本次要求把这个程序做成GUI( ...
- 结对作业--基于GUI的四则运算生成器
组员:201421123015 陈麟凤 201421123019 张志杰 201421123020 黄海鸿 coding 地址 :https://coding.net/u/zhang1995/p/wo ...
- 结队编程-基于gui的四则运算生成器
成员:卢少锐 201421123027.刘存201421033023 coding.net地址 1.需求分析:除了实现四则运算的功能外,还添加了计时器功能和语言选择功能 2.程序设计:这次作业是基于上 ...
- 结对作业1----基于GUI的四则运算生成器
组员:201421123015 陈麟凤 201421123019 张志杰 201421123020 黄海鸿 coding 地址:代码点这里 需求分析: 1.除了整数的四则运算还要支持分数的四则运算: ...
- 结对编程1----基于java的四则运算生成器
小组成员:王震(201421123054).王杰(201421123055) Coding地址:https://git.coding.net/a506504661/sssss.git 一.题目描述 我 ...
- 结对作业:基于GUI实现四则运算
1)Coding.Net项目地址:https://git.coding.net/day_light/GUIszysLL.git 2)在开始实现程序之前,在下述PSP表格记录下你估计将在程序的各个模块的 ...
- 结对编程——paperOne基于java的四则运算 功能改进
项目成员:张金生 张政 由于新的需求,原本使用JSP的实现方式目前改为Java实现,即去除了B/S端. 需求分析: 1.四则运算要满足整数运算.分数运算两种: 2.运算题目随机,并且可以打印题 ...
- 结对编程1--基于GUI的四则运算题目生成器
最终项目详细代码(coding地址)/李志强的博客/我的详细代码/方言的博客 一.需求分析 1.实现之前项目的功能,如:除了整数之外,还要支持真分数的四则运算,真分数的运算,并且要求能处理用户的输入, ...
- 基于GUI的四则运算
基于GUI的四则运算 李志强 201421123028 连永刚 201421123014 林方言 201421123023 coding 地址 https://git.coding.net/lizhi ...
随机推荐
- 2016 "Bird Cup" ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛
"波导杯"安徽科技学院第七届程序设计大赛 Contest - 2016 "Bird Cup" ICPC7th@ahstu Start time: 2016-0 ...
- webpack的四个核心概念介绍
前言 webpack 是一个当下最流行的前端资源的模块打包器.当 webpack 处理应用程序时,它会递归地构建一个依赖关系图(dependency graph),其中包含应用程序需要的每个模块,然后 ...
- 【社交系统研发日记五】ThinkSNS+如何计算字符显示长度?
今天我们来聊一下可能很多人都会头疼的东西:显示长度. 需求是这样的,在字符的显示上,两个英文单词才占一个中文或者其他语言的显示长度.如下: 上面排的是两个英文字母,一个汉字,一个Emoji.你会发现, ...
- RMAN备份-未使用catalog-控制文件丢失
情况描述 客户报告数据库故障,新来的系统管理员误操作.删掉了一些文件.具体情况是:删掉了所有重要数据文件.所有控制文件.数据库原来是归档模式,用rman备份数据,而rman 使用控制文件. 幸运的是, ...
- JS和OC交互的简单应用
先简单地说一下思路吧 需求:在App中嵌入一个webView,已经有了网址,但是需要去掉这个网页中的一些内容 解决方案:取到webView要加载的网址,对这个网址对应的网页信息进行修改 简单描述: 遵 ...
- js通过添加随机数的方法,解决多张图片加载时由于缓存导致图片无法正确显示的问题
问题出现描述:当对列表中某个图片进行重新编辑时,提交后会发现图片列表仍会出现修改之前的图片,新图片并未覆盖. 问题出现原因:缓存问题. 解决办法:通过js方法,在每张图片路劲后面添加一个随机数,这样每 ...
- 为什么新生代内存需要有两个Survivor区
转载自:http://blog.csdn.net/antony9118/article/details/51425581 在JVM的新生代内存中,为什么除了Eden区,还要设置两个Survivor区? ...
- js中高度与宽度的获取
JS获取各种宽度.高度的简单介绍: scrollHeight: 获取对象的滚动高度. scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离 scrollTop:设置或获 ...
- 利用浏览器调试APP中的H5页面
安卓手机的情况下,可以用chrome浏览器来调试. 打开地址: chrome://inspect/#devices 手机用USB数据线连接电脑,并启动USB调试模式. 只要在APP中打开H5页面,界面 ...
- 有了 indexOf,为什么 ECMAScript 7 还添加了 Array.prototype.include
ECMAScript 7 中新增了用于检测数组中是否包含某个元素 Array.prototype.includes() API,想到了 Array 其实有很多相关 API 可以检测到是否包含某个元素, ...