作业2结对子
1.摘要:
一、从第一次作业出发,将程序改装成一个单机带用户界面(不是控制台)的程序,这个程序最基本要达到:
1)生成题目,单个题目最多不能超过4个运算符,操作数小于100。
2)用户可以输入答案若用户输入答案正确,则提示正确;
3)若答案错误,则提示错误,并要提示正确答案是多少?
2.5个方向:
1)用户登入;
2)用户答题结束以后,程序可以显示用户答题所用的时间;
3)程序可以出单个整数阶乘的题目;
4)用户可以选择出题的个数(最多不能超过5个题目),答题结束可以显示用户答错的题目个数和答对的题目个数;
5)程序可以设置皮肤功能,可以改变界面的颜色即可;
3.结对同伴的学号姓名以及同伴的博客地址。
47黄杰:http://www.cnblogs.com/hj1994/
48练丽云:http://www.cnblogs.com/Lianliyun/
4,这个结对编程过程中,你做了什么,同伴做了什么?
我:界面,监听,显示用户答题所用的时间,设置皮肤功能,出单个整数阶乘的题目;
黄杰:用户登入,用户可以选择出题的个数(最多不能超过5个题目),答题结束可以显示用户答错的题目个数和答对的题目个数;
5总结这次结对编程的收获到和感悟。
结对子比较强调团队作用,和加强配合沟通的能力。除了要分工好,还要求把大家的代码整理到一个java文件上。通过这次结对子我明白的团队合作的强大性和艰巨性!
6.源代码:
import java.util.*;
import java.util.Random;
import java.math.*;
public class YunSuan {
Scanner in=new Scanner(System.in);
int a,b,c,d,e,f,i,h,j,p,q,m;
Long startTime = System.nanoTime();
Long endTime = System.nanoTime();
String mz[]=new String[100];
int daan[]=new int[10];
int shuzi[]=new int[10];
Random t=new Random();
long Totletime=(endTime-startTime);
YunSuan(int e,int h){
this.e=e;
this.h=h;
f=0;
}
public YunSuan() {
// TODO 自动生成的构造函数存根
}
public void MZ(String mz[],int m){
this.m=m;
this.mz[m]=mz[m];
}
public void TiMu(int h,int e)
{
for(int i=0;i<h;i++)
{
a=t.nextInt(100)+1;
b=t.nextInt(100)+1;
c=t.nextInt(100)+1;
d=t.nextInt(100)%4;
if(e==1)
{
if(d==1 ||d==0){
System.out.printf("\n"+"%d"+"+"+"%d"+"*"+"%d"+"=",a,b,c);
shuzi[i]=in.nextInt();
daan[i]=a+b*d;}
else if(d==2){
System.out.printf("\n"+"%d"+"+"+"%d"+"/"+"%d"+"=",a,b,c);
shuzi[i]=in.nextInt();
daan[i]=a-b*d;}
else if(d==3){
System.out.printf("\n"+"%d"+"-"+"%d"+"*"+"%d"+"=",a,b,c);
shuzi[i]=in.nextInt();
daan[i]=a+b/d;}
else if(d==4){
System.out.printf("\n"+"%d"+"-"+"%d"+""+"%d"+"=",a,b,c);
shuzi[i]=in.nextInt();
daan[i]=a-b/d;}
}
else if(e==2){
System.out.printf("\n"+"%d"+"!"+"=",a);
shuzi[i]=in.nextInt();
daan[0]=0;
daan[i]+=daan[i]*i;
}
else{
if(d==1||d==2){
System.out.printf("\n"+"%d"+"+"+"%d"+"=",a,b);
shuzi[i]=in.nextInt();
daan[i]=a+b;}
else{
System.out.printf("\n"+"%d"+"-"+"%d"+"=",a,b);
shuzi[i]=in.nextInt();
daan[i]=a-b;}
}
}
}
public void PanDuan()
{
for(int i=0;i<h;i++)
{
if(daan[i]==shuzi[i]){
p++;
f=f+10;
System.out.printf("\n"+"恭喜你答对第%d题",i+1);
}
else {
q++;
System.out.printf("\n"+"对不起,你答错了第%d题",i+1);
System.out.printf("\n"+"正确答案是:"+"%d",shuzi[i]);
}
}
System.out.printf("\n"+"你答对了%d题",p);
System.out.printf("\n"+"你答错了%d题",q);
System.out.println("\n"+"你的得分为:"+f);
System.out.println("\n"+"所用时间:"+Totletime);
}
public String getp() {
return String.valueOf(p);
}
public String getq() {
return String.valueOf(q);
}
public String getf() {
return String.valueOf(f);
}
}
import java.awt.Graphics;
import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.Panel;
import javax.swing.JLabel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Font;
import javax.swing.ImageIcon;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.Icon;
import javax.swing.event.*;
import javax.swing.*;
import java.awt.*;
import java.awt.FlowLayout;
import java.util.StringTokenizer;
import javax.swing.SwingConstants;
public class JiShi extends JFrame implements ActionListener{
public TextField T0;
public TextField T1;
public TextField T2;
public TextField T3;
public TextField T4;
public TextField t1;
public String n1;
public String m1;
public String c1;
public int n2;
public int m2;
public int c2;
/**
* Launch the application.
*/
/**
* Create the application.
*/
JiShi(){
getContentPane().setBackground(Color.PINK);
getContentPane().setForeground(Color.BLACK);
setForeground(Color.PINK);
setTitle("\u8BA1\u7B97");
setBounds(100, 100, 450, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{86, 0, 43, 214, 204, 51, 10, 63, 0, 0, 10, 120, 0};
gridBagLayout.rowHeights = new int[]{41, 109, 43, 33, 50, 0};
gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
getContentPane().setLayout(gridBagLayout);
Label label_2 = new Label("\u6B22\u8FCE\u8FDB\u5165\u5E7F\u5546\u56DB\u5219\u8FD0\u7B97\u7CFB\u7EDF\uFF01");
label_2.setAlignment(Label.RIGHT);
label_2.setFont(new Font("黑体", Font.PLAIN, 12));
GridBagConstraints gbc_label_2 = new GridBagConstraints();
gbc_label_2.anchor = GridBagConstraints.SOUTHWEST;
gbc_label_2.insets = new Insets(0, 0, 5, 5);
gbc_label_2.gridx = 4;
gbc_label_2.gridy = 0;
getContentPane().add(label_2, gbc_label_2);
Panel panel_4 = new Panel();
GridBagConstraints gbc_panel_4 = new GridBagConstraints();
gbc_panel_4.anchor = GridBagConstraints.EAST;
gbc_panel_4.gridwidth = 4;
gbc_panel_4.insets = new Insets(0, 0, 5, 5);
gbc_panel_4.gridx = 3;
gbc_panel_4.gridy = 1;
getContentPane().add(panel_4, gbc_panel_4);
JLabel j = new JLabel(new ImageIcon("I:\\Yunsuan\\src\\\u5E7F\u5546.jpg"));
panel_4.add(j);
j.setFont(UIManager.getFont("Button.font"));
j.setBackground(Color.WHITE);
j.setBounds(1, 1, 1, 1);
Panel panel_1 = new Panel();
GridBagConstraints gbc_panel_1 = new GridBagConstraints();
gbc_panel_1.anchor = GridBagConstraints.SOUTHEAST;
gbc_panel_1.insets = new Insets(0, 0, 5, 5);
gbc_panel_1.gridx = 3;
gbc_panel_1.gridy = 2;
getContentPane().add(panel_1, gbc_panel_1);
Label label = new Label("\u9898\u76EE\u6570\uFF1A");
label.setAlignment(Label.RIGHT);
panel_1.add(label);
T0 = new TextField();
T0.setFont(new Font("Dialog", Font.PLAIN, 12));
T0.setColumns(1);
T0.addActionListener(this);
panel_1.add(T0);
Panel panel_7 = new Panel();
GridBagConstraints gbc_panel_7 = new GridBagConstraints();
gbc_panel_7.insets = new Insets(0, 0, 5, 5);
gbc_panel_7.gridx = 4;
gbc_panel_7.gridy = 2;
getContentPane().add(panel_7, gbc_panel_7);
Label label_7 = new Label("\u4E58\u9664,\u9636\u4E58\uFF081,0,2\uFF09\uFF1A");
panel_7.add(label_7);
T1 = new TextField();
T1.setColumns(1);
T1.addActionListener(this);
panel_7.add(T1);
Panel panel_6 = new Panel();
GridBagConstraints gbc_panel_6 = new GridBagConstraints();
gbc_panel_6.anchor = GridBagConstraints.EAST;
gbc_panel_6.insets = new Insets(0, 0, 5, 5);
gbc_panel_6.gridx = 3;
gbc_panel_6.gridy = 3;
getContentPane().add(panel_6, gbc_panel_6);
Label label_6 = new Label("\u7B54\u6848\u4E3A\uFF1A");
panel_6.add(label_6);
T3 = new TextField();
T3.setEditable(false);
T3.setEnabled(false);
panel_6.add(T3);
T3.setColumns(1);
Panel panel = new Panel();
GridBagConstraints gbc_panel = new GridBagConstraints();
gbc_panel.anchor = GridBagConstraints.WEST;
gbc_panel.insets = new Insets(0, 0, 5, 5);
gbc_panel.gridx = 4;
gbc_panel.gridy = 3;
getContentPane().add(panel, gbc_panel);
Label label_3 = new Label("\u606D\u559C\u4F60\u7B54\u5BF9\u4E86\uFF1A");
label_3.setAlignment(Label.RIGHT);
panel.add(label_3);
T4 = new TextField();
T4.setFont(new Font("Dialog", Font.PLAIN, 12));
T4.setEnabled(false);
T4.setEditable(false);
T4.setColumns(4);
panel.add(T4);
Panel panel_5 = new Panel();
GridBagConstraints gbc_panel_5 = new GridBagConstraints();
gbc_panel_5.anchor = GridBagConstraints.NORTHEAST;
gbc_panel_5.insets = new Insets(0, 0, 0, 5);
gbc_panel_5.gridx = 3;
gbc_panel_5.gridy = 4;
getContentPane().add(panel_5, gbc_panel_5);
Label label_5 = new Label("\u603B\u5206\uFF1A");
panel_5.add(label_5);
label_5.setAlignment(Label.RIGHT);
T2 = new TextField();
T2.setEditable(false);
T2.setEnabled(false);
T2.setColumns(1);
panel_5.add(T2);
Panel panel_2 = new Panel();
GridBagConstraints gbc_panel_2 = new GridBagConstraints();
gbc_panel_2.anchor = GridBagConstraints.NORTHEAST;
gbc_panel_2.insets = new Insets(0, 0, 0, 5);
gbc_panel_2.gridx = 4;
gbc_panel_2.gridy = 4;
getContentPane().add(panel_2, gbc_panel_2);
Label label_4 = new Label("\u5BF9\u4E0D\u8D77\u4F60\u7B54\u9519\u4E86\uFF1A");
panel_2.add(label_4);
t1 = new TextField();
t1.setEnabled(false);
t1.setEditable(false);
t1.setColumns(3);
panel_2.add(t1);
setVisible(true); //将窗口设置为可视
setResizable(false);
setAlwaysOnTop(true);//设置此窗口永远为最上方 是window的方法
setLocationRelativeTo(null); //让窗口在屏幕的正中间显示
}
/**
* Initialize the contents of the frame.
*/
public void actionPerformed(ActionEvent evt){
if(evt.getSource()==T0){
T1.requestFocusInWindow();
}
else if(evt.getSource()==T1){
n1=T0.getText();
m1=T1.getText();
n2=Integer.valueOf(n1);
m2=Integer.valueOf(m1);
c2=Integer.valueOf(c1);
YunSuan bes =new YunSuan();
bes.TiMu(n2,m2);
bes.PanDuan();
T4.setText(bes.getp());
T2.setText(bes.getf());
t1.setText(bes.getq());
}
}
}
import java.util.*;
public class CeShi {
public static void main(String[] args) {
int e,h;
Scanner in=new Scanner(System.in);
String mz[]=new String[100];
System.out.printf("请输入用户名:");
String md= in.nextLine();
System.out.printf("请输入题目个数:");
h=in.nextInt();
System.out.printf("是否需要除乘法,阶乘:(1、0,2):");
e=in.nextInt();
YunSuan t =new YunSuan(e,h);
t.TiMu(h,e);
t.PanDuan();
}
}
7.界面及测试结果:
8.问题:界面那里还是有点问题,希望大家能给点建议我们!
最后附上我们的合照: