-2

i have written below code without applying any design pattern,Is anything wrong in this code.

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

Here is the assignment: problem

Gus
  • 3,534
  • 1
  • 30
  • 39
And
  • 5
  • 5
  • What problem are you trying to solve? Does this do something you don't want, or fail to do something you do want? – Gus Mar 30 '20 at 17:06
  • What's the issue you are facing with this code? You have interface created be not used anywhere in the code. That's one problem I notice. – Chetan Mar 30 '20 at 17:07
  • i want to use design pattern can u pls – And Mar 30 '20 at 17:36

1 Answers1

0

Since you pasted the image instead of text, we have to pay for it by re-typing.

Do not handover like this. Instead of trying to employ design patterns (which is not expected from you), handover work which is correct.

Your assignment says that you should take as input the employee name, employee type and years of experience.

Your console app should get these three values by Console.ReadLine() commands.

Please make sure that this is so. Bu it probably is, since all the code competitions use stdin (Console.ReadLine() reads from stdin) to feed input to an application.

Then, what your teacher wants from you are:

  1. Generate a sequential employee Id,
  2. Calculate the salary according to the years of experience
  3. Print out the results (using Console.WriteLine(), which writes to the stdout (standard output))
  4. Proceed to the next employee

Here is a limited example to help you. Please do research and fill in the required parts yourself, otherwise, what does it mean to get a good mark if it isn't yours?

I am not saying that you can handover this directly, mind you.

But at least you can take this as a starting point.

Good luck.

    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 

        }
    }
Oguz Ozgul
  • 6,809
  • 1
  • 14
  • 26