/*设计了一个Dinnerparty的类,来为Dinnerparty的花费做一个预算
题目要求:
1、食物每人25¥/人
2、饮料:
喝酒方案:每人20¥
不喝酒方案:每人5¥,并且总共的花费可以打九五折
3、装饰:
特别装饰:每人7.5¥ 总花费再加30¥
普通装饰:每人15¥并且 总花费再加50¥用到 numbericupdown textbox checkbox 这些控件
如下为我的程序:
类的设计:*/
using System;
using System.Collections.Generic;
using System.Text;namespace DinnerParty
{
class DinnerParty
{
// public float TotalCost;
//private float FoodCostPerPerson;
private float DrinkCostPerPerson;
private float DecorationCostPerPerson;
private int numberofpeople;
private float foodcostperperson;
public float TotalCost;
public float FoodCostPerPerson
{
set
{
foodcostperperson = 25.0f;
}
get
{
return foodcostperperson;
}
}
public int Numberofpeople
{
get
{
return numberofpeople;
}
set
{
numberofpeople=value;
}
}
private bool isfancydecoration;
public bool Isfancydecoration
{
set
{
isfancydecoration = value;
if (isfancydecoration)
{
DecorationCostPerPerson = 15.0f;
}
else
{
DecorationCostPerPerson = 7.5f;
}
}
get
{
return isfancydecoration;
}
}
private bool ishealthyoption;
public bool Ishealthyoption
{
set
{
ishealthyoption = value;
if (ishealthyoption)
{
DrinkCostPerPerson = 5.0f;
}
else
{ DrinkCostPerPerson = 20.0f; }
}
get
{
return ishealthyoption;
}
}
public DinnerParty()
{
this.TotalCost = (this.Numberofpeople * FoodCostPerPerson);
if (Isfancydecoration == true)
{
this.TotalCost += (this.Numberofpeople * DecorationCostPerPerson) + 50;
}
else
{
this.TotalCost += (this.Numberofpeople * DecorationCostPerPerson) + 30;
}
if (Ishealthyoption == true)
{
this.TotalCost = (this.Numberofpeople * DrinkCostPerPerson + TotalCost) * 0.95f;
}
else
{
this.TotalCost += this.Numberofpeople * DrinkCostPerPerson;
} }
}
}
/*form1 的代码*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace DinnerParty
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DinnerParty dinner=new DinnerParty();
dinner.Numberofpeople = Convert.ToInt16(this.numericUpDown1.Value);
dinner.Isfancydecoration = Convert.ToBoolean(checkBox1.Checked);
dinner.Ishealthyoption = Convert.ToBoolean(checkBox2.Checked);
this.textBox1.Text = dinner.TotalCost.ToString();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
DinnerParty dinner = new DinnerParty();
textBox1.Text = Convert.ToString(dinner.TotalCost);
} private void checkBox1_Click(object sender, EventArgs e)
{
DinnerParty dinner = new DinnerParty();
if(checkBox1.Checked)
{
dinner.Isfancydecoration = Convert.ToBoolean(checkBox1.Checked);
}
} private void checkBox2_Click(object sender, EventArgs e)
{
DinnerParty dinner = new DinnerParty();
if (checkBox2.Checked)
{
dinner.Ishealthyoption = Convert.ToBoolean(checkBox2.Checked);
}
}
}
}
为什么最终运行以后不管点什么控件,最后的textbox里面的数都是恒定不变的??大家谁知道是为什么??、
都来找一下错误吧……不知道怎么改??
题目要求:
1、食物每人25¥/人
2、饮料:
喝酒方案:每人20¥
不喝酒方案:每人5¥,并且总共的花费可以打九五折
3、装饰:
特别装饰:每人7.5¥ 总花费再加30¥
普通装饰:每人15¥并且 总花费再加50¥用到 numbericupdown textbox checkbox 这些控件
如下为我的程序:
类的设计:*/
using System;
using System.Collections.Generic;
using System.Text;namespace DinnerParty
{
class DinnerParty
{
// public float TotalCost;
//private float FoodCostPerPerson;
private float DrinkCostPerPerson;
private float DecorationCostPerPerson;
private int numberofpeople;
private float foodcostperperson;
public float TotalCost;
public float FoodCostPerPerson
{
set
{
foodcostperperson = 25.0f;
}
get
{
return foodcostperperson;
}
}
public int Numberofpeople
{
get
{
return numberofpeople;
}
set
{
numberofpeople=value;
}
}
private bool isfancydecoration;
public bool Isfancydecoration
{
set
{
isfancydecoration = value;
if (isfancydecoration)
{
DecorationCostPerPerson = 15.0f;
}
else
{
DecorationCostPerPerson = 7.5f;
}
}
get
{
return isfancydecoration;
}
}
private bool ishealthyoption;
public bool Ishealthyoption
{
set
{
ishealthyoption = value;
if (ishealthyoption)
{
DrinkCostPerPerson = 5.0f;
}
else
{ DrinkCostPerPerson = 20.0f; }
}
get
{
return ishealthyoption;
}
}
public DinnerParty()
{
this.TotalCost = (this.Numberofpeople * FoodCostPerPerson);
if (Isfancydecoration == true)
{
this.TotalCost += (this.Numberofpeople * DecorationCostPerPerson) + 50;
}
else
{
this.TotalCost += (this.Numberofpeople * DecorationCostPerPerson) + 30;
}
if (Ishealthyoption == true)
{
this.TotalCost = (this.Numberofpeople * DrinkCostPerPerson + TotalCost) * 0.95f;
}
else
{
this.TotalCost += this.Numberofpeople * DrinkCostPerPerson;
} }
}
}
/*form1 的代码*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace DinnerParty
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DinnerParty dinner=new DinnerParty();
dinner.Numberofpeople = Convert.ToInt16(this.numericUpDown1.Value);
dinner.Isfancydecoration = Convert.ToBoolean(checkBox1.Checked);
dinner.Ishealthyoption = Convert.ToBoolean(checkBox2.Checked);
this.textBox1.Text = dinner.TotalCost.ToString();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
DinnerParty dinner = new DinnerParty();
textBox1.Text = Convert.ToString(dinner.TotalCost);
} private void checkBox1_Click(object sender, EventArgs e)
{
DinnerParty dinner = new DinnerParty();
if(checkBox1.Checked)
{
dinner.Isfancydecoration = Convert.ToBoolean(checkBox1.Checked);
}
} private void checkBox2_Click(object sender, EventArgs e)
{
DinnerParty dinner = new DinnerParty();
if (checkBox2.Checked)
{
dinner.Ishealthyoption = Convert.ToBoolean(checkBox2.Checked);
}
}
}
}
为什么最终运行以后不管点什么控件,最后的textbox里面的数都是恒定不变的??大家谁知道是为什么??、
都来找一下错误吧……不知道怎么改??
解决方案 »
- 日期验证
- 网络唤醒,MAC地址string怎么转换为byte
- 事件的问题
- 求助:代码实现点击webbrowser上的超链
- 求BYTE[]删除函数,ALL和s包含特殊字符,请不要转为字符去删除.
- 工具拦中的|是如何实现的?
- 数据库邦定问题,dataGrid
- 两个进程分别对多个TXT文件进行写操作和读操作,但在读操作时总会漏掉几个TXT。晚饭后在线等答复。
- 我在page_load()事件中动态创建控件,能成功,而在button_click()事件中创建,却失败,错误信息:“未实例化”
- 关于using System.Management ;
- 学C#中关于接口的问题
- 不经过文件如何把image转换成byte[],或串行化。
这句为什么总是在文本改变的时候初始化对象呢?