第三次作业 结对编程
软件工程助教老师第三次作业
一 设计思路
由于这次的作业是要我们结对编程的,所以在开始做这次作业的时候,我就找了一个结对编程的小伙伴-----王颜辉。我们决定在新的基础上重新做这次的作业,创建了一个windows窗体应用程序,我们在做关于关于时间和数量上出现了分歧,我坚持认为时间和数量只能有一个,但他坚持要都做,没有办法的我向他妥协了,在选择计算方法上,直接交给用户来选择,做了一个TextBox来接收用户输入是那个四则法则。至于想在什么范围内进行计算,也交给用户自己选择。
二 代码实现
Form1 窗体代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace sizeyunsuan
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int count = 0; //定¨义?题琣目?总哩?数簓,?正y确ā?数簓,?四?则ò运?算?的?变?量?
public static int right = 0;
public static int sum;
public static int lefttime;
public static int m1, m2;
public void RandomNum() //定¨义?随?机ú产ú生Θ?随?机ú数簓的?方?法ぁ?
{
try
{
Random ran = new Random();
int n1, n2;
m1 = Convert.ToInt32(textBox5.Text);
m2 = Convert.ToInt32(textBox6.Text);
n1 = ran.Next(m1, m2);
n2 = ran.Next(m1, n1);
textBox2.Text = n1.ToString();
textBox3.Text = n2.ToString();
textBox4.Text = "";
}
catch (Exception ex)
{
MessageBox.Show("请?输?入?数簓值μ范?围§");
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int minute;
try
{
minute = int.Parse(this.textBox7.Text);
}
catch (System.Exception ex)
{
this.label8.Text = "输?入?错洙?误ó";
return;
}
lefttime = minute;
this.timer1.Interval = 1000;
this.timer1.Enabled = true;
this.timer1.Start();
RandomNum();
}
public void jiance()
{
}
private void textBox4_KeyDown(object sender, KeyEventArgs e)
{
string m = textBox1.Text;
int n = Convert.ToInt32(textBox8.Text);
int result;
switch (m)
{
case "+":
sum = int.Parse(textBox2.Text) + int.Parse(textBox3.Text);
break;
case "-":
sum = int.Parse(textBox2.Text) - int.Parse(textBox3.Text);
break;
case "×á":
sum = int.Parse(textBox2.Text) * int.Parse(textBox3.Text);
break;
case "÷?":
sum = int.Parse(textBox2.Text) * int.Parse(textBox3.Text);
break;
default:
break;
}
if (e.KeyCode == Keys.Enter)
{
if (int.TryParse(textBox4.Text, out result) == false)
{
MessageBox.Show("请?输?入?数簓字?");
count--;
}
if (textBox4.Text == sum.ToString())
{
right++;
count++;
RandomNum();
}
else
{
count++;
RandomNum();
}
}
if (n == count)
{
MessageBox.Show("题琣目?答鋏完?,?请?重?新?开a始?");
textBox3.Enabled = false;
Form2 frm2 = new Form2();
frm2.ShowDialog();
this.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox3.Enabled = false;
Form2 frm2 = new Form2();
frm2.ShowDialog();
this.Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
this.label3.Text = this.textBox1.Text;
}
public void timer1_Tick(object sender, EventArgs e)
{
if (lefttime <= 0)
{
timer1.Enabled = false;
MessageBox.Show("答鋏题琣时骸?间?到?!?");
textBox4.Enabled = false;
Form2 frm2 = new Form2();
frm2.ShowDialog();
}
this.label8.Text = "剩骸?余?时骸?间?" + lefttime.ToString() + "秒?";
lefttime--;
}
}
}
Form2 代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace sizeyunsuan
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
textBox1.Text = Form1.count.ToString();
textBox2.Text = Form1.right.ToString();
textBox3.Text = ((Form1.count - (double)(Form1.right))).ToString();
textBox4.Text = ((Form1.right / (double)(Form1.count)) * 100).ToString() + "%";
}
}
}
三 psp
四 结对编程总结
这是我第一次和别人做结对编程,感觉自己的想法他接收不了,我的想法他也不理解,在以后的时间里要慢慢去磨合,毕竟这是第一次做。
这对两个人的基础知识要求的很高。希望以后合作的越来越好。
五 结对编程对象
王颜辉