import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Random; import javax.swing.*;
public class MainJFrame extends JFrame {
JButton b1=new JButton("切换皮肤");JButton b2=new JButton("GOGOGO!");JButton b3=new JButton("开始/下一题");
int xz, cc,count,max,min=1,jc,sum1,dt=0,tm=0,tm1=0,zs1,zs2,fs1,fs2,fs3,fs4;
char ssfh[]={'+','-','*','/'};
int fh;
String Sum1,Sum2;
long star,end;
JLabel l1=new JLabel(" 题目");JLabel l2=new JLabel(" 得数");
JTextField t1=new JTextField(10);JTextField t2=new JTextField(8);
String [] path={
"0.jpg",
"1.jpg",
"2.jpg"};
public MainJFrame(int count1,int cc1,int xz1,int max1,long star1) {
count=count1;
cc=cc1;
xz=xz1;
max=max1;
star=star1;
//设置大小
setSize(500, 400);
//设置位置
setLocation(200, 50);
//背景图片的路径。(相对路径或者绝对路径。本例图片放于"java项目名"的文件下)
// 背景图片
ImageIcon background = new ImageIcon(path[1]);
// 把背景图片显示在一个标签里面
JLabel label = new JLabel(background);
// 把标签的大小位置设置为图片刚好填充整个面板
label.setBounds(0, 0, this.getWidth(), this.getHeight());
// 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明
JPanel imagePanel = (JPanel) this.getContentPane();
imagePanel.setOpaque(false);
// 把背景图片添加到分层窗格的最底层作为背景
imagePanel.setLayout(new FlowLayout(FlowLayout.CENTER,20,100));
this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
imagePanel.add(l1);imagePanel.add(t1);imagePanel.add(l2);imagePanel.add(t2);imagePanel.add(b1);imagePanel.add(b3);imagePanel.add(b2);
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(xz==1)
{
if(tm1<count){
tm1++;
zs1=new Random().nextInt(max) + min;
zs2=new Random().nextInt(max) + min;
fh=new Random().nextInt(4);
while(fh==3&&zs2==0){
zs2=new Random().nextInt(max) + min;
}
Zhengshu zhengshu=new Zhengshu(zs1,fh,zs2);
if(fh==0){
t1.setText(zhengshu.getJiaf());
zhengshu.setJiaf(zs1, zs2);
}
else if(fh==1){
t1.setText(zhengshu.getJianf());
zhengshu.setJianf(zs1, zs2);
}
else if(fh==2){
t1.setText(zhengshu.getChengf());
zhengshu.setChengf(zs1, zs2);
}
else if(fh==3){
t1.setText(zhengshu.getChuf());
zhengshu.setChuf(zs1, zs2);
}
}
}
else if(xz==2){
if(tm1<count){
tm1++;
fs1=new Random().nextInt(max) + min;
fs2=new Random().nextInt(max) + min;
fs3=new Random().nextInt(max) + min;
fs4=new Random().nextInt(max) + min;
Fenshu fenshu=new Fenshu();
fh=new Random().nextInt(3);
t1.setText(fenshu.suanshi(fs1, fs2, fs3, fs4, fh));
}
}
else{
if(tm1<count){ tm1++;
jc=new Random().nextInt(max) + min;t1.setText("("+ tm1 +")"+jc+"!="); }
} }
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(xz==1)
{
if(tm<count)
{
Zhengshu zhengshu=new Zhengshu();
if(fh==0){
zhengshu.setJiaf(zs1, zs2);
}
else if(fh==1){
zhengshu.setJianf(zs1, zs2);
}
else if(fh==2){
zhengshu.setChengf(zs1, zs2);
}
else if(fh==3){
zhengshu.setChuf(zs1, zs2);
}
if(fh==3)
{Sum2=t2.getText();
Sum1=zhengshu.getsum(zs1,zs2);
if(Sum1.equals(Sum2))
dt++; }
else{
if((sum1=Integer.valueOf(t2.getText()))==zhengshu.getSum())
dt++;
} tm++;
t2.setText(null);
// System.out.print(tm+"\t"+zs1+"\t"+fh+"\t"+zs2+"\t"+dt+"\t"+zhengshu.getSum()+"\t"+Sum1+"\n");
}
if(tm==count){
end=System.currentTimeMillis()/1000;
// System.out.print("\t"+end+"\t"+star+"\t"+(end-star));
JOptionPane.showMessageDialog(rootPane, "一共"+count+"道题,答对"+dt+"道题!\t" +"得分"+(100/count*dt)+"用时"+(end-star)+"s");
} }
else if(xz==2){
if(tm<count)
{
Fenshu fenshu=new Fenshu();
Sum1=fenshu.answer(fs1, fs2, fs3, fs4, fh);
Sum2=t2.getText();
if(Sum1.equals(Sum2))
{
dt++;
}
tm++;
t2.setText(null);
// System.out.print(tm+"\t"+dt+"\t"+fenshu.answer(fs1, fs2, fs3, fs4, fh)+"\t"+Sum2+"\t"+fh+"\n");
if(tm==count){
end=System.currentTimeMillis()/1000;
// System.out.print("\t"+end+"\t"+star+"\t"+(end-star));
JOptionPane.showMessageDialog(rootPane, "一共"+count+"道题,答对"+dt+"道题!\t" +"得分"+(100/count*dt)+"用时"+(end-star)+"s");
}
}
}
else{
if(tm<count)
{
Jiecheng jiecheng=new Jiecheng(jc);
if((sum1=Integer.valueOf(t2.getText()))==jiecheng.getJieguo())
{
dt++;
}
tm++;
t2.setText(null);
System.out.print(tm+"\t"+jc+"!\t"+dt+"\t"+jiecheng.getsum()+"\t"+sum1+"\n");
}
if(tm==count){
end=System.currentTimeMillis()/1000;
// System.out.print("\t"+end+"\t"+star+"\t"+(end-star));
JOptionPane.showMessageDialog(rootPane, "一共"+count+"道题,答对"+dt+"道题!\t" +"得分"+(100/count*dt)+"用时"+(end-star)+"s");
}
} }
});
//设置可见
setVisible(true);
//点关闭按钮时退出
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} public static void main(String[] args) {
Baseframe frame=new Baseframe(); }
}
class Baseframe extends JFrame //基础界面
{
public Baseframe(){
super("四则运算 V2.0");
this.getContentPane().add(new p1(),"Center");
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setSize(500, 400);
this.setLocation(200, 50);
this.setVisible(true); } public static void close() {
// TODO Auto-generated method stub }
}
class p1 extends JPanel{
int xz, cc,count,max,min=1;long star;
JLabel l1=new JLabel(" 输入题目数");JLabel l2=new JLabel(" 是否有乘除法0/1");JLabel l3=new JLabel(" 数值范围是(1~)");JLabel l4=new JLabel(" 1:整数运算.2:分数运算.3:阶乘运算.");
JLabel l5=new JLabel();
JButton b1=new JButton("确定");
JTextField t1=new JTextField(8);JTextField t2=new JTextField(8);JTextField t3=new JTextField(8);JTextField t4=new JTextField(8);
int str=0;
int str1=0;
p1(){
super(new GridLayout(5,2,5,5));
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
count=Integer.valueOf(t1.getText());
cc=Integer.valueOf(t2.getText());
max=Integer.valueOf(t3.getText());
xz=Integer.valueOf(t4.getText());
star = System.currentTimeMillis()/1000;
MainJFrame Frame=new MainJFrame(count,cc,xz,max,star);
}
});
add(l1);add(t1);add(l2);add(t2);add(l3);add(t3);add(l4);add(t4);add(l5);add(b1);
}
public int getcount()
{
return count;
}
public int getcc()
{
return cc;
}
public int getmax()
{
return max;
}
public int getxz()
{
return xz;
}
public long getstar()
{
return star;
}
} public class Zhengshu {
int zs1,zs2,sum=1;int fh;
Zhengshu(){ }
Zhengshu(int Zs1,int Fh,int Zs2){
zs1=Zs1;
fh=Fh;
zs2=Zs2;
}
public void setJiaf(int Zs1,int Zs2){
sum=Zs1+Zs2;
}
public void setJianf(int Zs1,int Zs2){
sum=Zs1-Zs2;
}
public void setChengf(int Zs1,int Zs2){
sum=Zs1*Zs2;
}
public void setChuf(int Zs1,int Zs2){
sum=Zs1/Zs2;
}
public String getJiaf(){
return zs1+"+"+zs2;
}
public String getJianf(){
return zs1+"-"+zs2;
}
public String getChengf(){
return zs1+"*"+zs2;
}
public String getChuf(){
return zs1+"/"+zs2;
}
public int getSum(){
return sum;
}
public String getsum(int zs1,int zs2){
return zs1+"/"+zs2;
}
} public class Jiecheng {
private int jc1;
private int sum=1;
private int n;
Jiecheng(){ }
Jiecheng(int jc){
jc1=jc; }
public int getJieguo()
{
if(jc1==0)
sum=1;
else{
for(n=1;n<=jc1;n++)
{
sum=sum*n;
}
}
return sum;
}
public int getsum()
{
return sum;
}
} import java.util.Random; public class Fenshu {
private int fz,fm;//用户输入分子、分母
private int fz0,fm0;//已约分正确分子、分母
private int fz1=1,fm1=1;//未约分正确分子、分母
private int jlfz,jlfm;//操作数
private int temp,ys;//操作数
private char ch;
private char fh[]={'+','-','*','/'};
Fenshu(){}
public String suanshi(int a,int b,int c,int d,int z){
if(a>b)//确保分母大于分子
{
temp=b;
b=a;
a=temp;
}
if(c>d)//确保分母大于分子
{
temp=d;
d=c;
c=temp;
}
// z=new Random().nextInt(cc*2-1);
return a+"/"+b+" "+fh[z]+" "+c+"/"+d; }
public String answer(int a,int b,int c,int d,int z){
int shu []=new int [4];
shu[0]=a;
shu[1]=b;
shu[2]=c;
shu[3]=d;
switch(z)
{
case 0:
fz1=shu[0]*shu[3]+shu[1]*shu[2];
fm1=shu[1]*shu[3];
break;
case 1:
fz1=shu[0]*shu[3]-shu[1]*shu[2];
fm1=shu[1]*shu[3];
break;
case 2:
fz1=shu[0]*shu[2];
fm1=shu[1]*shu[3];
break;
case 3:
fz1=shu[0]*shu[3];
fm1=shu[1]*shu[2];
break;
default:
break;
}
jlfz=fz1;//约分
jlfm=fm1;
while(fm1!=0)
{
ys=fz1%fm1;
fz1=fm1;
fm1=ys;
}
fz0=jlfz/fz1;
fm0=jlfm/fz1;
if(fm0<0)
{
fz0=fz0*-1;
fm0=fm0*-1;
}
return fz0+"/"+fm0;
} }

开发环境:Eclipse

做的是3.4.6.8,/*8没成功*/

结对同伴的学号:201306114327  姓名:林海信    博客地址:http://www.cnblogs.com/linhaixin/ 

这个结对编程过程中,我和同伴轮流编程,轮流检测,轮流查阅资料。

总结:本次编程预想时间1天,实际时间3天外加熬夜修改BUFF。在次过程中,体会到结对子的乐趣与作用,还可以从中相互学习。不过,这还是一个需要磨合的时间,否则会什么都做不成。我觉得,结对子学习非常的有效。

结对子作业 四则运算 V2.0的更多相关文章

  1. 20175226 2018-2019-2《java程序设计》结对编程-四则运算(第一周-阶段总结)

    结对编程-四则运算(第一周-阶段总结) 需求分析 实现一个四则运算程序,要求: 自动随机生成小学四则运算题目(加,减,乘,除) 支持整数.真分数且支持多项式 能够利用栈的思想,将中缀转换为后缀表达式 ...

  2. 20175305张天钰Java结对编程四则运算(二)

    Java结对编程四则运算(二) 一.题目描述及要求 Git提交粒度不要太粗,建议一个文件/一个类/一个函数/一个功能/一个bug修复都进行提交,不能一天提交一次,更不能一周一次,参考Commit Me ...

  3. 20175305张天钰Java结对编程四则运算

    Java结对编程四则运算 一.题目描述:如何对表达式进行求值运算呢 1.中缀表达式与后缀表达式(娄老师讲解) 中缀表达式就是运算符号在运算数中间的表达式,比如1+2,顾名思义,后缀表达式就是运算符在运 ...

  4. 结对编程--四则运算(Java)萧英杰 夏浚杰

    结对编程--四则运算(Java)萧英杰 夏浚杰 Github项目地址 功能要求 题目:实现一个自动生成小学四则运算题目的命令行程序 使用 -n 参数控制生成题目的个数(实现) 使用 -r 参数控制题目 ...

  5. 结对编程--四则运算(Java)梅进鹏 欧思良

    结对编程--四则运算(Java)梅进鹏 欧思良 Github项目地址:https://github.com/MeiJinpen/Arithmetic 功能要求 题目:实现一个自动生成小学四则运算题目的 ...

  6. 作业2-MathExam V2.0

    MathExam V2.0 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 20 50 • ...

  7. Core 第三组 结对作业——四则运算 Part1. Core代码编写

    结对作业——四则运算 Part1. Core代码编写 PB15061303 刘梓轩PB16061489 艾寅中 GITHUB 地址 戳这里 目录 (因为内容较多,分为了三个部分,但作业系统中只能提交一 ...

  8. 王译潇20162314 实验报告三plus结对编程四则运算第一阶段

    北京电子科技学院BESTI实验报告 课程:程序设计与数据结构 班级: 1623 姓名: 王译潇 学号:20162314 指导教师:娄佳鹏老师.王志强老师 实验日期:2017年5月12号 实验密级: 非 ...

  9. Java结对编程四则运算一周小结

    Java结对编程四则运算一周小结 需求分析 对于四则运算来说最主要的就是要计算出产生的式子(字符串的形式). 设计思路 总体可将这个项目分解为几个部分:产生式子,计算式子,判断对错并记录: 具体的思路 ...

随机推荐

  1. Hive tuning tips

    1. limit Hive has a configuration property to enable sampling of source data for use with LIMIT: hiv ...

  2. 动手学习TCP:数据传输

    前面的文章介绍了TCP状态变迁,以及TCP状态变迁图中的一些特殊状态. 本文主要看看TCP数据传输过程中需要了解的一些重要点: MSS(Maximum Segment Size) Seq号和Ack号的 ...

  3. 【问题&解决】解决创建Android模拟器时提示"No system images installed for this target"的问题

    在创建Android模拟器时间发现提示“No system images installed for this target”问题,无法创建模拟器,如下图: 解决:经上网查证,发现原因在于CPU/AB ...

  4. tarjan算法+缩点:求强连通分量 POJ 2186

    强连通分量:1309. [HAOI2006]受欢迎的牛 ★★   输入文件:cow.in   输出文件:cow.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] 每一头牛 ...

  5. hihocoder 1388 &&2016 ACM/ICPC Asia Regional Beijing Online Periodic Signal

    #1388 : Periodic Signal 时间限制:5000ms 单点时限:5000ms 内存限制:256MB 描述 Profess X is an expert in signal proce ...

  6. 【转载】eclipse插件安装

    原文:http://blog.csdn.net/dylan619/article/details/46839941 原来的eclipse3.7安装了太多插件后,m2e怎么也安装不成功,因此今天重新下载 ...

  7. 利用appscan进行自动化定期安全测试

    Appscan的强大众所周知,如果可以自动执行定期安全测试,岂不是美事一件? 事实上,appscan提供了计划扫描的选项,配合windows的计划任务,可以按需设定. 1.打开appscan中的“工具 ...

  8. js中的return,return true,return false小结

    return  函数执行到这句时会终结,并返回调用函数,而且把表达式的值作为函数的结果返回 return false 可以防止默认的事件行为.例如,默认情况下点击一个<a>元素,页面会跳转 ...

  9. 了解了这些才能开始发挥jQuery的威力(转)

    链接:http://www.cnblogs.com/dolphinX/archive/2013/10/08/3347677.html 由于当前jQuery如此的如雷贯耳,相信不用介绍什么是jQuery ...

  10. android实现点击背景图片不同区域实现不同事件

    有时候我们拿到一张背景图片,客户要求点击图片的不同区域去跳转或者实现不同的操作事件.我们首先要确认图片的点击区域,往往我们会在布局文件那里下手,但是这样不好做适配,所以我实现了以下方法,基本功能可以实 ...