package size;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem; import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import javax.swing.JTextField;
import javax.swing.JTextArea; import java.awt.Color;
import java.util.*;
import java.util.regex.*;
import java.lang.*;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.*; public class vvvv extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
int x;//题目个数
int y=0;
int n;
int i=1;
char[] op = { '+', '-', '*', '/' };
int[] nov = new int[4];
int zf;//控制正负
int zz;//题型控制
String str = new String();
String str1 = new String();
int[] num1 = new int[5];
String s[] = new String[5];
int num2=0;
int[] anser=new int[5];//用户的答案
int[] trueanser=new int[5];//正确答案
File file;
int a = 0;
int b = 0;
// int c = 0;
public JFrame vvvv;
JTextArea ck;
private JTextField xmt;
private JButton yes;
private JButton no;
private JButton start;
private JButton huan;
private JPanel panel;
private JScrollPane scrollPane; /**
* Launch the application.
*/
public static void main(String[] args)// 主方法
{
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
vvvv window = new vvvv();
window.vvvv.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} /**
* Create the application.
*/
public vvvv() {
initialize();
} /**
* Initialize the contents of the frame.
*/
private void initialize() {
vvvv = new JFrame();
vvvv.getContentPane().setEnabled(false);
vvvv.getContentPane().setBackground(Color.GRAY);
vvvv.setTitle("\u56DB\u5219\u8FD0\u7B97");
vvvv.setBounds(100, 100, 494, 270);
vvvv.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
vvvv.setResizable(false); vvvv.getContentPane()
.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); panel = new JPanel();
vvvv.getContentPane().add(panel); ck = new JTextArea(10, 40);
// panel.add(ck);
// ck.setEditable(false); scrollPane = new JScrollPane(ck);
panel.add(scrollPane); xmt = new JTextField();
vvvv.getContentPane().add(xmt);
xmt.addActionListener(this);
xmt.setColumns(10); yes = new JButton("\u786E\u8BA4");
vvvv.getContentPane().add(yes);
yes.addActionListener(this); no = new JButton("\u6E05\u7A7A");
no.addActionListener(this);
vvvv.getContentPane().add(no); huan = new JButton("\u6362\u80A4");
huan.addActionListener(this);
vvvv.getContentPane().add(huan); start = new JButton("开始");
start.addActionListener(this);
vvvv.getContentPane().add(start);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == yes)
{
if(b==1)
{
if(xmt.getText().length()!=0)
try
{
x=Integer.parseInt(xmt.getText());
b++;
}
catch(NumberFormatException x)
{
ck.setText("输入有误!");
}
else ck.setText("输入有误!");
}
if(b==2)
{
if(n!=0)anser[i-2]=Integer.parseInt(xmt.getText());
str1="第"+i+"条题目为:";
n=(int)(Math.random() * 4 + 2);//随机出运算符的数量
zz=(int)(Math.random()*2);
for(int j=0;j<n;j++)
{
//zf=(int)(Math.random()*2);
//if(zf==0)//负
// num1[j]=-(int)(Math.random()*100);//产生随机数
//else //正
num1[j]=(int)(Math.random()*100);
if(zz==1)num1[j]=(int)(Math.random()*10+1);
}
for(int k=0;k<n-1;k++)
{
nov[k]=(int)(Math.random()*4);
if(nov[k]==3&&num1[k+1]==0)
{
do
{
num1[k+1]=(int)(Math.random()*100);
}while(num1[k+1]==0);
}
}
str="";
if(zz==0)
{
for(int j=0;j<n;j++)
{
//if(num1[j]<0)str=str+"("+String.valueOf(num1[j])+")";
str=str+String.valueOf(num1[j]);
if(j==n-1)
{
//try
//{
//int ii=0;
trueanser[i-1]=opt(str);
//}
/*catch (Exception e1)
{
System.out.println(e1);
//e1.printStackTrace();
}*/
str=str+"=";
//str=str+String.valueOf(trueanser[i-1]);
ck.setText(str1+str);
break;
}
str=str+op[nov[j]];
}
}
if(zz==1)
{
trueanser[i-1]=1;
str=String.valueOf(num1[0])+"!=";
for(int j=1;j<=num1[0];j++)
trueanser[i-1]=trueanser[i-1]*j;
//str=str+String.valueOf(trueanser[i-1]);
ck.setText(str1+str);
}
if(i==x+1)
{
b=3;
anser[i-2]=Integer.parseInt(xmt.getText());
}
else i++;
}
if(b==3)
{
y=0;
for(int j=0;j<x;j++)
{
if(anser[j]==(int)trueanser[j])y++;
}
ck.setText("答题完成!答对"+y+"道!");
b=0;
}
}
if (e.getSource() == no)
{
xmt.setText(null);
}
if (e.getSource() == huan)
{
if (a == 0) {
vvvv.getContentPane().setBackground(Color.blue);
a++;
}
else if (a == 1) {
vvvv.getContentPane().setBackground(Color.yellow);
a++;
}
else if (a == 2) {
vvvv.getContentPane().setBackground(Color.gray);
a = 0;
}
}
if (e.getSource() == start)
{
ck.setText("欢迎使用四则运算练习系统\n请输入题目的数量(1-5)");
n=0;
i=1;
b=1;
}
}
public int opt(String str){ String[] operater =new String[20];
String[] number = new String[20];
Stack countStack1 = new Stack();
Stack countStack2 = new Stack();
int result =0;
number = str.split("\\/|\\*|\\+|\\-");
operater= str.split("\\d+");
for(int i = 0; i<number.length;i++)
{
countStack1.push(number[i]);
if(i!=number.length-1)
{
countStack1.push(operater[i+1]);
}
}
while(!countStack1.isEmpty())
countStack2.push(countStack1.pop());
String op;
while(!countStack2.isEmpty())
{
result=0;
op = countStack2.pop().toString();
if(op.equals("*"))
{
result=Integer.parseInt(countStack1.pop().toString())*Integer.parseInt(countStack2.pop().toString());
countStack1.push(result);
continue;
}
if(op.equals("/"))
{
result=Integer.parseInt(countStack1.pop().toString())/Integer.parseInt(countStack2.pop().toString());
countStack1.push(result);
continue;
}
countStack1.push(op);
}
while(!countStack1.isEmpty())
countStack2.push(countStack1.pop());
while(!countStack2.isEmpty())
{
result=0;
op = countStack2.pop().toString();
if(op.equals("+"))
{
result=Integer.parseInt(countStack1.pop().toString())+Integer.parseInt(countStack2.pop().toString());
countStack1.push(result);
continue;
}
if(op.equals("-"))
{
result=Integer.parseInt(countStack1.pop().toString())-Integer.parseInt(countStack2.pop().toString());
countStack1.push(result);
continue;
}
countStack1.push(op);
}
return result;
}
/*public static int opt(int[] num1,int[] nov,int n,int i)
{
if(i>=n)return num1[i];
int sum=0;
if(nov[0]==0 && i<n)
{
sum=num1[i]+opt(num1,nov,n,i+1);
}
if(nov[0]==1 && i<n)
{
sum=num1[i]-opt(num1,nov,n,i+1);
}
if(nov[0]==2 && i<n)
{
sum=num1[i]*opt(num1,nov,n,i+1);
}
if(nov[0]==3 && i<n)
{
sum=num1[i]/opt(num1,nov,n,i+1);
}
return sum;
}*/
}

相比之前的未完成版,这个去掉一些功能简化一下先做一个初版放上来了.

已完成的扩展方向:

A.换肤

B.user选择题目数量

C.阶乘

任务分配:

我负责的是出题以及计算两个部分,界面换肤以及其他功能是同伴莫俊宇负责的,最后两个人一起进行整合以及调试

感想:

  结队作业比起以往我一个人干要效率不少,这样我可以把我不擅长的部分交给队友,两个人各施其职,效率非常高,而且也能互相帮忙解决问题,程序的容错也比以往要好,两个人结队的时候注重的是交流,这样才能融合两个人不同的编码风格,让程序的质量进一步提升

  这一次结队让我受益良多,也让我认识到编程队的重要性,期待与伙伴的下一次合作

开发环境:Eclipse

结对伙伴:201306114408 林达 (http://www.cnblogs.com/SiPine/)

201306114405 莫俊余 (http://www.cnblogs.com/mjysok/)

PS:接下来完善更多扩展功能后会继续上传新的版本~

实验二 四则运算 完成版 ver.1的更多相关文章

  1. 四则运算安卓版ver.mk3

    在原有的基础上做了些许改动以及添加了一点小功能,以下是代码: package com.example.add; import java.io.File; import com.example.add. ...

  2. 四则运算安卓版ver.mk2

    做了一点微小的变动....非常微小...不过美观点了就是...那就是----加背景! 变更后的部分代码: <LinearLayout xmlns:android="http://sch ...

  3. 20145213《Java程序设计》实验二Java面向对象程序设计实验报告

    20145213<Java程序设计>实验二Java面向对象程序设计实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装,继承,多态 初步掌握UML建模 熟悉S.O. ...

  4. 20145225唐振远 实验二 "Java面向对象程序设计"

    20145225<Java程序设计> 实验二 Java面向对象程序设计 实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S ...

  5. 四则运算GUI版

    小学四则运算界面版 李永豪 201421123117 郑靖涛 201421123114 coding 地址:https://git.coding.net/ras/work2.git 一.题目描述 我们 ...

  6. 2018-2019-2 实验二 Java面向对象程序设计

    实验内容 1.初步掌握单元测试和TDD 2.理解并掌握面向对象三要素:封装.继承.多态 3.初步掌握UML建模 4.熟悉S.O.L.I.D原则 5.了解设计模式 实验要求 1.没有Linux基础的同学 ...

  7. 2018-2019-2 20175234 实验二《Java面向对象程序设计》实验报告

    目录 实验内容 实验要求 实验步骤 实验收获 参考资料 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 解设计模式 实验 ...

  8. 2016-2017-2 20155324实验二《Java面向对象程序设计》实验报告

    2016-2017-2 20155324实验二<Java面向对象程序设计>实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉 ...

  9. # 20155219实验二 Java面向对象程序设计

    20155219实验二 Java面向对象程序设计 一.实验内容 1.初步掌握单元测试和TDD 2.理解并掌握面向对象三要素:封装.继承.多态 3.初步掌握UML建模 4.熟悉S.O.L.I.D原则 5 ...

随机推荐

  1. Linux中定时删除超过指定大小的文件夹

    背景: 开发环境总是动不动就没有空间了, 大部分都是debug日志.所以有必要在日志很疯狂的时候,删除不必要的日志. 思路:一. 书写删除日志文件脚本: 定时任务执行.  但是有时候的日志是需要保存用 ...

  2. 使用CURL模拟表单上传文件

    //以下代码适合PHP7.x PHP5.6$file = new CURLFile('./127.zip','application/octet-stream');$file->setMimeT ...

  3. SparkSQL执行时参数优化

    近期接手了不少大数据表任务调度补数据的工作,补数时发现资源消耗异常的大且运行速度却不怎么给力. 发现根本原因在于sparkSQL配置有诸多问题,解决后总结出来就当抛砖引玉了. 具体现象 内存CPU比例 ...

  4. python抠图与pip install PIL报错

    窗口命令pip install PIL(python3.6+selenium——2.53.1+pycharm) from PIL import Image from selenium import w ...

  5. My97DatePicker:开始时间和结束时间的最大间隔为1个月30天,并且不大于当前时间(3种方法)

    问题的背景 在之前做Web项目的时候,开始时间和结束时间,只有2个要求: 1.开始时间必须小于等于结束时间,不能超过当前时间. 2.结束时间必须大于等于开始时间,不能超过当前时间. 由于开始时间不大于 ...

  6. 3、计数排序,电影top100

    1.计数排序 # -*- coding: utf-8 -*- # @Time : 2018/07/31 0031 11:32 # @Author : Venicid def count_sort(li ...

  7. Python day1 ---python基础1.1

    1.模块初识2..pyc是个什么鬼?3.数据类型初识 4.数据运算5.入门知识拾遗 1.模块初识 sys模块 import sys print(sys.path) #打印环境变量 'D:\\Pycha ...

  8. springboot之websocket,STOMP协议

    一.WebSocket 是 HTML5 开始提供的一种在单个 TCP 连接上进行全双工通讯的协议. WebSocket 使得客户端和服务器之间的数据交换变得更加简单,允许服务端主动向客户端推送数据.在 ...

  9. [BZOJ1974][SDOI2010]代码拍卖会[插板法]

    题意 询问有多少个数位为 \(n\) 的形如 \(11223333444589\) 的数位值不下降的数字在\(\mod p\) 的意义下同余 \(0\). $n\leq 10^{18} ,p\leq ...

  10. python爬虫之数据的三种解析方式

    一.正则解析 单字符: . : 除换行以外所有字符 [] :[aoe] [a-w] 匹配集合中任意一个字符 \d :数字 [0-9] \D : 非数字 \w :数字.字母.下划线.中文 \W : 非\ ...