Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何通过id、姓名、经验以最佳方式获取员工_C#_Oop_Design Patterns_Solid Principles - Fatal编程技术网

C# 如何通过id、姓名、经验以最佳方式获取员工

C# 如何通过id、姓名、经验以最佳方式获取员工,c#,oop,design-patterns,solid-principles,C#,Oop,Design Patterns,Solid Principles,我在没有应用任何设计模式的情况下编写了下面的代码,这段代码中是否有任何错误 class Employee { public int EmployeeID { get; set; } public int YearOExperience { get; set; } public int Salary { get; set; } public string EmploeyeeType { get; set; } } interface

我在没有应用任何设计模式的情况下编写了下面的代码,这段代码中是否有任何错误

class Employee {
    public int EmployeeID
    { get; set; }
    public int YearOExperience
    { get; set; }
    public int Salary
    { get; set; }
    public string EmploeyeeType
    { get; set; }
}

interface IEmployee {
    List<Employee> getInformation(int id, int exp, int sal);

}

class EmployeeData1 {

    public List<Employee> GetData(int id,int exp , int sal)
        {
            List<Employee> empInfo = new List<Employee> {

    new Employee { EmploeyeeType = "P", EmployeeID = 1, Salary = 20000, YearOExperience= 2  },
     new Employee { EmploeyeeType = "P", EmployeeID = 2, Salary = 20000, YearOExperience= 2  },
      new Employee { EmploeyeeType = "C", EmployeeID = 3, Salary = 20000, YearOExperience= 2  }

        };
            return empInfo;
        }

    }

    static void Main(string[] args) {EmployeeData1 emp = new EmployeeData1();
        emp.getInformation(1, 2, 2000);
    };
}
class员工{
公共国际雇员ID
{get;set;}
公共国际年经验
{get;set;}
公共内部工资
{get;set;}
公共字符串employeeType
{get;set;}
}
介面雇员{
列表获取信息(int-id、int-exp、int-sal);
}
类别EmployeeData1{
公共列表GetData(int-id、int-exp、int-sal)
{
List empInfo=新列表{
新员工{employeeetype=“P”,EmployeeID=1,工资=20000,年经验=2},
新员工{employeeetype=“P”,EmployeeID=2,工资=20000,年经验=2},
新员工{employeeetype=“C”,EmployeeID=3,工资=20000,年经验=2}
};
返回empInfo;
}
}
静态void Main(字符串[]args){EmployeeData1 emp=new EmployeeData1();
《环境管理信息》(2000年1月2日);
};
}
以下是作业:
由于您粘贴的是图像而不是文本,我们必须通过重新键入来支付费用

别这样。与其尝试采用设计模式(这是您不期望的),不如选择正确的设计模式

您的任务要求您输入员工姓名、员工类型和工作年限

您的console应用程序应该通过
console.ReadLine()
命令获取这三个值

请确保这是真的。但可能是这样的,因为所有的代码竞赛都使用stdin(
Console.ReadLine()从stdin中读取)向应用程序提供输入

那么,你的老师想要你做的是:

  • 生成连续的员工Id
  • 根据工作经验计算工资
  • 打印结果(使用
    Console.WriteLine()
    ,写入标准输出)
  • 转到下一个员工
  • 这里有一个有限的例子来帮助你。请自己研究并填写所需的部分,否则,如果不是你的部分,获得好分数意味着什么

    请注意,我并不是说你可以直接移交

    但至少你可以以此为出发点

    祝你好运

        static void Main()
        {
            // this will be used to create sequential employee Ids
            int employeeId = 0;
    
            while(true) // Just press enter without entering anything to exit.
            {
                string employeeName = Console.ReadLine();
    
                if(employeeName == "")
                {
                    return;
                }
    
                // Get the other two input parameters like the one above.
                // Please be careful with the last one (years of experience)
                // It should be parsed to an integer (a little research effort)
    
                // string employeeType = ..
                // int yearsOfExperience = ..
    
                // Now, assign this employee the next Id.
                employeeId++;
    
                // And now, calculate the employee's salary
                // You should use the years of experience and employee type
                // to match an amount in the salary table.
                int salary;
                if(employeeType == "Permanent")
                {
                    salary = ..;
                }
                else
                {
                    salary = ..;
                }
    
                // And finally, print-out using stdout
                Console.WriteLine("Employee ID: {0}", employeeId);
                // Print the other two outputs like the one above 
    
            }
        }
    

    你想解决什么问题?这是做了你不想做的事情,还是没能做你想做的事情?这段代码面临的问题是什么?您创建的接口不能在代码中的任何地方使用。这是我注意到的一个问题。我想使用设计模式,可以吗