C# 4.0 C#:如何显示薪资最低的员工姓名
我必须创建一个适当的GUI来输入至少10名员工的信息。对于每位员工,我必须输入以下信息。员工ID、员工姓名、员工姓氏和年薪。此外,我必须检查输入数据的正确性。此外,我需要创建一个单独的类EMPLOYEE,其中包含员工信息:员工ID、名字、姓氏和年薪。该类应该具有构造函数属性和方法。所有员工信息都必须存储在employee类型的数组中。在读取表单GUI中关于特定employee的信息之后,还要使用相关构造函数创建类employee(数组元素)的对象。用户希望能够找到年薪最低的员工,尽管有多个员工年薪最低。并显示有关它们的信息。应为用户提供适当的GUI以显示所需信息。 我需要确保在我的程序中包含处理异常的适当代码,以及适当的方法 这是班级的职员:C# 4.0 C#:如何显示薪资最低的员工姓名,c#-4.0,C# 4.0,我必须创建一个适当的GUI来输入至少10名员工的信息。对于每位员工,我必须输入以下信息。员工ID、员工姓名、员工姓氏和年薪。此外,我必须检查输入数据的正确性。此外,我需要创建一个单独的类EMPLOYEE,其中包含员工信息:员工ID、名字、姓氏和年薪。该类应该具有构造函数属性和方法。所有员工信息都必须存储在employee类型的数组中。在读取表单GUI中关于特定employee的信息之后,还要使用相关构造函数创建类employee(数组元素)的对象。用户希望能够找到年薪最低的员工,尽管有多个员工年
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Project_employee
{
class Employee
{
private int employeeID;
private string fullName;
private string lastName;
private double salary;
public Employee()
{
employeeID = 0;
fullName = "";
lastName = "";
salary = 0.0;
}
public Employee(int empIDValue, string fullNameVal, string lastNameVal)
{
employeeID = empIDValue;
fullName = fullNameVal;
lastName = lastNameVal;
salary = 0.0;
}
public Employee(int empIDValue, string fullNameVal, string lastNameVal, double salaryValue)
{
employeeID = empIDValue;
fullName = fullNameVal;
lastName = lastNameVal;
salary = salaryValue;
}
public int EmployeeIDNum
{
get
{
return employeeID;
}
set
{
employeeID = value;
}
}
public string FullName
{
get
{
return fullName;
}
set
{
fullName = value;
}
}
public int Getinfo
{
get
{
return employeeID;
}
set
{
employeeID = value;
}
}
public string employeeInformationToString()
{
// employeeID = Convert.ToInt32(this.textBox1.Text);
return (Convert.ToString(employeeID) + " " + fullName + " " + lastName + " " + Convert.ToString(salary));
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Project_employee
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void Searchbtn_Click(object sender, EventArgs e)
{
employee[0] = new Employee();
employee[1] = new Employee(17433, "Adrian", "Smith", 8000.00);
employee[2] = new Employee(17434, "Stephen", "Rad", 9000.00);
employee[3] = new Employee(17435, "Jesse", "Harris", 800.00);
employee[4] = new Employee(17436, "jonatan", "Morris", 9500.00);
employee[5] = new Employee(17437, "Morgen", "Freeman", 12000.00);
employee[6] = new Employee(17438, "Leory", "Gomez", 10200.00);
employee[7] = new Employee(17439, "Michael", "Brown", 9000.00);
employee[8] = new Employee(17440, "Andrew", "White", 3500.00);
employee[9] = new Employee(17441, "Maria", "Carson", 12000.00);
//employee[10] = new Employee(17442, "Mark", "Jonson", 17000.00);
for(int i = 0; i < 10; i++)
{
string employeeString = employee[i].employeeInformationToString() + "\r\n";
richTextBox1.AppendText(employeeString);
}
}
Employee[] employee = new Employee[10];
private void getinfibtn_Click(object sender, EventArgs e)
{
Find();
}
private void Find()
{
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
命名空间项目\u员工
{
班级员工
{
私人国际雇员ID;
私有字符串全名;
私有字符串lastName;
私人双薪;
公职人员()
{
employeeID=0;
全名=”;
lastName=“”;
工资=0.0;
}
公共雇员(int-empIDValue、字符串fullNameVal、字符串lastNameVal)
{
employeeID=empIDValue;
fullName=fullNameVal;
lastName=lastNameVal;
工资=0.0;
}
公共雇员(int-empIDValue、字符串fullNameVal、字符串lastNameVal、双salaryValue)
{
employeeID=empIDValue;
fullName=fullNameVal;
lastName=lastNameVal;
工资=工资价值;
}
public int EmployeeIDNum
{
得到
{
返回员工ID;
}
设置
{
employeeID=值;
}
}
公共字符串全名
{
得到
{
返回全名;
}
设置
{
全名=值;
}
}
公共int获取信息
{
得到
{
返回员工ID;
}
设置
{
employeeID=值;
}
}
公共字符串employeeInformationToString()
{
//employeeID=Convert.ToInt32(this.textBox1.Text);
return(Convert.ToString(employeeID)+“”+全名+“”+姓氏+“”+Convert.ToString(薪水));
}
}
}
使用制度;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
命名空间项目\u员工
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
私有void richTextBox1_TextChanged(对象发送方,事件参数e)
{
}
私有无效搜索单击(对象发送者,事件参数e)
{
员工[0]=新员工();
员工[1]=新员工(17433,“阿德里安”,“史密斯”,8000.00);
雇员[2]=新雇员(17434,“斯蒂芬”,“拉德”,9000.00);
员工[3]=新员工(17435,“杰西”,“哈里斯”,800.00);
员工[4]=新员工(17436,“jonatan”,“Morris”,9500.00);
员工[5]=新员工(17437,“摩根”,“弗里曼”,12000.00);
员工[6]=新员工(17438,“勒里”,“戈麦斯”,10200.00);
员工[7]=新员工(17439,“迈克尔”,“布朗”,9000.00);
员工[8]=新员工(17440,“安德鲁”,“怀特”,3500.00);
雇员[9]=新雇员(17441,“玛丽亚”,“卡森”,12000.00);
//员工[10]=新员工(17442,“马克”,“琼森”,17000.00);
对于(int i=0;i<10;i++)
{
字符串employeeString=employee[i]。employeeInformationToString()+“\r\n”;
richTextBox1.AppendText(employeeString);
}
}
员工[]员工=新员工[10];
私有void getinfibtn_单击(对象发送方,事件参数e)
{
查找();
}
私有void Find()
{
}
}
}
我的问题是:
用户如何找到年薪最低的员工。我必须确保至少有一名员工年薪最低,并显示他们的相关信息。为用户提供适当的GUI(如消息框),以显示所需信息,包括处理异常的适当代码,并在适当情况下使用方法?您需要让您的班级员工实现可兼容的界面,然后将对象与薪水进行比较,并在另一个类中对数组进行排序 例子:
这将列出最低工资员工的名单
employee.Add(new Employee(17434, "Stephen", "Rad", 9000.00));
employee.Add(new Employee(17435, "Jesse", "Harris", 800.00));
employee.Add(new Employee(17436, "jonatan", "Morris", 9500.00));
var c = employee.OrderBy(i => i.salary).ToList();
var e = employee.Where(i => Math.Abs(i.salary - c[0].salary) < 1).ToList();
employee.Add(新员工(17434,“斯蒂芬”,“拉德”,9000.00));
添加(新员工(17435,“杰西”,“哈里斯”,800.00));
添加(新员工(17436,“jonatan”,“Morris”,9500.00));
var c=employee.OrderBy(i=>i.salary.ToList();
var e=employee.Where(i=>Math.Abs(i.salary-c[0].salary)<1.ToList();
稍微修改了您的代码
class Employee
{
private int employeeID;
private string fullName;
private string lastName;
private double salary;
public double Salary
{
get
{
return salary;
}
set
{
salary = value;
}
}
//public Employee()
//{
// employeeID = 0;
// fullName = "";
// lastName = "";
// salary = 0.0;
//}
//public Employee(int empIDValue, string fullNameVal, string lastNameVal)
//{
// employeeID = empIDValue;
// fullName = fullNameVal;
// lastName = lastNameVal;
// salary = 0.0;
//}
public Employee(int empIDValue, string fullNameVal, string lastNameVal, double salaryValue)
{
employeeID = empIDValue;
fullName = fullNameVal;
lastName = lastNameVal;
salary = salaryValue;
}
public int EmployeeIDNum
{
get
{
return employeeID;
}
set
{
employeeID = value;
}
}
public string FullName
{
get
{
return fullName;
}
set
{
fullName = value;
}
}
public int Getinfo
{
get
{
return employeeID;
}
set
{
employeeID = value;
}
}
public string employeeInformationToString()
{
// employeeID = Convert.ToInt32(this.textBox1.Text);
return (Convert.ToString(employeeID) + " " + fullName + " " + lastName + " " + Convert.ToString(salary));
}
}
和获取列表中的最小值
var minEmpSalarylist = employee.Where(x => x.Salary == employee.Min(y => y.Salary)).ToList();
如果存在默认构造函数,则所有minE
class Employee
{
private int employeeID;
private string fullName;
private string lastName;
private double salary;
public double Salary
{
get
{
return salary;
}
set
{
salary = value;
}
}
//public Employee()
//{
// employeeID = 0;
// fullName = "";
// lastName = "";
// salary = 0.0;
//}
//public Employee(int empIDValue, string fullNameVal, string lastNameVal)
//{
// employeeID = empIDValue;
// fullName = fullNameVal;
// lastName = lastNameVal;
// salary = 0.0;
//}
public Employee(int empIDValue, string fullNameVal, string lastNameVal, double salaryValue)
{
employeeID = empIDValue;
fullName = fullNameVal;
lastName = lastNameVal;
salary = salaryValue;
}
public int EmployeeIDNum
{
get
{
return employeeID;
}
set
{
employeeID = value;
}
}
public string FullName
{
get
{
return fullName;
}
set
{
fullName = value;
}
}
public int Getinfo
{
get
{
return employeeID;
}
set
{
employeeID = value;
}
}
public string employeeInformationToString()
{
// employeeID = Convert.ToInt32(this.textBox1.Text);
return (Convert.ToString(employeeID) + " " + fullName + " " + lastName + " " + Convert.ToString(salary));
}
}
var minEmpSalarylist = employee.Where(x => x.Salary == employee.Min(y => y.Salary)).ToList();
employee[0] = new Employee();
employee[0] = new Employee(17433, "XXX", "YYY", 8000.00);