软件工程个人作业(1)

package zuoye;

import java.awt.Container;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.Random;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;


import javax.swing.JOptionPane;

import javax.swing.JTextField;

import javax.swing.WindowConstants;

public class m extends JFrame

{
public m()
{
setTitle("四则运算");
setLayout(null);
setBounds(0,20,800,650);
Container c=getContentPane();

setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

int a[]=new int[30];
int b[]=new int[30];
int d[]=new int[30];
int e[]=new int[30];
String a1[]=new String[30];
String b1[]=new String[30];
String d1[]=new String[30];
JLabel j1[]=new JLabel[30];
JLabel j2[]=new JLabel[30];
JLabel j3[]=new JLabel[30];
JLabel j4[]=new JLabel[30];
JButton b2=new JButton("退出");
JButton b3=new JButton("提交");
b2.setBounds(100, 550, 100, 50);
c.add(b2);
JTextField j5[]=new JTextField[30];
Random r1[]=new Random[30];
Random r2[]=new Random[30];
Random r3[]=new Random[30];
int i,j=0,k=0,l;
for(i=0;i<30;i++)
{
j5[i]=new JTextField();
r1[i]=new Random();
r2[i]=new Random();
r3[i]=new Random();
j5[i]=new JTextField();
e[i]=r3[i].nextInt(4);
e[i]=e[i]+1;
if(e[i]==1)
{
a[i]=r1[i].nextInt(100);
b[i]=r2[i].nextInt(100);
d[i]=a[i]+b[i];
a1[i]=String.valueOf(a[i]);
b1[i]=String.valueOf(b[i]);
d1[i]=String.valueOf(d[i]);
j1[i]=new JLabel(a1[i]);
j2[i]=new JLabel("+");
j3[i]=new JLabel(b1[i]);
j4[i]=new JLabel("=");

}
if(e[i]==2)
{
a[i]=r1[i].nextInt(100);
b[i]=r2[i].nextInt(100);
d[i]=a[i]-b[i];
a1[i]=String.valueOf(a[i]);
b1[i]=String.valueOf(b[i]);
d1[i]=String.valueOf(d[i]);
j1[i]=new JLabel(a1[i]);
j2[i]=new JLabel("-");
j3[i]=new JLabel(b1[i]);
j4[i]=new JLabel("=");

}
if(e[i]==3)
{
a[i]=r1[i].nextInt(50);
b[i]=r2[i].nextInt(50);
d[i]=a[i]*b[i];
a1[i]=String.valueOf(a[i]);
b1[i]=String.valueOf(b[i]);
d1[i]=String.valueOf(d[i]);
j1[i]=new JLabel(a1[i]);
j2[i]=new JLabel("X");
j3[i]=new JLabel(b1[i]);
j4[i]=new JLabel("=");

}
if(e[i]==4)
{
d[i]=r1[i].nextInt(20);
b[i]=r2[i].nextInt(20);
a[i]=b[i]*d[i];
while(d[i]==0||b[i]==0)
{
r1[i]=new Random();
r2[i]=new Random();
d[i]=r1[i].nextInt(20);
b[i]=r2[i].nextInt(20);
a[i]=b[i]*d[i];

}

a1[i]=String.valueOf(a[i]);
b1[i]=String.valueOf(b[i]);
d1[i]=String.valueOf(d[i]);
j1[i]=new JLabel(a1[i]);
j2[i]=new JLabel("/");
j3[i]=new JLabel(b1[i]);
j4[i]=new JLabel("=");


}
j1[i].setBounds(50+j*42, 25+(k/2)*32, 40, 30);
j++;
j2[i].setBounds(50+j*42, 25+(k/2)*32, 40, 30);
j++;
j3[i].setBounds(50+j*42, 25+(k/2)*32, 40, 30);
j++;
j4[i].setBounds(50+j*42, 25+(k/2)*32, 40, 30);
j++;
j5[i].setBounds(50+j*42, 25+(k/2)*32, 40, 30);
j++;
j++;
j++;
j++;
k++;
if(k!=0&&k%2==0)
{
j=0;
}
c.add(j1[i]);
c.add(j2[i]);
c.add(j3[i]);
c.add(j4[i]);
c.add(j5[i]);
}

b2.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e)

{
            dispose();
}

});
setVisible(true);
}

public static void main(String[] args) {

// TODO Auto-generated method stub new m(); }

}

 

 

编程思想:

产生60个随机数随机组成30到四则运算题输出

截图:

 

posted @ 2016-05-25 21:20  dkjjjj  阅读(144)  评论(0编辑  收藏  举报