Skip to content

Commit

Permalink
oopcommit
Browse files Browse the repository at this point in the history
  • Loading branch information
emrekurtarr committed Nov 21, 2021
1 parent a308def commit d6bb49a
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 7 deletions.
Binary file modified Week5-ObjectOriented/OOPBasics/.vs/OOPBasics/v16/.suo
Binary file not shown.
19 changes: 19 additions & 0 deletions Week5-ObjectOriented/OOPBasics/OOPBasics/Entities/Employee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OOPBasics.Entities
{
//Inheritance
public class Employee : Person
{
public Employee(string name,string surname,int age,int salary):base(name,surname,age)
{
Salary = salary;
}

public int Salary { get; set; }
}
}
20 changes: 20 additions & 0 deletions Week5-ObjectOriented/OOPBasics/OOPBasics/Entities/Employer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OOPBasics.Entities
{
// Polymorphism with Person class
// Inheritance
public class Employer : Person
{
public Employer(string name, string surname, int age,string degree) : base(name, surname, age)
{
Degree = degree;
}

public string Degree { get; set; }
}
}
40 changes: 40 additions & 0 deletions Week5-ObjectOriented/OOPBasics/OOPBasics/Entities/Person.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OOPBasics.Entities
{
public class Person
{
private int _Age;
//Encapsulation
public int Age
{
get { return _Age; }
set
{
if (value < 18)
{
_Age = 0;
}
else
{
_Age = value;
}
}
}
public string Name { get; set; }
public string Surname { get; set; }

public Person(string name,string surname,int age)
{
Name = name;
Surname = surname;
Age = age;
}


}
}
4 changes: 0 additions & 4 deletions Week5-ObjectOriented/OOPBasics/OOPBasics/OOPBasics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="Entites\" />
</ItemGroup>

</Project>
21 changes: 19 additions & 2 deletions Week5-ObjectOriented/OOPBasics/OOPBasics/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
using System;
using OOPBasics.Entities;
using OOPBasics.Services;
using System;

namespace OOPBasics
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
EmployerManager employerManager = new EmployerManager();
EmployeeManager employeeManager = new EmployeeManager();

Employee emp1 = employeeManager.CreateEmployee("Emre", "Kurtar", 30, 10000);
Employee emp2 = employeeManager.CreateEmployee("Merve", "Kurtar", 25, 5000);
employeeManager.CreateEmployee("Fatma", "Kurtar", 20, 8000);
employeeManager.CreateEmployee("Can", "Kurtar", 19, 3000);

Employer patron = employerManager.CreateEmployer("Patron", "Patron", 45, "Yazılım Uzmanı");

employerManager.ChangeEmployeeSalary(employeeManager.EmployeeS, "Emre", 5000);
employerManager.ChangeEmployeeSalary(employeeManager.EmployeeS, "Merve","Kurtar", 1000);

Console.WriteLine(emp1.Salary);
Console.WriteLine(emp2.Salary);

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using OOPBasics.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OOPBasics.Services
{
public class EmployeeManager
{
public List<Employee> EmployeeS { get; set; }
public EmployeeManager()
{
EmployeeS = new List<Employee>();
}

public Employee CreateEmployee(string name, string surname, int age, int salary)
{
Employee newEmployee = new Employee(name, surname, age, salary);
EmployeeS.Add(newEmployee);
return newEmployee;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using OOPBasics.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OOPBasics.Services
{
public class EmployerManager
{
public List<Employer> Employers { get; set; }
public EmployerManager()
{
Employers = new List<Employer>();
}

public Employer CreateEmployer(string name,string surname,int age,string degree)
{
Employer newEmployer = new Employer(name, surname, age, degree);
Employers.Add(newEmployer);
return newEmployer;
}

public void ChangeEmployeeSalary(List<Employee> employeeList,string name,int newSalary)
{
if(employeeList != null)
{
foreach (var item in employeeList)
{
if (item.Name.Equals(name))
{
item.Salary = newSalary;
Console.WriteLine(name + " 'nin maaşı " + item.Salary + " olarak değişti");
}
}
}
}

// Polymorphism with overriding function
public void ChangeEmployeeSalary(List<Employee> employeeList, string name,string surname, int newSalary)
{
if (employeeList != null)
{
foreach (var item in employeeList)
{
if (item.Name.Equals(name) && item.Surname.Equals(surname))
{
item.Salary = newSalary;
Console.WriteLine(name + " 'nin maaşı " + item.Salary + " olarak değişti");
}
}
}
}


}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d8c246f9963cb322e902c2b11a1eeddf9f72d408
5160bbfeee8bdc461d5ac90c679ae5018a0d3363
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit d6bb49a

Please sign in to comment.