四则运算出题(界面版)



 

设计思想:



实现代码:



 

//jiangzhongxi 2015/3/19



 

package count;



 

 



import java.awt.BorderLayout;



 

import java.awt.Color;



 

import java.awt.Container;



 

import java.awt.Graphics;



 

import java.awt.Graphics2D;



 

import java.awt.Image;



 

import java.awt.Toolkit;



 

import java.awt.event.ActionEvent;



 

import java.awt.event.ActionListener;



 

import java.util.Random;



 

import java.util.Vector;



 

 



 

import javax.swing.JButton;



 

import javax.swing.JCheckBox;



 

import javax.swing.JComboBox;



 

import javax.swing.JFrame;



 

import javax.swing.JLabel;



 

import javax.swing.JPanel;



 

import javax.swing.JTextArea;



 

import javax.swing.JTextField;



 

 



 

public class Count extends JFrame
implements ActionListener{



 

 



 

         JPanel
pa;



 

        



 

   
JLabel la;//
出题标签



 

    JTextArea
tf;//
文本区



 

   



 

   
JLabel la1;//
范围标签



 

   
JLabel la2;//
范围标签



 

   
JTextField f1;//
最大值



 

   
JTextField f2;//
最小值



 

   
JButton bu;



 

   
//
选择运算符加减乘除



 

   
JLabel l0;



 

   
JLabel l1;



 

   
JLabel l2;



 

   
JLabel l3;



 

   
JLabel l4;



 

   
JCheckBox cb1;



 

   
JCheckBox cb2;



 

   
JCheckBox cb3;



 

   
JCheckBox cb4;



 

   
Boolean flag1;



 

   
Boolean flag2;



 

   
Boolean flag3;



 

   
Boolean flag4;



 

 



 

   
int a,max;



 

   
int b,min;



 

   



 

   
String str=" ";



 

   



 

   
JLabel la3;//
题目数量



 

   
String[]
s={"0","10","20","30","40","50","60"};



 

   



 

   
JLabel l5;//
打印方式



 

   
JComboBox  co5;



 

   
JComboBox co;//
保证行列的整齐



 

   
String[]
si={"","1","2","3","4","5"};



 

         public
Count() {



 

                   //
TODO Auto-generated constructor stub



 

                   this.setSize(1200,
700);



 

                   this.setLocation(80,
0);



 

                   this.setLayout(null);



 

                   Container
cn=this.getContentPane();



 

                   pa=new
JPanel()



 

                   {



 

                             public void paint(Graphics g)



 

                             {              



 

                  Graphics2D g2 = (Graphics2D)
g;  



 

                  Image img =
Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("1.JPEG"));    



 

                  g2.drawImage(img, 0, 0,
this);         



 

              }



 

                   };



 

             cn.add(pa, BorderLayout.CENTER);                 



 

                   la=new
JLabel("
四则运算");



 

                   la.setFont(new
java.awt.Font("Dialog",1,20));



 

                   la.setLocation(600,
40);



 

                   la.setSize(100,
40);



 

                   this.add(la);



 

                  



 

                   bu=new
JButton("
开始出题");



 

                   bu.addActionListener(this);



 

                   bu.setSize(100,
20);



 

                   bu.setLocation(40,
340);



 

                   this.add(bu);



 

                  



 

                  



 

                   tf=new
JTextArea();



 

                   tf.setLocation(40,380);



 

                   tf.setSize(400,
200);



 

                   this.add(tf);



 

                   //添加取值范围



 

                   la1=new
JLabel("
取值范围");



 

                   la1.setSize(100,
20);



 

                   la1.setLocation(40,
200);



 

                   this.add(la1);



 

                  



 

                   f1=new
JTextField();



 

                   f1.setSize(40,
20);



 

                   f1.setLocation(40,
230);



 

                   this.add(f1);



 

                  



 

                   la1=new
JLabel("
");



 

                   la1.setSize(20,
20);



 

                   la1.setLocation(80,
230);



 

                   this.add(la1);



 

                  



 

                   f2=new
JTextField();



 

                   f2.setSize(40,
20);



 

                   f2.setLocation(100,
230);



 

                   this.add(f2);



 

                   //打印数量



 

                   la3=new
JLabel("
打印数量");



 

                   la3.setSize(80,
20);



 

                   la3.setLocation(40,
150);



 

                   this.add(la3);



 

                   //选择数量的下拉列表



 

             co=new JComboBox(s);



 

             co.setSize(40, 20);



 

             co.setLocation(110,150);



 

             this.add(co);



 

             //添加加减乘除选择复选框



 

             l0=new JLabel("请选择运算符:");



 

             l0.setSize(120, 20);



 

             l0.setLocation(40, 270);



 

             this.add(l0);



 

             l1=new JLabel("");



 

             l1.setSize(40, 20);



 

             l1.setLocation(90, 300);



 

             cb1=new JCheckBox();



 

             cb1.setSize(20, 20);



 

             cb1.setLocation(105, 300);



 

             this.add(cb1);



 

             this.add(l1);



 

             flag1=cb1.isSelected();



 

            



 

             l2=new JLabel("");



 

             l2.setSize(40, 20);



 

             l2.setLocation(140, 300);



 

             cb2=new JCheckBox();



 

             cb2.setSize(20, 20);



 

             cb2.setLocation(160, 300);



 

             this.add(cb2);



 

             this.add(l2);



 

             flag2=cb2.isSelected();



 

            



 

             l3=new JLabel("");



 

             l3.setSize(40, 20);



 

             l3.setLocation(205, 300);



 

             cb3=new JCheckBox();



 

             cb3.setSize(40, 20);



 

             cb3.setLocation(230, 300);



 

             this.add(cb3);



 

             this.add(l3);



 

             cb3.isSelected();



 

             flag3=cb3.isSelected();



 

            



 

             l4=new JLabel("");



 

             l4.setSize(20, 20);



 

             l4.setLocation(275, 300);



 

             cb4=new JCheckBox();



 

             cb4.setSize(40, 20);



 

             cb4.setLocation(300, 300);



 

             this.add(cb4);



 

             this.add(l4);



 

             flag4=cb4.isSelected();



 

            



 

             l5=new JLabel("打印方式:每行数目");



 

             l5.setSize(200, 20);



 

             l5.setLocation(40, 100);



 

             this.add(l5);



 

             co5=new JComboBox(si);



 

             co5.setSize(60, 20);



 

             co5.setLocation(160, 100);



 

             this.add(co5);



 

         }



 

 



 

         public
static void main(String[] args) {



 

                   //
TODO Auto-generated method stub



 

 



 

                   Count
c=new Count();



 

                   c.setVisible(true);//加入主窗体



 

                  



 

                  



 

         }



 

 



 

         @Override



 

         public
void actionPerformed(ActionEvent e) {



 

                   //
TODO Auto-generated method stub



 

                   String
g;



 

                   g=(String)
co.getSelectedItem();



 

                   int
n=Integer.parseInt(g);//
获取下拉列表的数值



 

                  



 

                   String
co;



 

                   co=(String)co5.getSelectedItem();



 

                   int
w=Integer.parseInt(co);



 

        



 

                   System.out.println(w);



 

             int[] result = new int[100]; //限定不重复



 

             int[] result2 = new int[100]; //限定不重复



 

             for(int k=0;k<100;k++)



 

                   {



 

                            result[k]=-1;



 

                   }                



 

                   if(e.getSource()==bu)



 

                  {



 

                             flag4=cb4.isSelected();



 

                             flag3=cb3.isSelected();



 

                             flag2=cb2.isSelected();



 

                             flag1=cb1.isSelected();



 

                       String        mi=f1.getText();



 

                            min=Integer.parseInt(mi);//获取最小值



 

                  



 

                      String ma=f2.getText();



 

                            max=Integer.parseInt(ma);//获取最大值



 

                            for(int
m=1;m<=n;m++)



 

                            {



 

                                     int
flag=1;



 

                                     a
= (int)( Math.random() * (max-min))+min; //
max min 范围内的整数



 

                                     String
stra;



 

                                     stra=String.valueOf(a);//将整数转化为字符串



 

                                     result[m]=a;//a依次的数值存入整数数组



 

                                    



 

                                     b
= (int) (Math.random() * (max-min))+min; //
max min 范围内的整数



 

                                     String
strb;



 

                                     strb=String.valueOf(b);



 

                                     result2[m]=b;



 

                                     //保证第一次比较时aresult0】不重复



 

                                    



 

                                     for(int
k=0;k<m;k++)



 

                                     {



 

                                               if(a==result[k]&&b==result[k])



 

                                               {



 

                                                        flag=0;



 

                                                        n=n+1;



 

                                               }



 

                                               break;



 

                                     }



 

                                     if(flag==1)



 

                                     {



 

                                    



 

                                               if(flag1==true&&flag2==true&&flag3==true&&flag4==true)



 

                                               {



 

                                                        if(a<(min+max)/4)



 

                                                        {



 

                                                                 str=str+stra+"+"+strb+"=  ";



 

                                                        }



 

                                                        else
if(a>=(min+max)/4&&a<(max+min)/2)



 

                                                        {



 

                                                                 str=str+stra+"-"+strb+"=  ";



 

                                                        }



 

                                                        else
if(a>=(max+min)/2&&a<3*(min+max)/4)



 

                                                        {



 

                                                                 str=str+stra+"*"+strb+"=  ";



 

                                                        }



 

                                                        else



 

                                                        {



 

                                                                 str=str+stra+"/"+strb+"=  ";



 

                                                        }



 

                                                        if(m%w==0)



 

                                                        {



 

                                                                 str=str+" ";



 

                                                        }



 

                                               }



 

                                               else



 

                                               {



 

                                                        if(flag1==true&&flag2==true)



 

                                                        {



 

                                                                 if(a<(max+min)/2)



 

                                                                 {



 

                                                                           str=str+stra+"+"+strb+"=  ";



 

                                                                 }



 

                                    



 

                                                                 else



 

                                                                 {



 

                                                                           str=str+stra+"-"+strb+"=  ";



 

                                                                 }



 

                                                                 if(m%w==0)



 

                                                                 {



 

                                                                           str=str+" ";



 

                                                                 }



 

                                                        }



 

                                                        else



 

                                                        {



 

                                                                  if(flag1==true&&flag3==true)



 

                                                                           {



 

                                                                                    if(a<(max+min)/2)



 

                                                                                    {



 

                                                                                             str=str+stra+"+"+strb+"=  ";



 

                                                                                    }



 

                                                       



 

                                                                                    else



 

                                                                                    {



 

                                                                                             str=str+stra+"*"+strb+"=  ";



 

                                                                                    }



 

                                                                                    if(m%w==0)



 

                                                                                    {



 

                                                                                             str=str+" ";



 

                                                                                    }



 

                                                                           }



 

                                                                  else



 

                                                                  {



 

                                                                            if(flag1==true&&flag4==true)



 

                                                                                    {



 

                                                                                             if(a<(max+min)/2)



 

                                                                                             {



 

                                                                                                       str=str+stra+"+"+strb+"=  ";



 

                                                                                             }



 

                                                                



 

                                                                                             else



 

                                                                                             {



 

                                                                                                       str=str+stra+"/"+strb+"=  ";



 

                                                                                             }



 

                                                                                             if(m%w==0)



 

                                                                                             {



 

                                                                                                       str=str+" ";



 

                                                                                             }



 

                                                                                    }



 

                                                                            else



 

                                                                            {



 

                                                                                     if(flag2==true&&flag3==true)



 

                                                                                             {



 

                                                                                                       if(a<(max+min)/2)



 

                                                                                                       {



 

                                                                                                                str=str+stra+"-"+strb+"=  ";



 

                                                                                                       }



 

                                                                          



 

                                                                                                       else



 

                                                                                                       {



 

                                                                                                                str=str+stra+"*"+strb+"=  ";



 

                                                                                                       }



 

                                                                                                       if(m%w==0)



 

                                                                                                       {



 

                                                                                                                str=str+" ";



 

                                                                                                       }



 

                                                                                             }



 

                                                                                     else



 

                                                                                     {



 

                                                                                              if(flag2==true&&flag4==true)



 

                                                                                                       {



 

                                                                                                                if(a<(max+min)/2)



 

                                                                                                                {



 

                                                                                                                         str=str+stra+"-"+strb+"=  ";



 

                                                                                                                }



 

                                                                                   



 

                                                                                                                else



 

                                                                                                                {



 

                                                                                                                         str=str+stra+"/"+strb+"=  ";



 

                                                                                                                }



 

                                                                                                                if(m%w==0)



 

                                                                                                                {



 

                                                                                                                         str=str+" ";



 

                                                                                                                }



 

                                                                                                       }



 

                                                                                              else



 

                                                                                              {



 

                                                                                                        if(flag3==true&&flag4==true)



 

                                                                                                                {



 

                                                                                                                         if(a<(max+min)/2)



 

                                                                                                                         {



 

                                                                                                                                   str=str+stra+"*"+strb+"=  ";



 

                                                                                                                          }



 

                                                                                            



 

                                                                                                                         else



 

                                                                                                                         {



 

                                                                                                                                   str=str+stra+"/"+strb+"=  ";



 

                                                                                                                         }



 

                                                                                                                         if(m%w==0)



 

                                                                                                                         {



 

                                                                                                                                   str=str+" ";



 

                                                                                                                         }



 

                                                                                                                }



 

                                                                                                                else



 

                                                                                                                {



 

                                                                                                                         if(flag1==true)



 

                                                                                                                         {



 

                                                                                                                                   str=str+stra+"+"+strb+"=  ";



 

                                                                                                                                   if(m%w==0)



 

                                                                                                                                   {



 

                                                                                                                                            str=str+" ";



 

                                                                                                                                   }



 

                                                                                                                         }



 

                                                                                                                         else
if(flag2==true)



 

                                                                                                                         {



 

                                                                                                                                   str=str+stra+"-"+strb+"=  ";



 

                                                                                                                                   if(m%w==0)



 

                                                                                                                                   {



 

                                                                                                                                            str=str+" ";



 

                                                                                                                                   }



 

                                                                                                                         }



 

                                                                                                                         else
if(flag3==true)



 

                                                                                                                         {



 

                                                                                                                                   str=str+stra+"*"+strb+"=  ";



 

                                                                                                                                   if(m%w==0)



 

                                                                                                                                   {



 

                                                                                                                                            str=str+" ";



 

                                                                                                                                   }



 

                                                                                                                         }



 

                                                                                                                         else



 

                                                                                                                         {



 

                                                                                                                                   str=str+stra+"/"+strb+"=  ";



 

                                                                                                                                   if(m%w==0)



 

                                                                                                                                   {



 

                                                                                                                                            str=str+" ";



 

                                                                                                                                   }



 

                                                                                                                         }



 

                                                                                                                }



 

                                                                                              }



 

                                                                                                      



 

                                                                                     }



 

                                                                                              



 

                                                                            }



 

                                                                  }



 

                                                                             



 

                                                                   



 

                                                        }



 

                                                       



 

                                               }



 

                                       



 

                                               tf.setText(str);



 

                                     }



 

                           



 

                            }



 

                   }



 

         }



 

}



 

        



心得总结:

首先是设计思想带来的问题,大一编程以来几乎很少有文字性的编程思想,写在纸上记录下来,进行比对那么问题来了原本的设计和实际的编程差别很大,首先反思设计思想思考的不全面,或者说用心不够,因为几乎不能够把所有的问题都能提前想到,就是功能也可能在实现的过程中添加一些或者有些由于时间问题只能放弃,接下来说说人月问题,我的感受是总是觉得程序可以在完美比如我还想在程序中加入符合主题的背景和其他一些把界面美化,如果说编程开始的晚我觉得再早的时间也不够你用的,我们永远不能到达最美最精致只能是更好,这就是《梦断代码》里所谓的软件时间啊,多读书多读书。

时间记录日志

学生:

姜中希

 

日期:

3/19/2015

 

教师:

王建民

 

课程:

PSP

 

 

 

 

 

 

 

日期

开始时间

结束时间

净时

活动

备注

318

1230

1800

100分钟

设计思想

 

318

1900

1030

20分钟

编写程序

 

319

558

740

90分钟

编写程序

 

318

1600

1714

30分钟

完善程序记录日志

 

 

 



 

 



 

原文地址:https://www.cnblogs.com/xizhenghe/p/4351154.html