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 StudentScore
{
public class Student
{
string name;
int score; public int GiveScore(int amount)
{
if (amount > 0)
{
score += amount;
return amount;
}
else
{
MessageBox.show("加分" + amount + "不是一个合理的值");
return 0;
}
} public int TakeOffScore(int amount)
{
if (Score >= amount && amount > 0)
{
Score -= amount;
return amount; }
else
{
MessageBox.Show("减分" + amount + "不是一个合理的值");
return 0;
} }
}}
namespace WindowsForms1
{
public partial class Form1 : Form
{
Student zhangfei, liubei;
public void UpdateForm()
{
label3.Text = zhangfei.Name + "have" + zhangfei.Score + "分";
label4.Text = liubei.Name + "have" + liubei.Score + "分";
}
public Form1()
{
InitializeComponent(); zhangfei=new Student();
liubei=new Student();
zhangfei.Name="zhangfei";
zhangfei.Score = 100;
liubei.Name = "liubei";
liubei.Score = 100;
UpdateForm;
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
zhangfei.GiveScore(5);
UpdateForm;
} private void button2_Click(object sender, EventArgs e)
{
liubei.TakeOffScore(3);
UpdateForm;
}
}
}《提示没有student这个空间,我是新手,看了下我的studnet写的是public啊》
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace StudentScore
{
public class Student
{
string name;
int score; public int GiveScore(int amount)
{
if (amount > 0)
{
score += amount;
return amount;
}
else
{
MessageBox.show("加分" + amount + "不是一个合理的值");
return 0;
}
} public int TakeOffScore(int amount)
{
if (Score >= amount && amount > 0)
{
Score -= amount;
return amount; }
else
{
MessageBox.Show("减分" + amount + "不是一个合理的值");
return 0;
} }
}}
namespace WindowsForms1
{
public partial class Form1 : Form
{
Student zhangfei, liubei;
public void UpdateForm()
{
label3.Text = zhangfei.Name + "have" + zhangfei.Score + "分";
label4.Text = liubei.Name + "have" + liubei.Score + "分";
}
public Form1()
{
InitializeComponent(); zhangfei=new Student();
liubei=new Student();
zhangfei.Name="zhangfei";
zhangfei.Score = 100;
liubei.Name = "liubei";
liubei.Score = 100;
UpdateForm;
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
zhangfei.GiveScore(5);
UpdateForm;
} private void button2_Click(object sender, EventArgs e)
{
liubei.TakeOffScore(3);
UpdateForm;
}
}
}《提示没有student这个空间,我是新手,看了下我的studnet写的是public啊》
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货