2016-04-15 8 views
2

少なくとも10人の従業員の情報を入力するための適切なGUIを作成する必要があります。各従業員について、以下の情報を入力する必要があります。従業員ID、従業員の姓、従業員の姓、年俸などが含まれます。私は入力データの正確性をチェックする必要があります。さらに、私は別のクラスを作成する必要があります従業員、従業員の情報を含む:従業員のID、名、姓と年俸。クラスにはコンストラクタのプロパティとメソッドが必要です。すべての従業員情報を従業員タイプの配列に格納する必要があります。フォームGUIを読んだ後、特定の従業員についての情報、関連するコンストラクタを持つ従業員クラス(配列の要素)のオブジェクトも作成します。ユーザは、最低年俸を有する複数の従業員を有するにもかかわらず、最低年俸を有する従業員を見つけることができるようにする。それらに関する情報を表示します。必要な情報を表示するための適切なGUIをユーザーに提供する必要があります。 私のプログラムに例外を処理するための適切なコードと適切な方法を含めることを保証する必要があります。ここC#:最低給与の従業員名を表示する方法

は、クラスの従業員である:

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() 
     { 

     } 
    } 
} 

私の質問は:

ユーザーは最低年俸を持つ従業員を見つけるにはどうすればよいです。最低年俸を持つ複数の従業員がいることを確認し、それらに関する情報を表示する必要があります。例外を処理するための適切なコードを含む必要な情報を表示するための適切なGUI(例えば、メッセージボックス)をユーザに提供し、適切な方法を使用することもできる。

+0

にそれを変更するには?あなたがこれをしたい場合は、私の答えを参照してください –

答えて

0
あなたは、その後、 IComparableをインターフェイスを実装給与に対するおよび他のクラスのソート配列内のオブジェクトを比較するために、あなたのクラスの従業員を作成する必要があり

...

例:

public class Employee :IComparable<Employee> 
{ 
    private int employeeID; 
    private string fullName; 
    private string lastName; 
    private double salary; 

    public int CompareTo(Employee other) 
    { 
    return salary.CompareTo(other.salary); 
    } 
} 

private void Find() 
{ 
    Array.Sort(employee); // after this Employee is sorted 
    employee[0]; 
    or 
    employee[9]; 
} 
+0

あなたに助けてくれてありがとう。特定の従業員IDのフルネーム、姓、年俸を取得するにはどうすればよいですか? – Naz

+0

employees [0] .employeeID、employees [0] .fullName、employees [0] .salary ... –

+0

エラー名前employeeは現在のコンテキストに存在しませんが、存在します。Employee [] employee = new Employee [10]; – Naz

0

これは最低給与emplyeesのリストが表示されます

 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(); 
0

あなたは少し

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)); 
     } 
    } 

をコーディングして、既定のコンストラクタは、その後デフォルトコンストラクタで初期化となり、すべてのminEmpSalarylist存在する場合は、リスト

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); 
関連する問題