├── 01.Defining Classes - Exercise
├── Company Roster
│ ├── App.config
│ ├── Company Roster.csproj
│ ├── Employee.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── StartUp.cs
└── Oldest Family Member
│ ├── App.config
│ ├── Family.cs
│ ├── Oldest Family Member.csproj
│ ├── Person.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ └── StartUp.cs
├── 02.Encapsulation - Exercise
├── AnimalFarm
│ ├── AnimalFarm.csproj
│ ├── AnimalFarm.zip
│ ├── App.config
│ ├── Models
│ │ └── Chicken.cs
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── bin
│ │ └── Debug
│ │ │ ├── AnimalFarm.exe
│ │ │ ├── AnimalFarm.exe.config
│ │ │ └── AnimalFarm.pdb
│ └── obj
│ │ └── Debug
│ │ ├── AnimalFarm.csproj.FileListAbsolute.txt
│ │ ├── AnimalFarm.exe
│ │ ├── AnimalFarm.pdb
│ │ ├── CoreCompileInputs.cache
│ │ └── DesignTimeResolveAssemblyReferencesInput.cache
├── ClassBox
│ ├── App.config
│ ├── Box.cs
│ ├── ClassBox.csproj
│ ├── ClassBox.zip
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── bin
│ │ └── Debug
│ │ │ ├── ClassBox.exe
│ │ │ ├── ClassBox.exe.config
│ │ │ └── ClassBox.pdb
│ └── obj
│ │ └── Debug
│ │ ├── ClassBox.csproj.FileListAbsolute.txt
│ │ ├── ClassBox.csprojResolveAssemblyReference.cache
│ │ ├── ClassBox.exe
│ │ ├── ClassBox.pdb
│ │ ├── CoreCompileInputs.cache
│ │ └── DesignTimeResolveAssemblyReferencesInput.cache
└── ShoppingSpree
│ ├── App.config
│ ├── Person.cs
│ ├── Product.cs
│ ├── Program.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── ShoppingSpree.csproj
│ ├── ShoppingSpree.zip
│ ├── bin
│ └── Debug
│ │ ├── ShoppingSpree.exe
│ │ ├── ShoppingSpree.exe.config
│ │ └── ShoppingSpree.pdb
│ └── obj
│ └── Debug
│ ├── CoreCompileInputs.cache
│ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ ├── ShoppingSpree.csproj.FileListAbsolute.txt
│ ├── ShoppingSpree.csprojResolveAssemblyReference.cache
│ ├── ShoppingSpree.exe
│ └── ShoppingSpree.pdb
├── 03.Defining Classes & Encapsulation - Exercise
├── FamilyTree
│ ├── App.config
│ ├── FamilyTree.csproj
│ ├── Person.cs
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── bin
│ │ └── Debug
│ │ │ ├── FamilyTree.exe
│ │ │ ├── FamilyTree.exe.config
│ │ │ └── FamilyTree.pdb
│ └── obj
│ │ └── Debug
│ │ ├── CoreCompileInputs.cache
│ │ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ │ ├── FamilyTree.csproj.FileListAbsolute.txt
│ │ ├── FamilyTree.csprojResolveAssemblyReference.cache
│ │ ├── FamilyTree.exe
│ │ └── FamilyTree.pdb
├── Pizza
│ ├── App.config
│ ├── Dough.cs
│ ├── Pizza.cs
│ ├── Pizza.csproj
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Topping.cs
│ ├── bin
│ │ └── Debug
│ │ │ ├── Pizza.exe
│ │ │ ├── Pizza.exe.config
│ │ │ └── Pizza.pdb
│ └── obj
│ │ └── Debug
│ │ ├── CoreCompileInputs.cache
│ │ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ │ ├── Pizza.csproj.FileListAbsolute.txt
│ │ ├── Pizza.csprojResolveAssemblyReference.cache
│ │ ├── Pizza.exe
│ │ └── Pizza.pdb
└── Rectangle Intersection
│ ├── 09.Rectangle Intersection.csproj
│ ├── App.config
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── Rectangle.cs
│ ├── StartUp.cs
│ ├── bin
│ └── Debug
│ │ ├── 09.Rectangle Intersection.exe
│ │ ├── 09.Rectangle Intersection.exe.config
│ │ └── 09.Rectangle Intersection.pdb
│ └── obj
│ └── Debug
│ ├── 09.Rectangle Intersection.csproj.FileListAbsolute.txt
│ ├── 09.Rectangle Intersection.csprojResolveAssemblyReference.cache
│ ├── 09.Rectangle Intersection.exe
│ ├── 09.Rectangle Intersection.pdb
│ ├── CoreCompileInputs.cache
│ └── DesignTimeResolveAssemblyReferencesInput.cache
├── 04.Inheritance - Exercise
├── Mankind
│ ├── App.config
│ ├── Human.cs
│ ├── Mankind.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Startup.cs
│ ├── Student.cs
│ └── Worker.cs
└── Person
│ ├── App.config
│ ├── Child.cs
│ ├── Person.cs
│ ├── Person.csproj
│ ├── Properties
│ └── AssemblyInfo.cs
│ └── Startup.cs
├── 05.Polymorphism - Exercise
├── 01.Vehicles
│ ├── App.config
│ ├── Car.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Startup.cs
│ ├── Truck.cs
│ ├── Vehicle.cs
│ └── Vehicles.csproj
└── 02.Vehicles Extension
│ ├── App.config
│ ├── Models
│ ├── Bus.cs
│ ├── Car.cs
│ ├── Truck.cs
│ └── Vehicle.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── Startup.cs
│ └── Vehicles.csproj
├── 06.Inheritance & Polymorphism - Exercise
├── MordorsCrueltyPlan
│ ├── App.config
│ ├── Factories
│ │ ├── FoodFactory.cs
│ │ └── MoodFactory.cs
│ ├── Models
│ │ ├── Food.cs
│ │ ├── Foods
│ │ │ ├── Apple.cs
│ │ │ ├── Cram.cs
│ │ │ ├── HoneyCake.cs
│ │ │ ├── Junk.cs
│ │ │ ├── Lembas.cs
│ │ │ ├── Melon.cs
│ │ │ └── Mushrooms.cs
│ │ ├── Gandalf.cs
│ │ ├── Mood.cs
│ │ └── Moods
│ │ │ ├── Angry.cs
│ │ │ ├── Happy.cs
│ │ │ ├── JavaScript.cs
│ │ │ └── Sad.cs
│ ├── MordorsCrueltyPlan.csproj
│ ├── Program.cs
│ └── Properties
│ │ └── AssemblyInfo.cs
└── WildFarm
│ ├── App.config
│ ├── Factories
│ ├── AnimalFactory.cs
│ └── FoodFactory.cs
│ ├── Models
│ ├── Animal.cs
│ ├── Animals
│ │ ├── Cat.cs
│ │ ├── Mouse.cs
│ │ ├── Tiger.cs
│ │ └── Zebra.cs
│ ├── Felime.cs
│ ├── Food.cs
│ ├── Foods
│ │ ├── Meat.cs
│ │ └── Vegetable.cs
│ └── Mammal.cs
│ ├── Program.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ └── WildFarm.csproj
├── ExamPrepLiveDemo
├── ExamPrepLiveDemo.sln
└── NFS
│ ├── App.config
│ ├── ClassDiagram1.cd
│ ├── Core
│ ├── CarManager.cs
│ └── Engine.cs
│ ├── Entities
│ ├── Cars
│ │ ├── Car.cs
│ │ ├── PerformanceCar.cs
│ │ └── ShowCar.cs
│ ├── Garage.cs
│ └── Races
│ │ ├── CasualRace.cs
│ │ ├── DragRace.cs
│ │ ├── DriftRace.cs
│ │ └── Race.cs
│ ├── NFS.csproj
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── StartUp.cs
│ ├── Utilities
│ └── Constants.cs
│ ├── bin
│ └── Debug
│ │ ├── NFS.exe
│ │ ├── NFS.exe.config
│ │ ├── NFS.pdb
│ │ └── nunit_random_seed.tmp
│ └── obj
│ └── Debug
│ ├── CoreCompileInputs.cache
│ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ ├── NFS.csproj.FileListAbsolute.txt
│ ├── NFS.csprojResolveAssemblyReference.cache
│ ├── NFS.exe
│ └── NFS.pdb
├── LICENSE
├── Live
├── AvatarLiveDemo
│ ├── App.config
│ ├── AvatarLiveDemo.csproj
│ ├── Core
│ │ ├── Engine.cs
│ │ └── NationsBuilder.cs
│ ├── Entities
│ │ ├── Benders
│ │ │ ├── AirBender.cs
│ │ │ ├── Bender.cs
│ │ │ ├── EarthBender.cs
│ │ │ ├── FireBender.cs
│ │ │ └── WaterBender.cs
│ │ ├── Monuments
│ │ │ ├── AirMonument.cs
│ │ │ ├── EarthMonument.cs
│ │ │ ├── FireMonument.cs
│ │ │ ├── Monument.cs
│ │ │ └── WaterMonument.cs
│ │ └── Nation.cs
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── bin
│ │ └── Debug
│ │ │ ├── AvatarLiveDemo.exe
│ │ │ ├── AvatarLiveDemo.exe.config
│ │ │ └── AvatarLiveDemo.pdb
│ └── obj
│ │ └── Debug
│ │ ├── AvatarLiveDemo.csproj.FileListAbsolute.txt
│ │ ├── AvatarLiveDemo.csprojResolveAssemblyReference.cache
│ │ ├── AvatarLiveDemo.exe
│ │ ├── AvatarLiveDemo.pdb
│ │ ├── CoreCompileInputs.cache
│ │ └── DesignTimeResolveAssemblyReferencesInput.cache
└── Live.sln
└── NeedForSpeed
├── App.config
├── Core
├── CarManager.cs
└── Engine.cs
├── Entities
├── Cars
│ ├── Car.cs
│ ├── PerformanceCar.cs
│ └── ShowCar.cs
├── Essentials
│ └── Garage.cs
└── Races
│ ├── NormalRaces
│ ├── CasualRace.cs
│ ├── CircuitRace.cs
│ ├── DragRace.cs
│ ├── DriftRace.cs
│ └── NormalRace.cs
│ ├── Race.cs
│ └── SpecialRaces
│ └── TimeLimitRace.cs
├── Factories
├── CarFactory.cs
└── RaceFactory.cs
├── IO
├── ConsoleReader.cs
└── ConsoleWriter.cs
├── NeedForSpeed.csproj
├── Properties
└── AssemblyInfo.cs
├── StartUp.cs
├── Tests
├── Bonus
│ ├── Bonus.zip
│ ├── test.000.001.in.txt
│ ├── test.000.001.out.txt
│ ├── test.000.002.in.txt
│ ├── test.000.002.out.txt
│ ├── test.001.in.txt
│ ├── test.001.out.txt
│ ├── test.002.in.txt
│ └── test.002.out.txt
├── BuisnessLogic
│ ├── BuisnessLogic.zip
│ ├── test.000.001.in.txt
│ ├── test.000.001.out.txt
│ ├── test.000.002.in.txt
│ ├── test.000.002.out.txt
│ ├── test.000.003.in.txt
│ ├── test.000.003.out.txt
│ ├── test.001.in.txt
│ ├── test.001.out.txt
│ ├── test.002.in.txt
│ ├── test.002.out.txt
│ ├── test.003.in.txt
│ ├── test.003.out.txt
│ ├── test.004.in.txt
│ ├── test.004.out.txt
│ ├── test.005.in.txt
│ └── test.005.out.txt
├── IO
│ ├── IO.zip
│ ├── test.000.001.in.txt
│ ├── test.000.001.out.txt
│ ├── test.000.002.in.txt
│ ├── test.000.002.out.txt
│ ├── test.001.in.txt
│ ├── test.001.out.txt
│ ├── test.002.in.txt
│ ├── test.002.out.txt
│ ├── test.003.in.txt
│ ├── test.003.out.txt
│ ├── test.004.in.txt
│ └── test.004.out.txt
└── Structure
│ ├── Structure.zip
│ ├── test.000.001.in.txt
│ ├── test.000.001.out.txt
│ ├── test.000.002.in.txt
│ ├── test.000.002.out.txt
│ ├── test.000.003.in.txt
│ ├── test.000.003.out.txt
│ ├── test.001.in.txt
│ ├── test.001.out.txt
│ ├── test.002.in.txt
│ ├── test.002.out.txt
│ ├── test.003.in.txt
│ ├── test.003.out.txt
│ ├── test.004.in.txt
│ ├── test.004.out.txt
│ ├── test.005.in.txt
│ └── test.005.out.txt
└── Utilities
├── Constants.cs
└── InputParser.cs
/01.Defining Classes - Exercise/Company Roster/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/01.Defining Classes - Exercise/Company Roster/Company Roster.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {5D41AB2E-0F1E-4EC1-9BA3-5C276F296FFE}
8 | Exe
9 | Company_Roster
10 | Company Roster
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/01.Defining Classes - Exercise/Company Roster/Employee.cs:
--------------------------------------------------------------------------------
1 | namespace CompanyRoster
2 | {
3 | public class Employee
4 | {
5 | private string name;
6 | private decimal salary;
7 | private string position;
8 | private string department;
9 | private string email;
10 | private int age;
11 |
12 | public Employee(string name, decimal salary, string position, string department)
13 | {
14 | this.name = name;
15 | this.salary = salary;
16 | this.position = position;
17 | this.department = department;
18 | this.age = -1;
19 | this.email = "n/a";
20 | }
21 |
22 | public int Age
23 | {
24 | set { this.age = value; }
25 | }
26 |
27 | public string Email
28 | {
29 | set { this.email = value; }
30 | }
31 |
32 | public string Department { get { return this.department; } }
33 |
34 | public decimal Salary { get { return this.salary; } }
35 |
36 | //public Employee(string name, decimal salary, string position, string department, int age) : this(name, salary, position, department)
37 | //{
38 | // this.age = age;
39 | //}
40 |
41 | //public Employee(string name, decimal salary, string position, string department, string email) : this(name, salary, position, department)
42 | //{
43 | // this.email = email;
44 | //}
45 |
46 | public string PrintEmployeeInfo()
47 | {
48 | return $"{this.name} {this.salary:f2} {this.email} {this.age}";
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/01.Defining Classes - Exercise/Company Roster/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Company Roster")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Company Roster")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("5d41ab2e-0f1e-4ec1-9ba3-5c276f296ffe")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/01.Defining Classes - Exercise/Company Roster/StartUp.cs:
--------------------------------------------------------------------------------
1 | namespace CompanyRoster
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 |
7 | public class StartUp
8 | {
9 | public static void Main()
10 | {
11 | var numberOfEmployees = int.Parse(Console.ReadLine());
12 | var employees = new List();
13 |
14 | for (int i = 0; i < numberOfEmployees; i++)
15 | {
16 | var employeeInfo = Console.ReadLine().Split(' ');
17 |
18 | var employee = new Employee(
19 | employeeInfo[0],
20 | decimal.Parse(employeeInfo[1]),
21 | employeeInfo[2],
22 | employeeInfo[3]);
23 |
24 | if (employeeInfo.Length > 4)
25 | {
26 | if (int.TryParse(employeeInfo[4], out int age))
27 | {
28 | employee.Age = age;
29 | }
30 | else
31 | {
32 | employee.Email = employeeInfo[4];
33 | }
34 | }
35 |
36 | if (employeeInfo.Length > 5)
37 | {
38 | employee.Age = int.Parse(employeeInfo[5]);
39 | }
40 |
41 | employees.Add(employee);
42 | }
43 |
44 | var departments = employees
45 | .GroupBy(em => em.Department)
46 | .Select(gr => new
47 | {
48 | Name = gr.Key,
49 | AverageSalary = gr.Average(em => em.Salary),
50 | Employees = gr
51 | })
52 | .OrderByDescending(gr => gr.AverageSalary)
53 | .FirstOrDefault();
54 |
55 | Console.WriteLine($"Highest Average Salary: {departments.Name}");
56 | foreach (var emp in departments.Employees.OrderByDescending(em => em.Salary))
57 | {
58 | Console.WriteLine(emp.PrintEmployeeInfo());
59 | }
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/01.Defining Classes - Exercise/Oldest Family Member/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/01.Defining Classes - Exercise/Oldest Family Member/Family.cs:
--------------------------------------------------------------------------------
1 | namespace OldestFamilyMember
2 | {
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | public class Family
6 | {
7 | private List members;
8 |
9 | public Family()
10 | {
11 | this.members = new List();
12 | }
13 | public void AddMember(Person member)
14 | {
15 | this.members.Add(member);
16 | }
17 |
18 | public Person GetOldestMember()
19 | {
20 | return this.members
21 | .OrderByDescending(p => p.Age)
22 | .FirstOrDefault();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/01.Defining Classes - Exercise/Oldest Family Member/Person.cs:
--------------------------------------------------------------------------------
1 | namespace OldestFamilyMember
2 | {
3 | public class Person
4 | {
5 | private string name;
6 | private int age;
7 |
8 | public Person(string name, int age)
9 | {
10 | this.name = name;
11 | this.age = age;
12 | }
13 |
14 | public int Age
15 | {
16 | get { return this.age; }
17 | }
18 |
19 | public string Name
20 | {
21 | get { return this.name; }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/01.Defining Classes - Exercise/Oldest Family Member/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Oldest Family Member")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Oldest Family Member")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("47f1b375-704f-4732-8451-49ab7ffb9b00")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/01.Defining Classes - Exercise/Oldest Family Member/StartUp.cs:
--------------------------------------------------------------------------------
1 | namespace OldestFamilyMember
2 | {
3 | using System;
4 | public class StartUp
5 | {
6 | public static void Main(string[] args)
7 | {
8 | var numberOfPeople = int.Parse(Console.ReadLine());
9 | var family = new Family();
10 |
11 | for (int i = 0; i < numberOfPeople; i++)
12 | {
13 | var personInfo = Console.ReadLine().Split(' ');
14 | var personName = personInfo[0];
15 | var personAge = int.Parse(personInfo[1]);
16 |
17 | var person = new Person(personName, personAge);
18 | family.AddMember(person);
19 | }
20 |
21 | var oldestPerson = family.GetOldestMember();
22 | Console.WriteLine($"{oldestPerson.Name} {oldestPerson.Age}");
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/AnimalFarm/AnimalFarm.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/AnimalFarm/AnimalFarm.zip
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/AnimalFarm/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/AnimalFarm/Models/Chicken.cs:
--------------------------------------------------------------------------------
1 | namespace AnimalFarm.Models
2 | {
3 | using System;
4 |
5 | public class Chicken
6 | {
7 | private const int MinAge = 0;
8 | private const int MaxAge = 15;
9 |
10 | private string name;
11 | private int age;
12 |
13 | public Chicken(string name, int age)
14 | {
15 | this.Name = name;
16 | this.Age = age;
17 | }
18 |
19 | public string Name
20 | {
21 | get
22 | {
23 | return this.name;
24 | }
25 |
26 | internal set
27 | {
28 | if (string.IsNullOrWhiteSpace(value))
29 | {
30 | throw new ArgumentException($"{nameof(Name)} cannot be empty.");
31 | }
32 |
33 | this.name = value;
34 | }
35 | }
36 |
37 | public int Age
38 | {
39 | get
40 | {
41 | return this.age;
42 | }
43 |
44 | internal set
45 | {
46 | if (value < MinAge || value > MaxAge)
47 | {
48 | throw new ArgumentException($"{nameof(Age)} should be between 0 and 15.");
49 | }
50 |
51 | this.age = value;
52 | }
53 | }
54 |
55 | public double GetProductPerDay()
56 | {
57 | return this.CalculateProductPerDay();
58 | }
59 |
60 | private double CalculateProductPerDay()
61 | {
62 | switch (this.Age)
63 | {
64 | case 0:
65 | case 1:
66 | case 2:
67 | case 3:
68 | return 1.5;
69 | case 4:
70 | case 5:
71 | case 6:
72 | case 7:
73 | return 2;
74 | case 8:
75 | case 9:
76 | case 10:
77 | case 11:
78 | return 1;
79 | default:
80 | return 0.75;
81 | }
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/AnimalFarm/Program.cs:
--------------------------------------------------------------------------------
1 | namespace P03_AnimalFarm
2 | {
3 | using System;
4 | using System.Diagnostics;
5 | using System.Linq;
6 | using System.Reflection;
7 | using AnimalFarm.Models;
8 |
9 | public class Program
10 | {
11 | public static void Main(string[] args)
12 | {
13 | Type chickenType = typeof(Chicken);
14 | FieldInfo[] fields = chickenType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
15 | MethodInfo[] methods = chickenType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
16 | Debug.Assert(fields.Where(f => f.IsPrivate).Count() == 2);
17 | Debug.Assert(methods.Where(m => m.IsPrivate).Count() == 1);
18 |
19 | string name = Console.ReadLine();
20 | int age = int.Parse(Console.ReadLine());
21 |
22 | try
23 | {
24 | Chicken chicken = new Chicken(name, age);
25 | Console.WriteLine(
26 | "Chicken {0} (age {1}) can produce {2} eggs per day.",
27 | chicken.Name,
28 | chicken.Age,
29 | chicken.GetProductPerDay());
30 | }
31 | catch (Exception e)
32 | {
33 | Console.WriteLine(e.Message);
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/AnimalFarm/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("AnimalFarm")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("AnimalFarm")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("32aec171-3440-43ed-822b-e7f89c5a8651")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/AnimalFarm/bin/Debug/AnimalFarm.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/AnimalFarm/bin/Debug/AnimalFarm.exe
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/AnimalFarm/bin/Debug/AnimalFarm.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/AnimalFarm/bin/Debug/AnimalFarm.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/AnimalFarm/bin/Debug/AnimalFarm.pdb
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/AnimalFarm/obj/Debug/AnimalFarm.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\AnimalFarm\bin\Debug\AnimalFarm.exe.config
2 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\AnimalFarm\bin\Debug\AnimalFarm.exe
3 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\AnimalFarm\bin\Debug\AnimalFarm.pdb
4 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\AnimalFarm\obj\Debug\AnimalFarm.exe
5 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\AnimalFarm\obj\Debug\AnimalFarm.pdb
6 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/AnimalFarm/obj/Debug/AnimalFarm.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/AnimalFarm/obj/Debug/AnimalFarm.exe
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/AnimalFarm/obj/Debug/AnimalFarm.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/AnimalFarm/obj/Debug/AnimalFarm.pdb
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/AnimalFarm/obj/Debug/CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 4fa61a6a2a2717e2e2f369cd900efb6eefa8be5c
2 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/AnimalFarm/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/AnimalFarm/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/Box.cs:
--------------------------------------------------------------------------------
1 | namespace ClassBox
2 | {
3 | using System;
4 |
5 | public class Box
6 | {
7 | private double length;
8 | private double width;
9 | private double height;
10 |
11 | public Box(double length, double width, double height)
12 | {
13 | this.Length = length;
14 | this.Width = width;
15 | this.Height = height;
16 | }
17 |
18 | private double Length
19 | {
20 | set
21 | {
22 | if (value <= 0)
23 | {
24 | throw new ArgumentException($"{nameof(Length)} cannot be zero or negative.");
25 | }
26 |
27 | this.length = value;
28 | }
29 | }
30 |
31 | private double Width
32 | {
33 | set
34 | {
35 | if (value <= 0)
36 | {
37 | throw new ArgumentException($"{nameof(Width)} cannot be zero or negative.");
38 | }
39 |
40 | this.width = value;
41 | }
42 | }
43 |
44 | private double Height
45 | {
46 | set
47 | {
48 | if (value <= 0)
49 | {
50 | throw new ArgumentException($"{nameof(Height)} cannot be zero or negative.");
51 | }
52 | this.height = value;
53 | }
54 | }
55 |
56 | public double GetSurfaceArea()
57 | {
58 | return 2 * this.length * this.width + 2 * this.length * this.height + 2 * this.width * this.height;
59 | }
60 |
61 | public double GetLateralSurfaceArea()
62 | {
63 | return 2 * this.length * this.height + 2 * this.width * this.height;
64 | }
65 |
66 | public double GetVolume()
67 | {
68 | return this.length * this.height * this.width;
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/ClassBox.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {C08A346E-88BB-4BFE-A9E9-B35A663345E0}
8 | Exe
9 | ClassBox
10 | ClassBox
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/ClassBox.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ClassBox/ClassBox.zip
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/Program.cs:
--------------------------------------------------------------------------------
1 | namespace ClassBox
2 | {
3 | using System;
4 | using System.Linq;
5 | using System.Reflection;
6 |
7 | public class Program
8 | {
9 | public static void Main()
10 | {
11 | Type boxType = typeof(Box);
12 | FieldInfo[] fields = boxType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
13 | Console.WriteLine(fields.Count());
14 |
15 | try
16 | {
17 | var boxParams = new double[3];
18 | for (int i = 0; i < boxParams.Length; i++)
19 | {
20 | boxParams[i] = double.Parse(Console.ReadLine());
21 | }
22 |
23 | var box = new Box(boxParams[0], boxParams[1], boxParams[2]);
24 |
25 | Console.WriteLine($"Surface Area - {box.GetSurfaceArea():f2}");
26 | Console.WriteLine($"Lateral Surface Area - {box.GetLateralSurfaceArea():f2}");
27 | Console.WriteLine($"Volume - {box.GetVolume():f2}");
28 | }
29 | catch (Exception e)
30 | {
31 | Console.WriteLine(e.Message);
32 | }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ClassBox")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ClassBox")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("c08a346e-88bb-4bfe-a9e9-b35a663345e0")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/bin/Debug/ClassBox.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ClassBox/bin/Debug/ClassBox.exe
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/bin/Debug/ClassBox.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/bin/Debug/ClassBox.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ClassBox/bin/Debug/ClassBox.pdb
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/obj/Debug/ClassBox.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\ClassBox\bin\Debug\ClassBox.exe.config
2 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\ClassBox\bin\Debug\ClassBox.exe
3 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\ClassBox\bin\Debug\ClassBox.pdb
4 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\ClassBox\obj\Debug\ClassBox.csprojResolveAssemblyReference.cache
5 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\ClassBox\obj\Debug\ClassBox.exe
6 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\ClassBox\obj\Debug\ClassBox.pdb
7 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/obj/Debug/ClassBox.csprojResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ClassBox/obj/Debug/ClassBox.csprojResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/obj/Debug/ClassBox.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ClassBox/obj/Debug/ClassBox.exe
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/obj/Debug/ClassBox.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ClassBox/obj/Debug/ClassBox.pdb
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/obj/Debug/CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 38424be911c816719024a6441263a9d78d2af9f6
2 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ClassBox/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ClassBox/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/Person.cs:
--------------------------------------------------------------------------------
1 | namespace ShoppingSpree
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | public class Person
7 | {
8 | private string name;
9 | private decimal money;
10 | private List bag;
11 |
12 | public Person(string name, decimal money)
13 | {
14 | this.Name = name;
15 | this.Money = money;
16 | this.bag = new List();
17 | }
18 |
19 | public decimal Money
20 | {
21 | get { return this.money; }
22 | set
23 | {
24 | if (value < 0)
25 | {
26 | throw new ArgumentException($"{nameof(Money)} cannot be negative");
27 | }
28 | this.money = value;
29 | }
30 | }
31 |
32 |
33 | public string Name
34 | {
35 | get { return this.name; }
36 | set
37 | {
38 | if (string.IsNullOrWhiteSpace(value))
39 | {
40 | throw new ArgumentException($"{nameof(Name)} cannot be empty");
41 | }
42 | this.name = value;
43 | }
44 | }
45 |
46 | public void BuyProduct(Product product)
47 | {
48 | if (this.Money < product.Price)
49 | {
50 | throw new InvalidOperationException($"{this.Name} can't afford {product.Name}");
51 | }
52 |
53 | this.bag.Add(product);
54 | this.Money -= product.Price;
55 | }
56 |
57 | public IList GetProducts()
58 | {
59 | return this.bag.AsReadOnly();
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/Product.cs:
--------------------------------------------------------------------------------
1 | namespace ShoppingSpree
2 | {
3 | using System;
4 |
5 | public class Product
6 | {
7 | private string name;
8 | private decimal price;
9 |
10 | public Product(string name, decimal price)
11 | {
12 | this.Name = name;
13 | this.Price = price;
14 | }
15 | public decimal Price
16 | {
17 | get { return this.price; }
18 | set
19 | {
20 | if (value < 0)
21 | {
22 | throw new ArgumentException($"Money cannot be negative");
23 | }
24 | this.price = value;
25 | }
26 | }
27 |
28 |
29 | public string Name
30 | {
31 | get { return this.name; }
32 | set
33 | {
34 | if (string.IsNullOrWhiteSpace(value))
35 | {
36 | throw new ArgumentException($"{nameof(Name)} cannot be empty");
37 | }
38 | this.name = value;
39 | }
40 | }
41 |
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ShoppingSpree")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ShoppingSpree")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("6247183c-3aca-4881-982b-c99a4a40945d")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/ShoppingSpree.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ShoppingSpree/ShoppingSpree.zip
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/bin/Debug/ShoppingSpree.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ShoppingSpree/bin/Debug/ShoppingSpree.exe
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/bin/Debug/ShoppingSpree.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/bin/Debug/ShoppingSpree.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ShoppingSpree/bin/Debug/ShoppingSpree.pdb
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/obj/Debug/CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | a958aeed344de4005b925871708ee13f8e7c687d
2 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ShoppingSpree/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/obj/Debug/ShoppingSpree.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\ShoppingSpree\bin\Debug\ShoppingSpree.exe.config
2 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\ShoppingSpree\bin\Debug\ShoppingSpree.exe
3 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\ShoppingSpree\bin\Debug\ShoppingSpree.pdb
4 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\ShoppingSpree\obj\Debug\ShoppingSpree.csprojResolveAssemblyReference.cache
5 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\ShoppingSpree\obj\Debug\ShoppingSpree.exe
6 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\ShoppingSpree\obj\Debug\ShoppingSpree.pdb
7 |
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/obj/Debug/ShoppingSpree.csprojResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ShoppingSpree/obj/Debug/ShoppingSpree.csprojResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/obj/Debug/ShoppingSpree.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ShoppingSpree/obj/Debug/ShoppingSpree.exe
--------------------------------------------------------------------------------
/02.Encapsulation - Exercise/ShoppingSpree/obj/Debug/ShoppingSpree.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/02.Encapsulation - Exercise/ShoppingSpree/obj/Debug/ShoppingSpree.pdb
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/FamilyTree/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/FamilyTree/FamilyTree.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {B010D627-84A9-4009-97DC-19DC67FFF48F}
8 | Exe
9 | FamilyTree
10 | FamilyTree
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/FamilyTree/Person.cs:
--------------------------------------------------------------------------------
1 | namespace FamilyTree
2 | {
3 | using System.Collections.Generic;
4 | using System.Linq;
5 |
6 | public class Person
7 | {
8 | private List children;
9 |
10 | public Person()
11 | {
12 | this.children = new List();
13 | }
14 |
15 | public Person(string name, string date) : this()
16 | {
17 | this.Name = name;
18 | this.BirthDate = date;
19 | }
20 |
21 | public string Name { get; set; }
22 | public string BirthDate { get; set; }
23 |
24 | public IReadOnlyList Children
25 | {
26 | get { return this.children.AsReadOnly(); }
27 | }
28 | public void AddChild(Person child)
29 | {
30 | this.children.Add(child);
31 | }
32 |
33 | public void AddChildrenInfo(string name, string date)
34 | {
35 | if (this.children.FirstOrDefault(c => c.Name == name) != null)
36 | {
37 | this.children.FirstOrDefault(c => c.Name == name).BirthDate = date;
38 | return;
39 | }
40 | if (this.children.FirstOrDefault(c => c.BirthDate == date) != null)
41 | {
42 | this.children.FirstOrDefault(c => c.BirthDate == date).Name = name;
43 | }
44 | }
45 |
46 | public Person FindChildName(string childName)
47 | {
48 | return this.children.FirstOrDefault(c => c.Name == childName);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/FamilyTree/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("FamilyTree")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("FamilyTree")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("b010d627-84a9-4009-97dc-19dc67fff48f")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/FamilyTree/bin/Debug/FamilyTree.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/FamilyTree/bin/Debug/FamilyTree.exe
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/FamilyTree/bin/Debug/FamilyTree.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/FamilyTree/bin/Debug/FamilyTree.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/FamilyTree/bin/Debug/FamilyTree.pdb
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/FamilyTree/obj/Debug/CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 165c2eed13097d0333c10e0b08a15bad720809ea
2 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/FamilyTree/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/FamilyTree/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/FamilyTree/obj/Debug/FamilyTree.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\FamilyTree\bin\Debug\FamilyTree.exe.config
2 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\FamilyTree\bin\Debug\FamilyTree.exe
3 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\FamilyTree\bin\Debug\FamilyTree.pdb
4 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\FamilyTree\obj\Debug\FamilyTree.csprojResolveAssemblyReference.cache
5 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\FamilyTree\obj\Debug\FamilyTree.exe
6 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\FamilyTree\obj\Debug\FamilyTree.pdb
7 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/FamilyTree/obj/Debug/FamilyTree.csprojResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/FamilyTree/obj/Debug/FamilyTree.csprojResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/FamilyTree/obj/Debug/FamilyTree.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/FamilyTree/obj/Debug/FamilyTree.exe
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/FamilyTree/obj/Debug/FamilyTree.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/FamilyTree/obj/Debug/FamilyTree.pdb
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/Pizza.cs:
--------------------------------------------------------------------------------
1 | namespace Pizza
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 |
7 | public class Pizza
8 | {
9 | private string name;
10 | private Dough dough;
11 | private List toppings;
12 | private int numberOfToppings;
13 |
14 | public Pizza(string name, int numberOfToppings)
15 | {
16 | this.Name = name;
17 | this.toppings = new List();
18 | this.NumberOfToppings = numberOfToppings;
19 | }
20 |
21 | public Dough Dough
22 | {
23 | //FIX set { this.Dough = value; } - ends up in recurcive call
24 | set { this.dough = value; }
25 | }
26 | public int NumberOfToppings
27 | {
28 | get { return this.numberOfToppings; }
29 | set
30 | {
31 | if (value < 0 || value > 10)
32 | {
33 | throw new ArgumentException("Number of toppings should be in range [0..10].");
34 | }
35 | this.numberOfToppings = value;
36 | }
37 | }
38 |
39 |
40 | public string Name
41 | {
42 | get { return this.name; }
43 | set {
44 | if (value.Length < 1 || value.Length > 15)
45 | {
46 | throw new ArgumentException("Pizza name should be between 1 and 15 symbols.");
47 | }
48 |
49 | this.name = value; }
50 | }
51 |
52 | public void AddTopping(Topping topping)
53 | {
54 | this.toppings.Add(topping);
55 | }
56 |
57 | public double GetCalories()
58 | {
59 | return this.dough.GetCalories() + this.toppings.Sum(t => t.GetCalories());
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/Program.cs:
--------------------------------------------------------------------------------
1 | namespace Pizza
2 | {
3 | using System;
4 |
5 | public class Program
6 | {
7 | public static void Main()
8 | {
9 | string inputLine;
10 | while ((inputLine = Console.ReadLine()) != "END")
11 | {
12 | var tokens = inputLine.Split(' ');
13 | try
14 | {
15 | switch (tokens[0])
16 | {
17 | case "Dough":
18 | var dough = new Dough(tokens[1], tokens[2], double.Parse(tokens[3]));
19 | Console.WriteLine($"{dough.GetCalories():f2}");
20 | break;
21 | case "Topping":
22 | var topping = new Topping(tokens[1], double.Parse(tokens[2]));
23 | Console.WriteLine($"{topping.GetCalories():f2}");
24 | break;
25 | case "Pizza":
26 | MakePizza(tokens);
27 | break;
28 | }
29 | }
30 | catch (Exception e)
31 | {
32 | Console.WriteLine(e.Message);
33 | return;
34 | }
35 | }
36 | }
37 |
38 | public static void MakePizza(string[] tokens)
39 | {
40 | var numberToppings = int.Parse(tokens[2]);
41 | var pizza = new Pizza(tokens[1], numberToppings);
42 | var doughInfo = Console.ReadLine().Split(' ');
43 | var dough = new Dough(doughInfo[1], doughInfo[2], double.Parse(doughInfo[3]));
44 | pizza.Dough = dough;
45 |
46 | for (var i = 0; i < numberToppings; i++)
47 | {
48 | var topInfo = Console.ReadLine().Split(' ');
49 | var topping = new Topping(topInfo[1], double.Parse(topInfo[2]));
50 | pizza.AddTopping(topping);
51 | }
52 |
53 | Console.WriteLine($"{pizza.Name} - {pizza.GetCalories():f2} Calories.");
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Pizza")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Pizza")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("48b18329-2585-4b19-9d6d-ca1e5123f303")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/Topping.cs:
--------------------------------------------------------------------------------
1 | namespace Pizza
2 | {
3 | using System;
4 |
5 | public class Topping
6 | {
7 | private string type;
8 | private double weight;
9 |
10 | private const int MinWeight = 1;
11 | private const int MaxWeight = 50;
12 |
13 | public Topping(string type, double weight)
14 | {
15 | this.Type = type;
16 | this.Weight = weight;
17 | }
18 | public double Weight
19 | {
20 | get { return this.weight; }
21 | set
22 | {
23 | if (value < MinWeight || value > MaxWeight)
24 | {
25 | throw new ArgumentException($"{this.Type} weight should be in the range [1..50].");
26 | }
27 | this.weight = value;
28 | }
29 | }
30 |
31 |
32 | public string Type
33 | {
34 | get { return this.type; }
35 | set
36 | {
37 | if (value.ToLower() != "meat" && value.ToLower() != "veggies" && value.ToLower() != "sauce" && value.ToLower() != "cheese")
38 | {
39 | throw new ArgumentException($"Cannot place {value} on top of your pizza.");
40 | }
41 | this.type = value;
42 | }
43 | }
44 |
45 | public double GetCalories()
46 | {
47 | return 2 * Weight * this.GetTypeMod();
48 | }
49 |
50 | private double GetTypeMod()
51 | {
52 | if (this.Type.ToLower() == "meat")
53 | {
54 | return 1.2;
55 | }
56 | else if (this.Type.ToLower() == "veggies")
57 | {
58 | return 0.8;
59 | }
60 | else if (this.Type.ToLower() == "cheese")
61 | {
62 | return 1.1;
63 | }
64 |
65 | return 0.9;
66 | }
67 |
68 |
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/bin/Debug/Pizza.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/Pizza/bin/Debug/Pizza.exe
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/bin/Debug/Pizza.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/bin/Debug/Pizza.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/Pizza/bin/Debug/Pizza.pdb
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/obj/Debug/CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 1d6155360d368692e5b1f62cbc33ae9174297d00
2 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/Pizza/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/obj/Debug/Pizza.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\Pizza\bin\Debug\Pizza.exe.config
2 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\Pizza\bin\Debug\Pizza.exe
3 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\Pizza\bin\Debug\Pizza.pdb
4 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\Pizza\obj\Debug\Pizza.csprojResolveAssemblyReference.cache
5 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\Pizza\obj\Debug\Pizza.exe
6 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\02.Encapsulation\Pizza\obj\Debug\Pizza.pdb
7 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/obj/Debug/Pizza.csprojResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/Pizza/obj/Debug/Pizza.csprojResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/obj/Debug/Pizza.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/Pizza/obj/Debug/Pizza.exe
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Pizza/obj/Debug/Pizza.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/Pizza/obj/Debug/Pizza.pdb
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("09.Rectangle Intersection")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("09.Rectangle Intersection")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("a30327e9-9763-4e43-bb73-f91e02d90f0a")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/Rectangle.cs:
--------------------------------------------------------------------------------
1 | namespace RectangleIntersection
2 | {
3 | public class Rectangle
4 | {
5 | private string id;
6 | private double width;
7 | private double height;
8 | private double x;
9 | private double y;
10 | public Rectangle(string id, double width, double height, double topLeftHoriz, double topLeftVert)
11 | {
12 | this.id = id;
13 | this.width = width;
14 | this.height = height;
15 | this.x = topLeftHoriz;
16 | this.y = topLeftVert;
17 | }
18 | public double Height
19 | {
20 | get { return this.height; }
21 | }
22 | public double Width
23 | {
24 | get { return this.width; }
25 | }
26 | public double X
27 | {
28 | get { return this.x; }
29 | }
30 | public double Y
31 | {
32 | get { return this.y; }
33 | }
34 |
35 |
36 |
37 | public bool InteresectsWith(Rectangle rectangle)
38 | {
39 | if (this.x <= rectangle.x + rectangle.width && this.x + this.width >= rectangle.x && this.y <= rectangle.y + rectangle.height && this.y + this.height >= rectangle.y)
40 | {
41 | return true;
42 | }
43 |
44 | return false;
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/StartUp.cs:
--------------------------------------------------------------------------------
1 | namespace RectangleIntersection
2 | {
3 | using System;
4 | using System.Linq;
5 | using System.Collections.Generic;
6 |
7 |
8 | public class StartUp
9 | {
10 | public static void Main()
11 | {
12 |
13 | var rectangles = new Dictionary();
14 | var inputInfo = Console.ReadLine()
15 | .Split(' ')
16 | .Select(int.Parse)
17 | .ToArray();
18 |
19 | for (int i = 0; i < inputInfo[0]; i++)
20 | {
21 | var rectangleInfo = Console.ReadLine().Split(' ');
22 | var id = rectangleInfo[0];
23 | var width = double.Parse(rectangleInfo[1]);
24 | var height = double.Parse(rectangleInfo[2]);
25 | var topLeftHoriz = double.Parse(rectangleInfo[3]);
26 | var topLeftVert = double.Parse(rectangleInfo[4]);
27 |
28 | var rectangle = new Rectangle(id, width, height, topLeftHoriz, topLeftVert);
29 | rectangles[id] = rectangle;
30 | }
31 |
32 | for (int i = 0; i < inputInfo[1]; i++)
33 | {
34 | var checkIDs = Console.ReadLine().Split(' ');
35 | var result = rectangles[checkIDs[0]].InteresectsWith(rectangles[checkIDs[1]]);
36 | Console.WriteLine(result.ToString().ToLower());
37 | }
38 |
39 |
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/bin/Debug/09.Rectangle Intersection.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/bin/Debug/09.Rectangle Intersection.exe
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/bin/Debug/09.Rectangle Intersection.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/bin/Debug/09.Rectangle Intersection.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/bin/Debug/09.Rectangle Intersection.pdb
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/obj/Debug/09.Rectangle Intersection.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\01.Defining Classes\09.Rectangle Intersection\bin\Debug\09.Rectangle Intersection.exe.config
2 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\01.Defining Classes\09.Rectangle Intersection\bin\Debug\09.Rectangle Intersection.exe
3 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\01.Defining Classes\09.Rectangle Intersection\bin\Debug\09.Rectangle Intersection.pdb
4 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\01.Defining Classes\09.Rectangle Intersection\obj\Debug\09.Rectangle Intersection.csprojResolveAssemblyReference.cache
5 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\01.Defining Classes\09.Rectangle Intersection\obj\Debug\09.Rectangle Intersection.exe
6 | C:\Local Disc D\Repos\SoftUni\04 - C# OOP Basics\01.Defining Classes\09.Rectangle Intersection\obj\Debug\09.Rectangle Intersection.pdb
7 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/obj/Debug/09.Rectangle Intersection.csprojResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/obj/Debug/09.Rectangle Intersection.csprojResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/obj/Debug/09.Rectangle Intersection.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/obj/Debug/09.Rectangle Intersection.exe
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/obj/Debug/09.Rectangle Intersection.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/obj/Debug/09.Rectangle Intersection.pdb
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/obj/Debug/CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | f8a5fe007dfe75ba308e3282a41c51bdf8e4eef8
2 |
--------------------------------------------------------------------------------
/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/03.Defining Classes & Encapsulation - Exercise/Rectangle Intersection/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/04.Inheritance - Exercise/Mankind/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/04.Inheritance - Exercise/Mankind/Human.cs:
--------------------------------------------------------------------------------
1 | namespace Mankind
2 | {
3 | using System;
4 | using System.Text;
5 |
6 | public class Human
7 | {
8 | private string firstName;
9 | private string lastName;
10 |
11 | public Human(string firstName, string lastName)
12 | {
13 | this.FirstName = firstName;
14 | this.LastName = lastName;
15 | }
16 | public string LastName
17 | {
18 | get { return this.lastName; }
19 | set
20 | {
21 | if (!char.IsUpper(value[0]))
22 | {
23 | throw new ArgumentException("Expected upper case letter! Argument: lastName");
24 | }
25 | if (value.Length < 3)
26 | {
27 | throw new ArgumentException("Expected length at least 3 symbols! Argument: lastName ");
28 | }
29 | this.lastName = value;
30 | }
31 | }
32 |
33 |
34 | public string FirstName
35 | {
36 | get { return this.firstName; }
37 | set
38 | {
39 | if (!char.IsUpper(value[0]))
40 | {
41 | throw new ArgumentException("Expected upper case letter! Argument: firstName");
42 | }
43 | if (value.Length < 4)
44 | {
45 | throw new ArgumentException("Expected length at least 4 symbols! Argument: firstName");
46 | }
47 |
48 | this.firstName = value;
49 | }
50 | }
51 |
52 | public override string ToString()
53 | {
54 | var sb = new StringBuilder();
55 | sb.AppendLine($"First Name: {this.FirstName}")
56 | .AppendLine($"Last Name: {this.LastName}");
57 |
58 | return sb.ToString();
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/04.Inheritance - Exercise/Mankind/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Mankind")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Mankind")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("0973f185-e3f1-4e35-8678-2895c705814c")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/04.Inheritance - Exercise/Mankind/Startup.cs:
--------------------------------------------------------------------------------
1 | namespace Mankind
2 | {
3 | using System;
4 |
5 | public class Startup
6 | {
7 | public static void Main()
8 | {
9 | try
10 | {
11 | var studentInfo = Console.ReadLine().Split(' ');
12 | var student = new Student(studentInfo[0], studentInfo[1], studentInfo[2]);
13 |
14 | var workerInfo = Console.ReadLine().Split(' ');
15 | var worker = new Worker(workerInfo[0], workerInfo[1], decimal.Parse(workerInfo[2]), decimal.Parse(workerInfo[3]));
16 |
17 | Console.WriteLine(student);
18 | Console.WriteLine(worker);
19 | }
20 | catch (ArgumentException ae)
21 | {
22 | Console.WriteLine(ae.Message);
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/04.Inheritance - Exercise/Mankind/Student.cs:
--------------------------------------------------------------------------------
1 | namespace Mankind
2 | {
3 | using System;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | public class Student : Human
8 | {
9 | private string facultyNumber;
10 |
11 | public Student(string firstName, string lastName, string facultyNumber) : base(firstName, lastName)
12 | {
13 | this.FacultyNumber = facultyNumber;
14 | }
15 |
16 | public string FacultyNumber
17 | {
18 | get { return this.facultyNumber; }
19 | set
20 | {
21 | if (value.Length < 5 || value.Length > 10 ||
22 | !value.All(char.IsLetterOrDigit))
23 | {
24 | throw new ArgumentException("Invalid faculty number!");
25 | }
26 | this.facultyNumber = value;
27 | }
28 | }
29 |
30 | public override string ToString()
31 | {
32 | var sb = new StringBuilder();
33 | sb.Append(base.ToString())
34 | .AppendLine($"Faculty number: {this.FacultyNumber}");
35 |
36 | return sb.ToString();
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/04.Inheritance - Exercise/Mankind/Worker.cs:
--------------------------------------------------------------------------------
1 | namespace Mankind
2 | {
3 | using System;
4 | using System.Text;
5 |
6 | public class Worker : Human
7 | {
8 | private decimal weekSalary;
9 | private decimal workHoursPerDay;
10 |
11 | public Worker(string firstName, string lastName, decimal weekSalary, decimal workHoursPerDay)
12 | : base(firstName, lastName)
13 | {
14 | this.WeekSalary = weekSalary;
15 | this.WorkHoursPerDay = workHoursPerDay;
16 | }
17 |
18 | public decimal WorkHoursPerDay
19 | {
20 | get { return this.workHoursPerDay; }
21 | set
22 | {
23 | if (value < 1 || value > 12)
24 | {
25 | throw new ArgumentException("Expected value mismatch! Argument: workHoursPerDay");
26 | }
27 | this.workHoursPerDay = value;
28 | }
29 | }
30 |
31 | public decimal WeekSalary
32 | {
33 | get { return this.weekSalary; }
34 | set
35 | {
36 | if (value <= 10)
37 | {
38 | throw new ArgumentException("Expected value mismatch! Argument: weekSalary");
39 | }
40 |
41 | this.weekSalary = value;
42 | }
43 | }
44 |
45 | private decimal CalculateSalaryPerHour()
46 | {
47 | return this.WeekSalary / (this.WorkHoursPerDay * 5m);
48 | }
49 |
50 | public override string ToString()
51 | {
52 | var sb = new StringBuilder();
53 | sb.Append(base.ToString())
54 | .AppendLine($"Week Salary: {this.WeekSalary:f2}")
55 | .AppendLine($"Hours per day: {this.WorkHoursPerDay:f2}")
56 | .AppendLine($"Salary per hour: {this.CalculateSalaryPerHour():f2}");
57 |
58 | return sb.ToString();
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/04.Inheritance - Exercise/Person/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/04.Inheritance - Exercise/Person/Child.cs:
--------------------------------------------------------------------------------
1 | namespace Person
2 | {
3 | using System;
4 |
5 | public class Child : Person
6 | {
7 | public Child(string name, int age) : base(name, age)
8 | {
9 | }
10 |
11 | public override int Age
12 | {
13 | set
14 | {
15 | if (value >= 15)
16 | {
17 | throw new ArgumentException("Child's age must be less than 15!");
18 | }
19 |
20 | base.Age = value;
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/04.Inheritance - Exercise/Person/Person.cs:
--------------------------------------------------------------------------------
1 | namespace Person
2 | {
3 | using System;
4 |
5 | public class Person
6 | {
7 | private string name;
8 | private int age;
9 |
10 | public Person(string name, int age)
11 | {
12 | this.Name = name;
13 | this.Age = age;
14 | }
15 | public virtual int Age
16 | {
17 | get { return this.age; }
18 | set
19 | {
20 | if (value < 0)
21 | {
22 | throw new ArgumentException("Age must be positive!");
23 | }
24 | this.age = value;
25 | }
26 | }
27 |
28 |
29 | public string Name
30 | {
31 | get { return this.name; }
32 | set
33 | {
34 | if (value.Length < 3)
35 | {
36 | throw new ArgumentException("Name's length should not be less than 3 symbols!");
37 | }
38 | this.name = value;
39 | }
40 | }
41 |
42 | public override string ToString()
43 | {
44 | return $"Name: {this.Name}, Age: {this.Age}";
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/04.Inheritance - Exercise/Person/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Person")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Person")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("2af64137-df44-4d7d-b4fc-3c239658a04f")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/04.Inheritance - Exercise/Person/Startup.cs:
--------------------------------------------------------------------------------
1 | namespace Person
2 | {
3 | using System;
4 |
5 | public class Program
6 | {
7 | public static void Main()
8 | {
9 | string name = Console.ReadLine();
10 | int age = int.Parse(Console.ReadLine());
11 |
12 | try
13 | {
14 | Child child = new Child(name, age);
15 | Console.WriteLine(child);
16 | }
17 | catch (ArgumentException ae)
18 | {
19 | Console.WriteLine(ae.Message);
20 | }
21 |
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/05.Polymorphism - Exercise/01.Vehicles/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/05.Polymorphism - Exercise/01.Vehicles/Car.cs:
--------------------------------------------------------------------------------
1 | namespace Vehicles
2 | {
3 | public class Car : Vehicle
4 | {
5 | private const double AcConsumptionMod = 0.9;
6 | public Car(double fuelQuantity, double fuelConsumptionPerKm)
7 | : base(fuelQuantity, fuelConsumptionPerKm + AcConsumptionMod)
8 | {
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/05.Polymorphism - Exercise/01.Vehicles/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Vehicles")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Vehicles")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("7f2cda71-9b65-43e3-bad2-7bf3dd1d8190")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/05.Polymorphism - Exercise/01.Vehicles/Startup.cs:
--------------------------------------------------------------------------------
1 | namespace Vehicles
2 | {
3 | using System;
4 |
5 | public class Startup
6 | {
7 | public static void Main()
8 | {
9 | var carInfo = Console.ReadLine().Split(' ');
10 | Vehicle car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]));
11 |
12 | var truckInfo = Console.ReadLine().Split(' ');
13 | Vehicle truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]));
14 |
15 | var commandsNumber = int.Parse(Console.ReadLine());
16 | for (int i = 0; i < commandsNumber; i++)
17 | {
18 | var commandTokens = Console.ReadLine().Split(' ');
19 | var vehicleType = commandTokens[1];
20 | if (vehicleType == "Car")
21 | {
22 | ExecuteAction(car, commandTokens[0], double.Parse(commandTokens[2]));
23 | }
24 | else
25 | {
26 | ExecuteAction(truck, commandTokens[0], double.Parse(commandTokens[2]));
27 | }
28 | }
29 |
30 | Console.WriteLine(car);
31 | Console.WriteLine(truck);
32 | }
33 |
34 | private static void ExecuteAction(Vehicle vehicle, string command, double parameter)
35 | {
36 | switch (command)
37 | {
38 | case "Drive":
39 | var result = vehicle.TryTravelDistance(parameter);
40 | Console.WriteLine(result);
41 | break;
42 | case "Refuel":
43 | vehicle.Refuel(parameter);
44 | break;
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/05.Polymorphism - Exercise/01.Vehicles/Truck.cs:
--------------------------------------------------------------------------------
1 | namespace Vehicles
2 | {
3 | public class Truck : Vehicle
4 | {
5 | private const double AcConsumptionMod = 1.6;
6 | private const double FuelLossFactor = 0.95;
7 |
8 | public Truck(double fuelQuantity, double fuelConsumptionPerKm)
9 | : base(fuelQuantity, fuelConsumptionPerKm + AcConsumptionMod)
10 | {}
11 |
12 | public override void Refuel(double fuelAmount)
13 | {
14 | base.Refuel(fuelAmount * FuelLossFactor);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/05.Polymorphism - Exercise/01.Vehicles/Vehicle.cs:
--------------------------------------------------------------------------------
1 | namespace Vehicles
2 | {
3 | using System.Globalization;
4 |
5 | public abstract class Vehicle
6 | {
7 | public Vehicle(double fuelQuantity, double fuelConsumptionPerKm)
8 | {
9 | this.FuelQuantity = fuelQuantity;
10 | this.FuelConsumptionPerKm = fuelConsumptionPerKm;
11 | }
12 | private double FuelQuantity { get; set; }
13 |
14 | private double FuelConsumptionPerKm { get; set; }
15 |
16 | private bool Drive(double distance)
17 | {
18 | var fuelRequired = distance * this.FuelConsumptionPerKm;
19 | if (fuelRequired <= this.FuelQuantity)
20 | {
21 | this.FuelQuantity -= fuelRequired;
22 | return true;
23 | }
24 |
25 | return false;
26 | }
27 |
28 | public string TryTravelDistance(double distance)
29 | {
30 | if (this.Drive(distance))
31 | {
32 | return $"{this.GetType().Name} travelled {distance} km";
33 | }
34 |
35 | return $"{this.GetType().Name} needs refueling";
36 | }
37 |
38 | public virtual void Refuel(double fuelAmount)
39 | => this.FuelQuantity += fuelAmount;
40 |
41 | public override string ToString()
42 | {
43 | return $"{this.GetType().Name}: {this.FuelQuantity:f2}";
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/05.Polymorphism - Exercise/02.Vehicles Extension/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/05.Polymorphism - Exercise/02.Vehicles Extension/Models/Bus.cs:
--------------------------------------------------------------------------------
1 | namespace Vehicles.Models
2 | {
3 | using System;
4 |
5 | public class Bus : Vehicle
6 | {
7 | private const double AcConsumptionMod = 1.4;
8 |
9 | public Bus(double fuelQuantity, double fuelConsumptionPerKm, double tankCapacity) : base(fuelQuantity, fuelConsumptionPerKm, tankCapacity)
10 | {
11 | }
12 |
13 | protected override double FuelQuantity
14 | {
15 | set
16 | {
17 | if (value > this.TankCapacity)
18 | {
19 | throw new ArgumentException("Cannot fit fuel in tank");
20 | }
21 |
22 | base.FuelQuantity = value;
23 | }
24 | }
25 |
26 | protected override bool Drive(double distance, bool isAcOn)
27 | {
28 | double requiredFuel = 0;
29 | if (isAcOn)
30 | {
31 | requiredFuel = distance * (this.FuelConsumptionPerKm + AcConsumptionMod);
32 | }
33 | else
34 | {
35 | requiredFuel = distance * this.FuelConsumptionPerKm;
36 | }
37 |
38 | if (requiredFuel <= this.FuelQuantity)
39 | {
40 | this.FuelQuantity -= requiredFuel;
41 | return true;
42 | }
43 |
44 | return false;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/05.Polymorphism - Exercise/02.Vehicles Extension/Models/Car.cs:
--------------------------------------------------------------------------------
1 | namespace Vehicles
2 | {
3 | using System;
4 |
5 | public class Car : Vehicle
6 | {
7 | private const double AcConsumptionMod = 0.9;
8 | public Car(double fuelQuantity, double fuelConsumptionPerKm, double tankCapacity)
9 | : base(fuelQuantity, fuelConsumptionPerKm + AcConsumptionMod,tankCapacity)
10 | {
11 | }
12 |
13 | protected override double FuelQuantity
14 | {
15 | set
16 | {
17 | if (value > this.TankCapacity)
18 | {
19 | throw new ArgumentException("Cannot fit in tank");
20 | }
21 |
22 | base.FuelQuantity = value;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/05.Polymorphism - Exercise/02.Vehicles Extension/Models/Truck.cs:
--------------------------------------------------------------------------------
1 | namespace Vehicles
2 | {
3 | public class Truck : Vehicle
4 | {
5 | private const double AcConsumptionMod = 1.6;
6 | private const double FuelLossFactor = 0.95;
7 |
8 | public Truck(double fuelQuantity, double fuelConsumptionPerKm, double tankCapacity)
9 | : base(fuelQuantity, fuelConsumptionPerKm + AcConsumptionMod, tankCapacity)
10 | {}
11 |
12 | public override void Refuel(double fuelAmount)
13 | {
14 | base.Refuel(fuelAmount * FuelLossFactor);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/05.Polymorphism - Exercise/02.Vehicles Extension/Models/Vehicle.cs:
--------------------------------------------------------------------------------
1 | namespace Vehicles
2 | {
3 | using System;
4 |
5 | public abstract class Vehicle
6 | {
7 | public Vehicle(double fuelQuantity, double fuelConsumptionPerKm, double tankCapacity)
8 | {
9 | this.TankCapacity = tankCapacity;
10 | this.FuelQuantity = fuelQuantity;
11 | this.FuelConsumptionPerKm = fuelConsumptionPerKm;
12 | }
13 | protected virtual double FuelQuantity { get; set; }
14 |
15 | protected double FuelConsumptionPerKm { get; set; }
16 |
17 | protected virtual double TankCapacity { get; set; }
18 |
19 | protected virtual bool Drive(double distance, bool isAcOn)
20 | {
21 | var fuelRequired = distance * this.FuelConsumptionPerKm;
22 | if (fuelRequired <= this.FuelQuantity)
23 | {
24 | this.FuelQuantity -= fuelRequired;
25 | return true;
26 | }
27 |
28 | return false;
29 | }
30 |
31 | public string TryTravelDistance(double distance, bool isAcOn)
32 | {
33 | if (this.Drive(distance, isAcOn))
34 | {
35 | return $"{this.GetType().Name} travelled {distance} km";
36 | }
37 |
38 | return $"{this.GetType().Name} needs refueling";
39 | }
40 |
41 | public string TryTravelDistance(double distance)
42 | {
43 | return this.TryTravelDistance(distance, true);
44 | }
45 |
46 | public virtual void Refuel(double fuelAmount)
47 | {
48 | if (fuelAmount <= 0)
49 | {
50 | throw new ArgumentException("Fuel must be a positive number");
51 | }
52 | this.FuelQuantity += fuelAmount;
53 | }
54 |
55 | public override string ToString()
56 | {
57 | return $"{this.GetType().Name}: {this.FuelQuantity:f2}";
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/05.Polymorphism - Exercise/02.Vehicles Extension/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Vehicles")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Vehicles")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("7f2cda71-9b65-43e3-bad2-7bf3dd1d8190")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Factories/FoodFactory.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Factories
2 | {
3 | using Models;
4 | using Models.Foods;
5 |
6 | public class FoodFactory
7 | {
8 | public Food GetFood(string foodType)
9 | {
10 | switch (foodType.ToLower())
11 | {
12 | case "cram":
13 | return new Cram();
14 | case "lembas":
15 | return new Lembas();
16 | case "melon":
17 | return new Melon();
18 | case "apple":
19 | return new Apple();
20 | case "honeycake":
21 | return new HoneyCake();
22 | case "mushrooms":
23 | return new Mushrooms();
24 | default:
25 | return new Junk();
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Factories/MoodFactory.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Factories
2 | {
3 | using Models;
4 | using Models.Moods;
5 |
6 | public class MoodFactory
7 | {
8 | public Mood GetMood(int hapinessPoints)
9 | {
10 | if (hapinessPoints < -5)
11 | {
12 | return new Angry();
13 | }
14 | if (hapinessPoints <= 0)
15 | {
16 | return new Sad();
17 | }
18 | if (hapinessPoints <= 15)
19 | {
20 | return new Happy();
21 | }
22 |
23 | return new JavaScript();
24 | }
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Food.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models
2 | {
3 | public abstract class Food
4 | {
5 | protected Food(int hapinessPoints)
6 | {
7 | this.HapinessPoints = hapinessPoints;
8 | }
9 | private int HapinessPoints { get; set; }
10 |
11 | public int GetHapinessPoints()
12 | {
13 | return this.HapinessPoints;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Foods/Apple.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models.Foods
2 | {
3 | public class Apple : Food
4 | {
5 | private const int HapinessPoints = 1;
6 | public Apple() : base(HapinessPoints)
7 | {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Foods/Cram.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models.Foods
2 | {
3 | public class Cram : Food
4 | {
5 | private const int HapinessPoints = 2;
6 | public Cram() : base(HapinessPoints)
7 | {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Foods/HoneyCake.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models.Foods
2 | {
3 | public class HoneyCake : Food
4 | {
5 | private const int HapinessPoints = 5;
6 | public HoneyCake() : base(HapinessPoints)
7 | {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Foods/Junk.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models.Foods
2 | {
3 | public class Junk : Food
4 | {
5 | private const int HapinessPoints = -1;
6 | public Junk() : base(HapinessPoints)
7 | {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Foods/Lembas.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models.Foods
2 | {
3 | public class Lembas : Food
4 | {
5 | private const int HapinessPoints = 3;
6 | public Lembas() : base(HapinessPoints)
7 | {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Foods/Melon.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models.Foods
2 | {
3 | public class Melon : Food
4 | {
5 | private const int HapinessPoints = 1;
6 | public Melon() : base(HapinessPoints)
7 | {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Foods/Mushrooms.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models.Foods
2 | {
3 | public class Mushrooms : Food
4 | {
5 | private const int HapinessPoints = -10;
6 | public Mushrooms() : base(HapinessPoints)
7 | {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Gandalf.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models
2 | {
3 | using System.Collections.Generic;
4 | using System.Linq;
5 |
6 | public class Gandalf
7 | {
8 | private List foodEaten;
9 |
10 | public Gandalf()
11 | {
12 | this.foodEaten = new List();
13 | }
14 |
15 | public void Eat(Food food)
16 | {
17 | this.foodEaten.Add(food);
18 | }
19 |
20 | public int GetHapinessPoints()
21 | {
22 | return foodEaten.Sum(f => f.GetHapinessPoints());
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Mood.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models
2 | {
3 | public abstract class Mood
4 | {
5 | public Mood(string moodName)
6 | {
7 | this.MoodName = moodName;
8 | }
9 |
10 | public string MoodName { get; set; }
11 |
12 | public override string ToString()
13 | {
14 | return this.MoodName;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Moods/Angry.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models.Moods
2 | {
3 | public class Angry : Mood
4 | {
5 | private const string MoodName = "Angry";
6 | public Angry() : base(MoodName)
7 | {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Moods/Happy.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models.Moods
2 | {
3 | public class Happy : Mood
4 | {
5 | private const string MoodName = "Happy";
6 | public Happy() : base(MoodName)
7 | {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Moods/JavaScript.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models.Moods
2 | {
3 | public class JavaScript : Mood
4 | {
5 | private const string MoodName = "JavaScript";
6 | public JavaScript() : base(MoodName)
7 | {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Models/Moods/Sad.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan.Models.Moods
2 | {
3 | public class Sad : Mood
4 | {
5 | private const string MoodName = "Sad";
6 | public Sad() : base(MoodName)
7 | {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Program.cs:
--------------------------------------------------------------------------------
1 | namespace MordorsCrueltyPlan
2 | {
3 | using System;
4 | using Factories;
5 | using Models;
6 |
7 | public class Program
8 | {
9 | public static void Main()
10 | {
11 | var foodFactory = new FoodFactory();
12 | var moodFactory = new MoodFactory();
13 | var gandalf = new Gandalf();
14 |
15 | var inputFood = Console.ReadLine().Split(new[] {'\t', ' ', '\n'}, StringSplitOptions.RemoveEmptyEntries);
16 |
17 | foreach (var foodStr in inputFood)
18 | {
19 | Food food = foodFactory.GetFood(foodStr);
20 | gandalf.Eat(food);
21 | }
22 |
23 | int totalHapinessPoints = gandalf.GetHapinessPoints();
24 |
25 | Mood currentMood = moodFactory.GetMood(totalHapinessPoints);
26 |
27 | Console.WriteLine(totalHapinessPoints);
28 | Console.WriteLine(currentMood);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/MordorsCrueltyPlan/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MordorsCrueltyPlan")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("MordorsCrueltyPlan")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("8ccba3ea-6728-4b87-8a40-9590582408ea")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Factories/AnimalFactory.cs:
--------------------------------------------------------------------------------
1 | namespace WildFarm.Factories
2 | {
3 | using Models;
4 | using Models.Animals;
5 |
6 | public class AnimalFactory
7 | {
8 | public static Animal GetAnimal(string[] tokens)
9 | {
10 | var animalType = tokens[0];
11 | var animalName = tokens[1];
12 | var animalWeight = double.Parse(tokens[2]);
13 | var animalRegion = tokens[3];
14 |
15 | switch (animalType)
16 | {
17 | case "Mouse":
18 | return new Mouse(animalName, animalType, animalWeight, animalRegion);
19 | case "Zebra":
20 | return new Zebra(animalName, animalType, animalWeight, animalRegion);
21 | case "Cat":
22 | return new Cat(animalName, animalType, animalWeight, animalRegion, tokens[4]);
23 | case "Tiger":
24 | return new Tiger(animalName,animalType, animalWeight, animalRegion);
25 | default:
26 | return null;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Factories/FoodFactory.cs:
--------------------------------------------------------------------------------
1 | namespace WildFarm.Factories
2 | {
3 | using Models;
4 | using Models.Foods;
5 |
6 | public class FoodFactory
7 | {
8 | public static Food GetFood(string[] tokens)
9 | {
10 | var foodType = tokens[0];
11 | var foodQuantity = int.Parse(tokens[1]);
12 |
13 | if (foodType == "Meat")
14 | {
15 | return new Meat(foodQuantity);
16 | }
17 |
18 | return new Vegetable(foodQuantity);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Models/Animal.cs:
--------------------------------------------------------------------------------
1 | namespace WildFarm.Models
2 | {
3 | public abstract class Animal
4 | {
5 | protected Animal(string name, string type, double weight)
6 | {
7 | this.Name = name;
8 | this.Type = type;
9 | this.Weight = weight;
10 | }
11 | protected string Name { get; set; }
12 | protected string Type { get; set; }
13 | protected double Weight { get; set; }
14 | protected int FoodEaten { get; set; }
15 |
16 | public abstract string MakeSound();
17 |
18 | public virtual void Eat(Food food)
19 | {
20 | this.FoodEaten += food.Quantity;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Models/Animals/Cat.cs:
--------------------------------------------------------------------------------
1 | namespace WildFarm.Models.Animals
2 | {
3 | public class Cat : Felime
4 | {
5 | public Cat(string name, string type, double weight, string livingRegion, string breed) : base(name, type, weight, livingRegion)
6 | {
7 | this.Breed = breed;
8 | }
9 |
10 | public string Breed { get; set; }
11 | public override string MakeSound()
12 | {
13 | return "Meowwww";
14 | }
15 |
16 | public override string ToString()
17 | {
18 | return $"{this.GetType().Name}[{this.Name}, {this.Breed}, {this.Weight}, {this.LivingRegion}, {this.FoodEaten}]";
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Models/Animals/Mouse.cs:
--------------------------------------------------------------------------------
1 | namespace WildFarm.Models.Animals
2 | {
3 | using System;
4 |
5 | public class Mouse : Mammal
6 | {
7 | public Mouse(string name, string type, double weight, string livingRegion) : base(name, type, weight, livingRegion)
8 | {
9 | }
10 |
11 | public override void Eat(Food food)
12 | {
13 | if (food.GetType().Name != "Vegetable")
14 | {
15 | throw new ArgumentException($"{this.GetType().Name}s are not eating that type of food!");
16 | }
17 | base.Eat(food);
18 | }
19 |
20 | public override string MakeSound()
21 | {
22 | return "SQUEEEAAAK!";
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Models/Animals/Tiger.cs:
--------------------------------------------------------------------------------
1 | namespace WildFarm.Models.Animals
2 | {
3 | using System;
4 |
5 | public class Tiger : Felime
6 | {
7 | public Tiger(string name, string type, double weight, string livingRegion) : base(name, type, weight, livingRegion)
8 | {
9 | }
10 |
11 | public override void Eat(Food food)
12 | {
13 | if (food.GetType().Name != "Meat")
14 | {
15 | throw new ArgumentException($"{this.GetType().Name}s are not eating that type of food!");
16 | }
17 |
18 | base.Eat(food);
19 | }
20 |
21 | public override string MakeSound()
22 | {
23 | return "ROAAR!!!";
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Models/Animals/Zebra.cs:
--------------------------------------------------------------------------------
1 | namespace WildFarm.Models.Animals
2 | {
3 | using System;
4 |
5 | public class Zebra : Mammal
6 | {
7 | public Zebra(string name, string type, double weight, string livingRegion) : base(name, type, weight, livingRegion)
8 | {
9 | }
10 |
11 | public override void Eat(Food food)
12 | {
13 | if (food.GetType().Name != "Vegetable")
14 | {
15 | throw new ArgumentException($"{this.GetType().Name}s are not eating that type of food!");
16 | }
17 | base.Eat(food);
18 | }
19 |
20 | public override string MakeSound()
21 | {
22 | return "Zs";
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Models/Felime.cs:
--------------------------------------------------------------------------------
1 | namespace WildFarm.Models
2 | {
3 | public abstract class Felime : Mammal
4 | {
5 | public Felime(string name, string type, double weight, string livingRegion) : base(name, type, weight, livingRegion)
6 | {
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Models/Food.cs:
--------------------------------------------------------------------------------
1 | namespace WildFarm.Models
2 | {
3 | public abstract class Food
4 | {
5 | protected Food(int quantity)
6 | {
7 | this.Quantity = quantity;
8 | }
9 | public int Quantity { get; set; }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Models/Foods/Meat.cs:
--------------------------------------------------------------------------------
1 | namespace WildFarm.Models.Foods
2 | {
3 | public class Meat : Food
4 | {
5 | public Meat(int quantity) : base(quantity)
6 | {
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Models/Foods/Vegetable.cs:
--------------------------------------------------------------------------------
1 | namespace WildFarm.Models.Foods
2 | {
3 | public class Vegetable : Food
4 | {
5 | public Vegetable(int quantity) : base(quantity)
6 | {
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Models/Mammal.cs:
--------------------------------------------------------------------------------
1 | namespace WildFarm.Models
2 | {
3 | using System;
4 |
5 | public abstract class Mammal : Animal
6 | {
7 | public Mammal(string name, string type, double weight, string livingRegion) : base(name, type, weight)
8 | {
9 | this.LivingRegion = livingRegion;
10 | }
11 |
12 |
13 | protected string LivingRegion { get; set; }
14 |
15 | public override string ToString()
16 | {
17 | return $"{this.GetType().Name}[{this.Name}, {this.Weight}, {this.LivingRegion}, {this.FoodEaten}]";
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Program.cs:
--------------------------------------------------------------------------------
1 | namespace WildFarm
2 | {
3 | using System;
4 | using Factories;
5 | using Models;
6 |
7 | public class Program
8 | {
9 | public static void Main()
10 | {
11 | string inputLine;
12 | while ((inputLine = Console.ReadLine()) != "End")
13 | {
14 | var animalTokens = inputLine.Split(new []{'\t', ' ', '\n'}, StringSplitOptions.RemoveEmptyEntries);
15 | var foodTokens = Console.ReadLine()
16 | .Split(new[] {'\t', ' ', '\n'}, StringSplitOptions.RemoveEmptyEntries);
17 |
18 | Animal animal = AnimalFactory.GetAnimal(animalTokens);
19 | Food food = FoodFactory.GetFood(foodTokens);
20 |
21 | Console.WriteLine(animal.MakeSound());
22 |
23 | try
24 | {
25 | animal.Eat(food);
26 | }
27 | catch (Exception e)
28 | {
29 | Console.WriteLine(e.Message);
30 | }
31 |
32 | Console.WriteLine(animal);
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/06.Inheritance & Polymorphism - Exercise/WildFarm/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("WildFarm")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("WildFarm")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("6c31a35f-5495-4178-927c-f015ea7b7d81")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/ExamPrepLiveDemo.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26403.7
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NFS", "NFS\NFS.csproj", "{672E48BE-6CEF-41F5-8640-88825399D83D}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {672E48BE-6CEF-41F5-8640-88825399D83D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {672E48BE-6CEF-41F5-8640-88825399D83D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {672E48BE-6CEF-41F5-8640-88825399D83D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {672E48BE-6CEF-41F5-8640-88825399D83D}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/Entities/Cars/Car.cs:
--------------------------------------------------------------------------------
1 | using System.Text;
2 |
3 | public abstract class Car
4 | {
5 | private string brand;
6 | private string model;
7 | private int yearOfProduction;
8 | private int horsepower;
9 | private int acceleration;
10 | private int suspension;
11 | private int durability;
12 |
13 | protected Car(string brand, string model, int yearOfProduction, int horsepower, int acceleration, int suspension, int durability)
14 | {
15 | this.brand = brand;
16 | this.model = model;
17 | this.yearOfProduction = yearOfProduction;
18 | this.horsepower = horsepower;
19 | this.acceleration = acceleration;
20 | this.suspension = suspension;
21 | this.durability = durability;
22 | }
23 |
24 | public string Brand => this.brand;
25 |
26 | public string Model => this.model;
27 |
28 | public int YearOfProduction => this.yearOfProduction;
29 |
30 | public int HorsePower
31 | {
32 | get { return this.horsepower; }
33 | set { this.horsepower = value; }
34 | }
35 |
36 | public int Acceleration { get { return this.acceleration; } }
37 |
38 | public int Suspension
39 | {
40 | get { return this.suspension; }
41 | set { this.suspension = value; }
42 | }
43 |
44 | public int Durability { get { return this.durability; } }
45 |
46 | public override string ToString()
47 | {
48 | StringBuilder sb = new StringBuilder();
49 |
50 | sb.AppendLine($"{brand} {model} {yearOfProduction}");
51 | sb.AppendLine($"{horsepower} HP, 100 m/h in {acceleration} s");
52 | sb.AppendLine($"{suspension} Suspension force, {durability} Durability");
53 |
54 | return sb.ToString();
55 | }
56 |
57 | public virtual void Tune(int tuneIndex, string addon)
58 | {
59 | this.HorsePower += tuneIndex;
60 | this.Suspension += tuneIndex * 50 / 100;
61 | }
62 | }
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/Entities/Cars/PerformanceCar.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text;
3 |
4 | public class PerformanceCar : Car
5 | {
6 | private List addOns;
7 |
8 | public PerformanceCar(string brand, string model, int yearOfProduction, int horsepower, int acceleration, int suspension, int durability) : base(brand, model, yearOfProduction, horsepower, acceleration, suspension, durability)
9 | {
10 | this.HorsePower += this.HorsePower * 50 / 100;
11 | this.Suspension -= this.Suspension * 25 / 100;
12 | this.addOns = new List();
13 | }
14 |
15 | public override string ToString()
16 | {
17 | StringBuilder sb = new StringBuilder(base.ToString());
18 |
19 | if (this.addOns.Count > 0)
20 | {
21 | sb.AppendLine("Add-ons: " + string.Join(", ", addOns));
22 | }
23 | else
24 | {
25 | sb.AppendLine("Add-ons: None");
26 | }
27 |
28 | return sb.ToString().Trim();
29 | }
30 |
31 | public override void Tune(int tuneIndex, string addon)
32 | {
33 | base.Tune(tuneIndex, addon);
34 | this.addOns.Add(addon);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/Entities/Cars/ShowCar.cs:
--------------------------------------------------------------------------------
1 | using System.Text;
2 |
3 | public class ShowCar : Car
4 | {
5 | private int stars;
6 |
7 | public ShowCar(string brand, string model, int yearOfProduction, int horsepower, int acceleration, int suspension, int durability)
8 | : base(brand, model, yearOfProduction, horsepower, acceleration, suspension, durability)
9 | {
10 | }
11 |
12 | public override string ToString()
13 | {
14 | StringBuilder sb = new StringBuilder(base.ToString());
15 |
16 | sb.AppendLine($"{stars} *");
17 |
18 | return sb.ToString().Trim();
19 | }
20 |
21 | public override void Tune(int tuneIndex, string addon)
22 | {
23 | base.Tune(tuneIndex, addon);
24 | this.stars += tuneIndex;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/Entities/Garage.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | public class Garage
4 | {
5 | public List ParkedCars { get; set; }
6 |
7 | public Garage()
8 | {
9 | this.ParkedCars = new List();
10 | }
11 |
12 | public void AddCar(int id)
13 | {
14 | this.ParkedCars.Add(id);
15 | }
16 |
17 | public void RemoveCar(int id)
18 | {
19 | this.ParkedCars.Remove(id);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/Entities/Races/CasualRace.cs:
--------------------------------------------------------------------------------
1 | public class CasualRace : Race
2 | {
3 | public CasualRace(int lenght, string route, int prizePool)
4 | : base(lenght, route, prizePool)
5 | {
6 | }
7 |
8 | public override int GetPerformance(int id)
9 | {
10 | var car = this.Participants[id];
11 |
12 | return (car.HorsePower / car.Acceleration) + (car.Suspension + car.Durability);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/Entities/Races/DragRace.cs:
--------------------------------------------------------------------------------
1 | public class DragRace : Race
2 | {
3 | public DragRace(int lenght, string route, int prizePool)
4 | : base(lenght, route, prizePool)
5 | {
6 | }
7 |
8 | public override int GetPerformance(int id)
9 | {
10 | var car = this.Participants[id];
11 |
12 | return (car.HorsePower / car.Acceleration);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/Entities/Races/DriftRace.cs:
--------------------------------------------------------------------------------
1 | public class DriftRace : Race
2 | {
3 | public DriftRace(int lenght, string route, int prizePool)
4 | : base(lenght, route, prizePool)
5 | {
6 | }
7 |
8 | public override int GetPerformance(int id)
9 | {
10 | var car = this.Participants[id];
11 |
12 | return (car.Suspension + car.Durability);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/Entities/Races/Race.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using System.Text;
4 |
5 | public abstract class Race
6 | {
7 | public int Length { get; set; }
8 | public string Route { get; set; }
9 | public int PrizePool { get; set; }
10 | public Dictionary Participants { get; set; }
11 | public List Winners { get; set; }
12 |
13 | public Race(int lenght, string route, int prizePool)
14 | {
15 | this.Length = lenght;
16 | this.Route = route;
17 | this.PrizePool = prizePool;
18 | this.Participants = new Dictionary();
19 | this.Winners = new List();
20 | }
21 |
22 | public abstract int GetPerformance(int id);
23 |
24 | public Dictionary GetWinners()
25 | {
26 | var winners = this.Participants.OrderByDescending(n => this.GetPerformance(n.Key)).Take(3).ToDictionary(n => n.Key, m => m.Value);
27 |
28 | return winners;
29 | }
30 |
31 | public List GetPrizes()
32 | {
33 | var result = new List();
34 | result.Add((this.PrizePool * 50) / 100);
35 | result.Add((this.PrizePool * 30) / 100);
36 | result.Add((this.PrizePool * 20) / 100);
37 | return result;
38 | }
39 |
40 | public string StartRace()
41 | {
42 |
43 | var winners = GetWinners();
44 | var prizes = GetPrizes();
45 | StringBuilder sb = new StringBuilder();
46 | sb.AppendLine($"{Route} - {Length}");
47 |
48 | for (int i = 0; i < winners.Count; i++)
49 | {
50 | var car = winners.ElementAt(i);
51 |
52 | sb.AppendLine(
53 | $"{i + 1}. {car.Value.Brand} {car.Value.Model} {this.GetPerformance(car.Key)}PP - ${prizes[i]}");
54 | }
55 |
56 |
57 |
58 | return sb.ToString().Trim();
59 | }
60 | }
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("NFS")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("NFS")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("672e48be-6cef-41f5-8640-88825399d83d")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/StartUp.cs:
--------------------------------------------------------------------------------
1 | public class StartUp
2 | {
3 | static void Main()
4 | {
5 | var engine = new Engine();
6 | engine.Run();
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/Utilities/Constants.cs:
--------------------------------------------------------------------------------
1 | public static class Constants
2 | {
3 | }
4 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/bin/Debug/NFS.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/ExamPrepLiveDemo/NFS/bin/Debug/NFS.exe
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/bin/Debug/NFS.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/bin/Debug/NFS.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/ExamPrepLiveDemo/NFS/bin/Debug/NFS.pdb
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/bin/Debug/nunit_random_seed.tmp:
--------------------------------------------------------------------------------
1 | 1808049391
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/obj/Debug/CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 52537b09c1099f61f16ee25eb446ddb4f1004711
2 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/ExamPrepLiveDemo/NFS/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/obj/Debug/NFS.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | D:\Projects\ExamPrepLiveDemo\NFS\bin\Debug\NFS.exe.config
2 | D:\Projects\ExamPrepLiveDemo\NFS\bin\Debug\NFS.exe
3 | D:\Projects\ExamPrepLiveDemo\NFS\bin\Debug\NFS.pdb
4 | D:\Projects\ExamPrepLiveDemo\NFS\obj\Debug\NFS.csprojResolveAssemblyReference.cache
5 | D:\Projects\ExamPrepLiveDemo\NFS\obj\Debug\NFS.exe
6 | D:\Projects\ExamPrepLiveDemo\NFS\obj\Debug\NFS.pdb
7 |
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/obj/Debug/NFS.csprojResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/ExamPrepLiveDemo/NFS/obj/Debug/NFS.csprojResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/obj/Debug/NFS.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/ExamPrepLiveDemo/NFS/obj/Debug/NFS.exe
--------------------------------------------------------------------------------
/ExamPrepLiveDemo/NFS/obj/Debug/NFS.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/ExamPrepLiveDemo/NFS/obj/Debug/NFS.pdb
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Core/Engine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 |
4 | public class Engine
5 | {
6 | private string input;
7 | private bool isRunning;
8 | private NationsBuilder builder;
9 |
10 | public Engine()
11 | {
12 | this.builder = new NationsBuilder();
13 | isRunning = true;
14 | }
15 |
16 | public void Run()
17 | {
18 | while (isRunning)
19 | {
20 | var cmdArgs = Console.ReadLine().Split(' ').ToList();
21 | var command = cmdArgs[0];
22 | cmdArgs.RemoveAt(0);
23 |
24 | switch (command)
25 | {
26 | case "Bender":
27 | builder.AssignBender(cmdArgs);
28 | break;
29 | case "Monument":
30 | builder.AssignMonument(cmdArgs);
31 | break;
32 | case "Status":
33 | Console.WriteLine(builder.GetStatus(cmdArgs[0]));
34 | break;
35 | case "War":
36 | builder.IssueWar(cmdArgs[0]);
37 | break;
38 | case "Quit":
39 | Console.WriteLine(builder.GetWarsRecord());
40 | isRunning = false;
41 | break;
42 | }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Entities/Benders/AirBender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | public class AirBender : Bender
4 | {
5 | public AirBender(string name, int power, double aerialIntegrity) : base(name, power)
6 | {
7 | this.AerialIntegrity = aerialIntegrity;
8 | }
9 |
10 | public double AerialIntegrity { get; private set; }
11 |
12 | public override double GetTotalPower()
13 | {
14 | return this.AerialIntegrity * base.Power;
15 | }
16 |
17 | public override string ToString()
18 | {
19 | return $"{base.ToString()} Aerial Integrity: {AerialIntegrity:f2}";
20 | }
21 | }
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Entities/Benders/Bender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | public abstract class Bender
3 | {
4 | public string Name { get; }
5 |
6 | public int Power { get; }
7 |
8 | protected Bender(string name, int power)
9 | {
10 | this.Name = name;
11 | this.Power = power;
12 | }
13 |
14 | public abstract double GetTotalPower();
15 |
16 | public override string ToString()
17 | {
18 | var name = this.GetType().Name;
19 | var index = name.IndexOf("Bender");
20 | name = name.Insert(index, " ");
21 |
22 | return $"###{name}: {this.Name}, Power: {this.Power},";
23 | }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Entities/Benders/EarthBender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | public class EarthBender : Bender
4 | {
5 | public EarthBender(string name, int power, double groundSaturation) : base(name, power)
6 | {
7 | this.GroundSaturation = groundSaturation;
8 | }
9 |
10 | public double GroundSaturation { get; private set; }
11 |
12 | public override double GetTotalPower()
13 | {
14 | return this.GroundSaturation * base.Power;
15 | }
16 |
17 | public override string ToString()
18 | {
19 | return $"{base.ToString()} Ground Saturation: {this.GroundSaturation:f2}";
20 | }
21 | }
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Entities/Benders/FireBender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | public class FireBender : Bender
4 | {
5 | public FireBender(string name, int power, double heatAggression ) : base(name, power)
6 | {
7 | this.HeatAggression = heatAggression;
8 | }
9 |
10 | public double HeatAggression { get; private set; }
11 |
12 | public override double GetTotalPower()
13 | {
14 | return this.HeatAggression * base.Power;
15 | }
16 |
17 | public override string ToString()
18 | {
19 | return $"{base.ToString()} Heat Aggression: {this.HeatAggression:f2}";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Entities/Benders/WaterBender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | public class WaterBender : Bender
4 | {
5 | public WaterBender(string name, int power, double waterClarity ) : base(name, power)
6 | {
7 | this.WaterClarity = waterClarity;
8 | }
9 |
10 | public double WaterClarity { get; private set; }
11 |
12 | public override double GetTotalPower()
13 | {
14 | return this.WaterClarity * base.Power;
15 | }
16 |
17 | public override string ToString()
18 | {
19 | return $"{base.ToString()} Water Clarity: {this.WaterClarity:f2}";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Entities/Monuments/AirMonument.cs:
--------------------------------------------------------------------------------
1 | public class AirMonument : Monument
2 | {
3 | public AirMonument(string name, int airAffinity ) : base(name)
4 | {
5 | this.AirAffinity = airAffinity;
6 | }
7 |
8 | private int AirAffinity { get;}
9 |
10 | public override double GetMonumentBonus()
11 | {
12 | return this.AirAffinity;
13 | }
14 |
15 | public override string ToString()
16 | {
17 | return $"{base.ToString()} Air Affinity: {this.AirAffinity}";
18 | }
19 | }
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Entities/Monuments/EarthMonument.cs:
--------------------------------------------------------------------------------
1 | public class EarthMonument : Monument
2 | {
3 | public EarthMonument(string name, int earthAffinity ) : base(name)
4 | {
5 | this.EarthAffinity = earthAffinity;
6 | }
7 |
8 | private int EarthAffinity { get; }
9 |
10 | public override double GetMonumentBonus()
11 | {
12 | return this.EarthAffinity;
13 | }
14 |
15 | public override string ToString()
16 | {
17 | return $"{base.ToString()} Earth Affinity: {this.EarthAffinity}";
18 | }
19 | }
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Entities/Monuments/FireMonument.cs:
--------------------------------------------------------------------------------
1 | public class FireMonument : Monument
2 | {
3 | public FireMonument(string name, int fireAffinity ) : base(name)
4 | {
5 | this.FireAffinity = fireAffinity;
6 | }
7 |
8 | private int FireAffinity { get; set; }
9 |
10 | public override double GetMonumentBonus()
11 | {
12 | return this.FireAffinity;
13 | }
14 |
15 | public override string ToString()
16 | {
17 | return $"{base.ToString()} Fire Affinity: {this.FireAffinity}";
18 | }
19 | }
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Entities/Monuments/Monument.cs:
--------------------------------------------------------------------------------
1 | public abstract class Monument
2 | {
3 | protected Monument(string name)
4 | {
5 | this.Name = name;
6 | }
7 |
8 | public string Name { get; }
9 |
10 | public abstract double GetMonumentBonus();
11 |
12 | public override string ToString()
13 | {
14 | var name = this.GetType().Name;
15 | var index = name.IndexOf("Monument");
16 | name = name.Insert(index, " ");
17 |
18 | return $"###{name}: {this.Name},";
19 | }
20 | }
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Entities/Monuments/WaterMonument.cs:
--------------------------------------------------------------------------------
1 | public class WaterMonument : Monument
2 | {
3 | public WaterMonument(string name, int waterAffinity ) : base(name)
4 | {
5 | this.WaterAffinity = waterAffinity;
6 | }
7 |
8 | private int WaterAffinity { get; }
9 |
10 | public override double GetMonumentBonus()
11 | {
12 | return this.WaterAffinity;
13 | }
14 |
15 | public override string ToString()
16 | {
17 | return $"{base.ToString()} Water Affinity: {this.WaterAffinity}";
18 | }
19 | }
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Entities/Nation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | public class Nation
7 | {
8 | private List benders;
9 | private List monuments;
10 |
11 | public Nation()
12 | {
13 | this.benders = new List();
14 | this.monuments = new List();
15 | }
16 |
17 | public void AddBender(Bender bender) => this.benders.Add(bender);
18 |
19 | public void AddMonument(Monument monument) => this.monuments.Add(monument);
20 |
21 | public double GetTotalPoints()
22 | {
23 | var power = this.benders.Sum(b => b.GetTotalPower());
24 | var bonus = this.monuments.Sum(m => m.GetMonumentBonus());
25 |
26 | return power += power / 100 * bonus;
27 | }
28 |
29 | public override string ToString()
30 | {
31 | StringBuilder sb = new StringBuilder();
32 |
33 | if (benders.Count > 0)
34 | {
35 | sb.AppendLine($"Benders:");
36 | sb.AppendLine(string.Join(Environment.NewLine, benders));
37 | }
38 | else
39 | {
40 | sb.AppendLine("Benders: None");
41 | }
42 |
43 | if (monuments.Count > 0)
44 | {
45 | sb.AppendLine($"Monuments:");
46 | sb.AppendLine(string.Join(Environment.NewLine, monuments));
47 | }
48 | else
49 | {
50 | sb.AppendLine("Monuments: None");
51 | }
52 |
53 | return sb.ToString().Trim();
54 | }
55 |
56 | public void KillYourself()
57 | {
58 | this.benders.Clear();
59 | this.monuments.Clear();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Program.cs:
--------------------------------------------------------------------------------
1 | public class Program
2 | {
3 | public static void Main(string[] args)
4 | {
5 | var engine = new Engine();
6 | engine.Run();
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("AvatarLiveDemo")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("AvatarLiveDemo")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("dc062521-6ca0-4fdd-b5bb-a588c66e9959")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/bin/Debug/AvatarLiveDemo.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/Live/AvatarLiveDemo/bin/Debug/AvatarLiveDemo.exe
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/bin/Debug/AvatarLiveDemo.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/bin/Debug/AvatarLiveDemo.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/Live/AvatarLiveDemo/bin/Debug/AvatarLiveDemo.pdb
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/obj/Debug/AvatarLiveDemo.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | D:\Projects\ExamPrepLiveDemo\Avatar\Live\AvatarLiveDemo\bin\Debug\AvatarLiveDemo.exe.config
2 | D:\Projects\ExamPrepLiveDemo\Avatar\Live\AvatarLiveDemo\bin\Debug\AvatarLiveDemo.exe
3 | D:\Projects\ExamPrepLiveDemo\Avatar\Live\AvatarLiveDemo\bin\Debug\AvatarLiveDemo.pdb
4 | D:\Projects\ExamPrepLiveDemo\Avatar\Live\AvatarLiveDemo\obj\Debug\AvatarLiveDemo.csprojResolveAssemblyReference.cache
5 | D:\Projects\ExamPrepLiveDemo\Avatar\Live\AvatarLiveDemo\obj\Debug\AvatarLiveDemo.exe
6 | D:\Projects\ExamPrepLiveDemo\Avatar\Live\AvatarLiveDemo\obj\Debug\AvatarLiveDemo.pdb
7 |
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/obj/Debug/AvatarLiveDemo.csprojResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/Live/AvatarLiveDemo/obj/Debug/AvatarLiveDemo.csprojResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/obj/Debug/AvatarLiveDemo.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/Live/AvatarLiveDemo/obj/Debug/AvatarLiveDemo.exe
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/obj/Debug/AvatarLiveDemo.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/Live/AvatarLiveDemo/obj/Debug/AvatarLiveDemo.pdb
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/obj/Debug/CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 4b01ec40a1e716381ee5b89821be3bec6c85c422
2 |
--------------------------------------------------------------------------------
/Live/AvatarLiveDemo/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/Live/AvatarLiveDemo/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/Live/Live.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26403.7
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvatarLiveDemo", "AvatarLiveDemo\AvatarLiveDemo.csproj", "{DC062521-6CA0-4FDD-B5BB-A588C66E9959}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {DC062521-6CA0-4FDD-B5BB-A588C66E9959}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {DC062521-6CA0-4FDD-B5BB-A588C66E9959}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {DC062521-6CA0-4FDD-B5BB-A588C66E9959}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {DC062521-6CA0-4FDD-B5BB-A588C66E9959}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/NeedForSpeed/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/NeedForSpeed/Entities/Cars/PerformanceCar.cs:
--------------------------------------------------------------------------------
1 | using NeedForSpeed.Utilities;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace NeedForSpeed.Entities.Cars
6 | {
7 | public class PerformanceCar : Car
8 | {
9 | private List addOns;
10 |
11 | public PerformanceCar(string brand, string model, int yearOfProduction, int horsepower, int acceleration, int suspension, int durability)
12 | : base(brand, model, yearOfProduction, horsepower, acceleration, suspension, durability)
13 | {
14 | this.modifyStats();
15 | this.addOns = new List();
16 | }
17 |
18 | public IReadOnlyList AddOns
19 | {
20 | get { return this.addOns.AsReadOnly(); }
21 | }
22 |
23 | private void modifyStats()
24 | {
25 | this.Horsepower = this.Horsepower +
26 | this.Horsepower *
27 | Constants.PERFORMANCE_CAR_HORSEPOWER_PERCENTAGE_MODIFIER /
28 | Constants.MAXIMUM_PERCENTAGE;
29 | this.Suspension = this.Suspension -
30 | this.Suspension *
31 | Constants.PERFORMANCE_CAR_SUSPENSION_PERCENTAGE_MODIFIER /
32 | Constants.MAXIMUM_PERCENTAGE;
33 | }
34 |
35 | public override void Tune(int tuneIndex, string tuneAddOn)
36 | {
37 | base.Tune(tuneIndex, tuneAddOn);
38 |
39 | this.addOns.Add(tuneAddOn);
40 | }
41 |
42 | public override string ToString()
43 | {
44 | StringBuilder result = new StringBuilder(base.ToString());
45 |
46 | result.Append(string.Format("Add-ons: {0}", this.AddOns.Count > 0 ? string.Join(", ", this.AddOns) : "None"));
47 |
48 | return result.ToString();
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/NeedForSpeed/Entities/Cars/ShowCar.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NeedForSpeed.Entities.Cars
8 | {
9 | public class ShowCar : Car
10 | {
11 | private int stars;
12 |
13 | public ShowCar(String brand, String model, int yearOfProduction, int horsepower, int acceleration, int suspension, int durability)
14 |
15 | :base(brand, model, yearOfProduction, horsepower, acceleration, suspension, durability)
16 | {
17 | this.Stars = 0;
18 | }
19 |
20 | public int Stars
21 | {
22 | get { return this.stars; }
23 | set { this.stars = value; }
24 | }
25 |
26 |
27 | public override void Tune(int tuneIndex, String tuneAddOn)
28 | {
29 | base.Tune(tuneIndex, tuneAddOn);
30 | this.Stars = this.Stars + tuneIndex;
31 | }
32 |
33 |
34 | public override string ToString()
35 | {
36 | StringBuilder result = new StringBuilder(base.ToString());
37 |
38 | result.Append(string.Format("{0} *", this.Stars));
39 |
40 | return result.ToString();
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/NeedForSpeed/Entities/Essentials/Garage.cs:
--------------------------------------------------------------------------------
1 | using NeedForSpeed.Entities.Cars;
2 | using System.Collections.Generic;
3 |
4 | namespace NeedForSpeed.Entities.Essentials
5 | {
6 | public class Garage
7 | {
8 | private Dictionary parkedCars;
9 |
10 | public Garage()
11 | {
12 | this.parkedCars = new Dictionary();
13 | }
14 |
15 | public void Park(int id, Car car)
16 | {
17 | this.parkedCars.Add(id, car);
18 | }
19 |
20 | public void Unpark(int id)
21 | {
22 | this.parkedCars.Remove(id);
23 | }
24 |
25 | public bool IsParked(int id)
26 | {
27 | return this.parkedCars.ContainsKey(id);
28 | }
29 |
30 | //WTF
31 | public void Tune(int tuneIndex, string addOn)
32 | {
33 | foreach (var parkedCar in this.parkedCars)
34 | {
35 | parkedCar.Value.Tune(tuneIndex, addOn);
36 | }
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/NeedForSpeed/Entities/Races/NormalRaces/CasualRace.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using NeedForSpeed.Entities.Cars;
7 | using NeedForSpeed.Utilities;
8 |
9 | namespace NeedForSpeed.Entities.Races.NormalRaces
10 | {
11 | public class CasualRace : NormalRace
12 | {
13 | public CasualRace(int length, String route, int prizePool)
14 | : base(length, route, prizePool)
15 | {
16 | }
17 |
18 |
19 | public override void Start()
20 | {
21 | int count = 0;
22 |
23 | Dictionary orderedParticipants = this.Participants
24 | .OrderByDescending(n => n.Value.OverallPerformance)
25 | .ToDictionary(x => x.Key, x => x.Value);
26 |
27 |
28 | foreach (var orderedParticipant in orderedParticipants)
29 | {
30 | if (count == Constants.CASUAL_RACE_MAXIMUM_WINNERS)
31 | {
32 | break;
33 | }
34 |
35 | this.AddWinner(orderedParticipant.Value);
36 | count++;
37 | }
38 | }
39 |
40 | protected override string GetWinningStats()
41 | {
42 | StringBuilder result = new StringBuilder();
43 |
44 | int count = 1;
45 |
46 | foreach (var winner in Winners)
47 | {
48 | int prize = this.GetPrize(count);
49 | result.AppendLine(string.Format(
50 | $"{count}. {winner.Brand} {winner.Model} {winner.OverallPerformance}PP - ${prize}"));
51 | count++;
52 | }
53 |
54 | return result.ToString().Trim();
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/NeedForSpeed/Entities/Races/NormalRaces/DragRace.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using NeedForSpeed.Entities.Cars;
7 | using NeedForSpeed.Utilities;
8 |
9 | namespace NeedForSpeed.Entities.Races.NormalRaces
10 | {
11 | public class DragRace : NormalRace
12 | {
13 | public DragRace(int length, String route, int prizePool)
14 | : base(length, route, prizePool)
15 | {
16 | }
17 |
18 |
19 | public override void Start()
20 | {
21 | int count = 0;
22 |
23 | Dictionary orderedParticipants = this.Participants
24 | .OrderByDescending(n => n.Value.EnginePerformance)
25 | .ToDictionary(x => x.Key, x => x.Value);
26 |
27 |
28 | foreach (var orderedParticipant in orderedParticipants)
29 | {
30 | if (count == Constants.CASUAL_RACE_MAXIMUM_WINNERS)
31 | {
32 | break;
33 | }
34 |
35 | this.AddWinner(orderedParticipant.Value);
36 | count++;
37 | }
38 | }
39 |
40 | protected override string GetWinningStats()
41 | {
42 | StringBuilder result = new StringBuilder();
43 |
44 | int count = 1;
45 |
46 | foreach (var winner in Winners)
47 | {
48 | int prize = this.GetPrize(count);
49 | result.AppendLine(string.Format(
50 | $"{count}. {winner.Brand} {winner.Model} {winner.EnginePerformance}PP - ${prize}"));
51 | count++;
52 | }
53 |
54 | return result.ToString().Trim();
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/NeedForSpeed/Entities/Races/NormalRaces/DriftRace.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using NeedForSpeed.Entities.Cars;
7 | using NeedForSpeed.Utilities;
8 |
9 | namespace NeedForSpeed.Entities.Races.NormalRaces
10 | {
11 | public class DriftRace : NormalRace
12 | {
13 | public DriftRace(int length, String route, int prizePool)
14 | : base(length, route, prizePool)
15 | {
16 | }
17 |
18 |
19 | public override void Start()
20 | {
21 | int count = 0;
22 |
23 | Dictionary orderedParticipants = this.Participants
24 | .OrderByDescending(n => n.Value.SuspensionPerformance)
25 | .ToDictionary(x => x.Key, x => x.Value);
26 |
27 |
28 | foreach (var orderedParticipant in orderedParticipants)
29 | {
30 | if (count == Constants.CASUAL_RACE_MAXIMUM_WINNERS)
31 | {
32 | break;
33 | }
34 |
35 | this.AddWinner(orderedParticipant.Value);
36 | count++;
37 | }
38 | }
39 |
40 | protected override string GetWinningStats()
41 | {
42 | StringBuilder result = new StringBuilder();
43 |
44 | int count = 1;
45 |
46 | foreach (var winner in Winners)
47 | {
48 | int prize = this.GetPrize(count);
49 | result.AppendLine(string.Format(
50 | $"{count}. {winner.Brand} {winner.Model} {winner.SuspensionPerformance}PP - ${prize}"));
51 | count++;
52 | }
53 |
54 | return result.ToString().Trim();
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/NeedForSpeed/Entities/Races/NormalRaces/NormalRace.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using NeedForSpeed.Utilities;
7 |
8 | namespace NeedForSpeed.Entities.Races.NormalRaces
9 | {
10 | public abstract class NormalRace : Race
11 | {
12 | protected NormalRace(int length, String route, int prizePool)
13 | : base(length, route, prizePool) { }
14 |
15 | protected override int GetPrize(int place)
16 | {
17 | int prize = this.PrizePool;
18 |
19 | switch (place)
20 | {
21 | case 1:
22 | prize = (prize * Constants.NORMAL_RACE_FIRST_PLACE_PRIZE_PERCENTAGE) / Constants.MAXIMUM_PERCENTAGE;
23 | break;
24 | case 2:
25 | prize = (prize * Constants.NORMAL_RACE_SECOND_PLACE_PRIZE_PERCENTAGE) / Constants.MAXIMUM_PERCENTAGE;
26 | break;
27 | case 3:
28 | prize = (prize * Constants.NORMAL_RACE_THIRD_PLACE_PRIZE_PERCENTAGE) / Constants.MAXIMUM_PERCENTAGE;
29 | break;
30 | }
31 |
32 | return prize;
33 | }
34 |
35 |
36 | public override string ToString()
37 | {
38 | StringBuilder result = new StringBuilder(base.ToString());
39 |
40 | result.Append(this.GetWinningStats());
41 |
42 | return result.ToString();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/NeedForSpeed/Entities/Races/Race.cs:
--------------------------------------------------------------------------------
1 | using NeedForSpeed.Entities.Cars;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace NeedForSpeed.Entities.Races
6 | {
7 | public abstract class Race
8 | {
9 | private int length;
10 | private string route;
11 | private int prizePool;
12 | private Dictionary participants;
13 | private List winners;
14 |
15 | protected Race(int length, string route, int prizePool)
16 | {
17 | this.Lenght = length;
18 | this.Route = route;
19 | this.PrizePool = prizePool;
20 |
21 | this.participants = new Dictionary();
22 | this.winners = new List();
23 | }
24 |
25 | protected IReadOnlyList Winners
26 | {
27 | get { return this.winners.AsReadOnly(); }
28 | }
29 |
30 | public int Lenght
31 | {
32 | get { return this.length; }
33 | set { this.length = value; }
34 | }
35 |
36 | public string Route
37 | {
38 | get { return this.route; }
39 | set { this.route = value; }
40 | }
41 |
42 | public int PrizePool
43 | {
44 | get { return this.prizePool; }
45 | set { this.prizePool = value; }
46 | }
47 |
48 | public Dictionary Participants
49 | {
50 | get { return this.participants; }
51 | }
52 |
53 | public abstract void Start();
54 |
55 | protected abstract int GetPrize(int place);
56 |
57 | protected abstract string GetWinningStats();
58 |
59 | public void AddParticipant(int carId, Car car)
60 | {
61 | this.participants.Add(carId, car);
62 | }
63 |
64 | protected void AddWinner(Car winner)
65 | {
66 | this.winners.Add(winner);
67 | }
68 |
69 | public override string ToString()
70 | {
71 | StringBuilder result = new StringBuilder();
72 |
73 | result.Append(string.Format($"{this.Route} - {this.Lenght}\r\n"));
74 |
75 | return result.ToString();
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/NeedForSpeed/Factories/CarFactory.cs:
--------------------------------------------------------------------------------
1 | using NeedForSpeed.Entities.Cars;
2 | using System;
3 |
4 | namespace NeedForSpeed.Factories
5 | {
6 | public class CarFactory
7 | {
8 | private CarFactory()
9 | {
10 | }
11 |
12 | public static PerformanceCar MakePerformanceCar(String brand, String model, int yearOfProduction, int horsepower, int acceleration, int suspension, int durability)
13 | {
14 | return new PerformanceCar(brand, model, yearOfProduction, horsepower, acceleration, suspension, durability);
15 | }
16 |
17 | public static ShowCar MakeShowCar(String brand, String model, int yearOfProduction, int horsepower, int acceleration, int suspension, int durability)
18 | {
19 | return new ShowCar(brand, model, yearOfProduction, horsepower, acceleration, suspension, durability);
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/NeedForSpeed/Factories/RaceFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using NeedForSpeed.Entities.Races.NormalRaces;
7 | using NeedForSpeed.Entities.Races.SpecialRaces;
8 |
9 | namespace NeedForSpeed.Factories
10 | {
11 | public class RaceFactory
12 | {
13 | private RaceFactory() { }
14 |
15 | public static CasualRace MakeCasualRace(int length, String route, int prizePool)
16 | {
17 | return new CasualRace(length, route, prizePool);
18 | }
19 |
20 | public static DragRace MakeDragRace(int length, String route, int prizePool)
21 | {
22 | return new DragRace(length, route, prizePool);
23 | }
24 |
25 | public static DriftRace MakeDriftRace(int length, String route, int prizePool)
26 | {
27 | return new DriftRace(length, route, prizePool);
28 | }
29 |
30 | public static TimeLimitRace MakeTimeLimitRace(int length, String route, int prizePool, int goldTime)
31 | {
32 | return new TimeLimitRace(length, route, prizePool, goldTime);
33 | }
34 |
35 | public static CircuitRace MakeCircuitRace(int length, String route, int prizePool, int laps)
36 | {
37 | return new CircuitRace(length, route, prizePool, laps);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/NeedForSpeed/IO/ConsoleReader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NeedForSpeed.IO
8 | {
9 | class ConsoleReader
10 | {
11 | public string ReadLine()
12 | {
13 | return Console.ReadLine();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/NeedForSpeed/IO/ConsoleWriter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NeedForSpeed.IO
8 | {
9 | public class ConsoleWriter
10 | {
11 | public void WriteLine(string output)
12 | {
13 | Console.WriteLine(output);
14 | }
15 |
16 | public void WriteLine(string[] elements)
17 | {
18 | foreach (var element in elements)
19 | {
20 | Console.WriteLine(string.Format(element));
21 |
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/NeedForSpeed/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("NeedForSpeed")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("NeedForSpeed")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("a4a0ff1a-c862-4470-bf96-a5f484ab6096")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/NeedForSpeed/StartUp.cs:
--------------------------------------------------------------------------------
1 | using NeedForSpeed.Core;
2 |
3 | namespace NeedForSpeed
4 | {
5 | public class StartUp
6 | {
7 | public static void Main()
8 | {
9 | Engine engine = new Engine();
10 | engine.Run();
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Bonus/Bonus.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/NeedForSpeed/Tests/Bonus/Bonus.zip
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Bonus/test.000.001.in.txt:
--------------------------------------------------------------------------------
1 | register 1 Performance Mitsubishi Lancer-Evo 2010 400 5 200 100
2 | register 2 Performance Nissan Z370 2012 500 4 300 200
3 | register 3 Show BMW i8-Spyder 2016 600 3 400 300
4 | register 4 Performance Lamborghini Aventador 2017 1000 2 500 300
5 | register 5 Show Ford Mustang-Shelby 1970 400 5 700 200
6 | open 1 Circuit 10 SofiaStreets 100000 5
7 | open 2 Circuit 2 SofiaAirport 10000 2
8 | participate 1 1
9 | participate 2 1
10 | participate 3 1
11 | participate 4 1
12 | participate 5 1
13 | start 1
14 | check 1
15 | check 2
16 | check 3
17 | check 4
18 | check 5
19 | Cops Are Here
20 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Bonus/test.000.001.out.txt:
--------------------------------------------------------------------------------
1 | SofiaStreets - 50
2 | 1. Lamborghini Aventador 925PP - $40000
3 | 2. Ford Mustang-Shelby 480PP - $30000
4 | 3. BMW i8-Spyder 400PP - $20000
5 | 4. Nissan Z370 112PP - $10000
6 | Mitsubishi Lancer-Evo 2010
7 | 600 HP, 100 m/h in 5 s
8 | 150 Suspension force, -400 Durability
9 | Add-ons: None
10 | Nissan Z370 2012
11 | 750 HP, 100 m/h in 4 s
12 | 225 Suspension force, -300 Durability
13 | Add-ons: None
14 | BMW i8-Spyder 2016
15 | 600 HP, 100 m/h in 3 s
16 | 400 Suspension force, -200 Durability
17 | 0 *
18 | Lamborghini Aventador 2017
19 | 1500 HP, 100 m/h in 2 s
20 | 375 Suspension force, -200 Durability
21 | Add-ons: None
22 | Ford Mustang-Shelby 1970
23 | 400 HP, 100 m/h in 5 s
24 | 700 Suspension force, -300 Durability
25 | 0 *
26 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Bonus/test.000.002.in.txt:
--------------------------------------------------------------------------------
1 | register 1 Performance Mitsubishi Lancer-Evo 2010 400 5 200 100
2 | register 4 Performance Lamborghini Aventador 2017 1000 2 500 300
3 | park 4
4 | tune 1000 Turbo
5 | unpark 4
6 | open 1 TimeLimit 5 SofiaAirport 100000 260
7 | open 2 TimeLimit 5 Malibu 10000 240
8 | start 1
9 | participate 4 1
10 | participate 4 2
11 | start 1
12 | start 2
13 | Cops Are Here
14 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Bonus/test.000.002.out.txt:
--------------------------------------------------------------------------------
1 | Cannot start the race with zero participants.
2 | SofiaAirport - 5
3 | Lamborghini Aventador - 250 s.
4 | Gold Time, $100000.
5 | Malibu - 5
6 | Lamborghini Aventador - 250 s.
7 | Silver Time, $5000.
8 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Bonus/test.001.in.txt:
--------------------------------------------------------------------------------
1 | register 1 Performance Mitsubishi Lancer-Evo 2010 400 5 200 100
2 | register 4 Performance Lamborghini Aventador 2017 1000 2 500 300
3 | park 4
4 | tune 1000 Turbo
5 | unpark 4
6 | open 1 TimeLimit 5 SofiaAirport 100000 260
7 | open 2 TimeLimit 5 Malibu 10000 240
8 | start 1
9 | participate 4 1
10 | participate 1 1
11 | start 1
12 | Cops Are Here
13 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Bonus/test.001.out.txt:
--------------------------------------------------------------------------------
1 | Cannot start the race with zero participants.
2 | SofiaAirport - 5
3 | Lamborghini Aventador - 250 s.
4 | Gold Time, $100000.
5 |
6 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Bonus/test.002.in.txt:
--------------------------------------------------------------------------------
1 | register 1 Performance Mitsubishi Lancer-Evo 2010 400 5 200 100
2 | register 2 Performance Nissan Z370 2012 500 4 300 200
3 | register 3 Show BMW i8-Spyder 2016 600 3 400 300
4 | register 4 Performance Lamborghini Aventador 2017 1000 2 500 300
5 | register 5 Show Ford Mustang-Shelby 1970 400 5 700 200
6 | open 1 Circuit 10 SofiaStreets 100000 5
7 | participate 1 1
8 | participate 2 1
9 | participate 3 1
10 | participate 4 1
11 | participate 5 1
12 | start 1
13 | open 2 TimeLimit 5 Airport 100000 200
14 | park 4
15 | check 4
16 | tune 1000 ReactiveOwl
17 | participate 4 2
18 | check 4
19 | start 2
20 | unpark 4
21 | participate 4 2
22 | start 2
23 | Cops Are Here
24 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Bonus/test.002.out.txt:
--------------------------------------------------------------------------------
1 | SofiaStreets - 50
2 | 1. Lamborghini Aventador 925PP - $40000
3 | 2. Ford Mustang-Shelby 480PP - $30000
4 | 3. BMW i8-Spyder 400PP - $20000
5 | 4. Nissan Z370 112PP - $10000
6 | Lamborghini Aventador 2017
7 | 1500 HP, 100 m/h in 2 s
8 | 375 Suspension force, -200 Durability
9 | Add-ons: None
10 | Lamborghini Aventador 2017
11 | 2500 HP, 100 m/h in 2 s
12 | 875 Suspension force, -200 Durability
13 | Add-ons: ReactiveOwl
14 | Cannot start the race with zero participants.
15 | Airport - 5
16 | Lamborghini Aventador - 250 s.
17 | Bronze Time, $30000.
18 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/BuisnessLogic.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/NeedForSpeed/Tests/BuisnessLogic/BuisnessLogic.zip
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.000.001.in.txt:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using System;
3 |
4 | [TestFixture]
5 | public class T00TestClassExists
6 | {
7 | private const string ClassNotExists = "Class '%s' not exist";
8 |
9 | // Class names
10 | private Type[] classes =
11 | {
12 | typeof(Car),
13 | typeof(ShowCar),
14 | typeof(PerformanceCar),
15 | typeof(Garage),
16 | typeof(Race),
17 | typeof(CasualRace),
18 | typeof(DragRace),
19 | typeof(DriftRace)
20 | };
21 |
22 | [Test]
23 | public void AssertExistingClasses()
24 | {
25 | foreach (var className in classes)
26 | {
27 | AssertClassExists(className);
28 | }
29 | }
30 |
31 | private void AssertClassExists(Type className)
32 | {
33 | Assert.IsNotNull(className, ClassNotExists);
34 | }
35 | }
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.000.001.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.000.002.in.txt:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using System;
3 | using System.Linq;
4 |
5 | [TestFixture]
6 | public class T00TestCarManagerMethods
7 | {
8 | private Type manager = typeof(CarManager);
9 | private string[] methodNames =
10 | {
11 | "Register",
12 | "Check",
13 | "Open",
14 | "Participate",
15 | "Start",
16 | "Park",
17 | "Unpark",
18 | "Tune"
19 | };
20 |
21 |
22 | [Test]
23 | public void TestMethod()
24 | {
25 | var methods = manager.GetMethods().Select(n => n.Name);
26 | foreach (var methodName in methodNames)
27 | {
28 | Assert.IsTrue(methods.Contains(methodName), $"{manager.Name} doesn't contain method {methodName}");
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.000.002.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.000.003.in.txt:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using System;
3 |
4 | [TestFixture]
5 | public class T00TestToStringOverride
6 | {
7 | private Type[] classes =
8 | {
9 | typeof(Car),
10 | typeof(ShowCar),
11 | typeof(PerformanceCar)
12 | };
13 |
14 | [Test]
15 | public void TestMethod()
16 | {
17 | foreach (var className in classes)
18 | {
19 | Assert.IsTrue(className.GetMethod("ToString").DeclaringType == className, $"{className}");
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.000.003.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.001.in.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using NUnit.Framework;
3 |
4 | [TestFixture]
5 | public class T01TestRegisterAndCheckMethods
6 | {
7 | private Type sut = typeof(CarManager);
8 | private object[] carDetails = new object[] {1, "Performance", "BMW", "M3", 1992, 200, 5, 100, 100};
9 | private string expectedOutput =
10 | "BMW M3 1992\r\n" +
11 | "300 HP, 100 m/h in 5 s\r\n" +
12 | "75 Suspension force, 100 Durability\r\n" +
13 | "Add-ons: None";
14 |
15 | [Test]
16 | public void TestMethod()
17 | {
18 | var register = sut.GetMethod("Register");
19 | var check = sut.GetMethod("Check");
20 |
21 | var manager = new CarManager();
22 | register.Invoke(manager, carDetails);
23 | var actualOutput = check.Invoke(manager, new object[] { 1 });
24 | Assert.AreEqual(expectedOutput, actualOutput, $"Methods {register.Name} or {check.Name} doesn't work properly");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.001.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.002.in.txt:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using System;
3 |
4 | [TestFixture]
5 | public class T02TestOpenParticipateStartMethods
6 | {
7 | private Type sut = typeof(CarManager);
8 | private object[] carDetails = new object[] { 1, "Performance", "BMW", "M3", 1992, 200, 5, 100, 100 };
9 | private object[] raceDetails = new object[] { 1, "Casual", 1000, "Dragon", 100 };
10 | private string expectedOutput = "Dragon - 1000\r\n" + "1. BMW M3 235PP - $50";
11 |
12 | [Test]
13 | public void TestMethod()
14 | {
15 | var register = sut.GetMethod("Register");
16 | var open = sut.GetMethod("Open", new Type[] { typeof(int), typeof(string), typeof(int), typeof(string), typeof(int) });
17 | var participate = sut.GetMethod("Participate");
18 | var start = sut.GetMethod("Start");
19 | var manager = new CarManager();
20 |
21 | register.Invoke(manager, carDetails);
22 | open.Invoke(manager, raceDetails);
23 | participate.Invoke(manager, new object[] { 1, 1 });
24 | var actualOutput = start.Invoke(manager, new object[] { 1 });
25 | Assert.AreEqual(expectedOutput, actualOutput);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.002.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.003.in.txt:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using System;
3 |
4 | [TestFixture]
5 | public class T03TestTuneMethods
6 | {
7 | private Type sut = typeof(CarManager);
8 | private object[] carDetails = new object[] { 1, "Performance", "BMW", "M3", 1992, 200, 5, 100, 100 };
9 | private string expectedOutput = "BMW M3 1992\r\n" +
10 | "400 HP, 100 m/h in 5 s\r\n" +
11 | "125 Suspension force, 100 Durability\r\n" +
12 | "Add-ons: White Stripes";
13 |
14 | [Test]
15 | public void TestMethod()
16 | {
17 | var register = sut.GetMethod("Register");
18 | var park = sut.GetMethod("Park");
19 | var tune = sut.GetMethod("Tune");
20 | var check = sut.GetMethod("Check");
21 | var manager = new CarManager();
22 |
23 | register.Invoke(manager, carDetails);
24 | park.Invoke(manager, new object[] {1});
25 | tune.Invoke(manager, new object[] { 100, "White Stripes" });
26 | var actualOutput = check.Invoke(manager, new object[] { 1 });
27 | Assert.AreEqual(expectedOutput, actualOutput, $"{expectedOutput}");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.003.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.004.in.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using NUnit.Framework;
3 |
4 | [TestFixture]
5 | public class T04TestParkAndRaceMethods
6 | {
7 | private Type sut = typeof(CarManager);
8 | private object[] perfCarDetails = new object[] { 1, "Performance", "BMW", "M3", 1992, 200, 5, 100, 100 };
9 | private object[] showCarDetails = new object[] { 2, "Show", "Merc", "C", 1995, 180, 6, 100, 100 };
10 | private object[] raceDetails = new object[] { 1, "Casual", 1000, "Dragon", 100 };
11 | private string expectedStartOutput = "Dragon - 1000\r\n" +
12 | "1. Merc C 230PP - $50";
13 |
14 | [Test]
15 | public void TestMethod()
16 | {
17 | var register = sut.GetMethod("Register");
18 | var park = sut.GetMethod("Park");
19 | var participate = sut.GetMethod("Participate");
20 | var start = sut.GetMethod("Start");
21 | var open = sut.GetMethod("Open", new Type[] { typeof(int), typeof(string), typeof(int), typeof(string), typeof(int) });
22 | var manager = new CarManager();
23 |
24 | register.Invoke(manager, perfCarDetails);
25 | register.Invoke(manager, showCarDetails);
26 | open.Invoke(manager, raceDetails);
27 | park.Invoke(manager, new object[] { 1 });
28 | participate.Invoke(manager, new object[] { 1, 1 });
29 | participate.Invoke(manager, new object[] { 2, 1 });
30 |
31 | String startActualOutput = (String)start.Invoke(manager, new object[] { 1 });
32 | Assert.AreEqual(startActualOutput, expectedStartOutput, $"{startActualOutput}");
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.004.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.005.in.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using NUnit.Framework;
3 |
4 | [TestFixture]
5 | public class T05TestParkParticipateUnparkParticipateStart
6 | {
7 | private Type sut = typeof(CarManager);
8 | private object[] perfCarDetails = new object[] { 1, "Performance", "BMW", "M3", 1992, 200, 5, 100, 100 };
9 | private object[] showCarDetails = new object[] { 2, "Show", "Merc", "C", 1995, 180, 6, 100, 100 };
10 | private object[] raceDetails = new object[] { 1, "Casual", 1000, "Dragon", 100 };
11 | private string expectedStartOutput = "Dragon - 1000\r\n" +
12 | "1. Merc C 230PP - $50";
13 |
14 | [Test]
15 | public void TestMethod()
16 | {
17 | var register = sut.GetMethod("Register");
18 | var park = sut.GetMethod("Park");
19 | var participate = sut.GetMethod("Participate");
20 | var start = sut.GetMethod("Start");
21 | var open = sut.GetMethod("Open", new Type[] { typeof(int), typeof(string), typeof(int), typeof(string), typeof(int) });
22 | var manager = new CarManager();
23 |
24 | register.Invoke(manager, perfCarDetails);
25 | register.Invoke(manager, showCarDetails);
26 | open.Invoke(manager, raceDetails);
27 | park.Invoke(manager, new object[] { 1 });
28 | participate.Invoke(manager, new object[] { 1, 1 }); // should not include 1
29 | participate.Invoke(manager, new object[] { 2, 1 });
30 | //park.Invoke(manager, new object[] { 2 }); // should not park 2
31 |
32 | // start
33 | String startActualOutput = (String)start.Invoke(manager, new object[] { 1 }); // Merc wins
34 | Assert.AreEqual(startActualOutput, expectedStartOutput, $"{startActualOutput}");
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/BuisnessLogic/test.005.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/IO/IO.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/NeedForSpeed/Tests/IO/IO.zip
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/IO/test.000.001.in.txt:
--------------------------------------------------------------------------------
1 | register 1 Performance BMV M92 2013 300 4 150 75
2 | register 2 Show Maserati Levante 2015 400 6 250 100
3 | register 3 Performance Nissan GT-R 2017 550 4 300 100
4 | register 4 Performance McLaren P1 2016 650 2 400 200
5 | register 5 Performance Trabant 601 1988 2000 1 10000 1000
6 | open 1 Drag 10 BeverlyHills 50000
7 | open 3 Casual 20 NewYork 100000
8 | participate 1 1
9 | participate 2 1
10 | participate 3 1
11 | participate 4 1
12 | participate 5 1
13 | participate 1 3
14 | participate 2 3
15 | participate 3 3
16 | participate 4 3
17 | participate 5 3
18 | check 5
19 | start 1
20 | start 3
21 | Cops Are Here
22 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/IO/test.000.001.out.txt:
--------------------------------------------------------------------------------
1 | Trabant 601 1988
2 | 3000 HP, 100 m/h in 1 s
3 | 7500 Suspension force, 1000 Durability
4 | Add-ons: None
5 | BeverlyHills - 10
6 | 1. Trabant 601 3000PP - $25000
7 | 2. McLaren P1 487PP - $15000
8 | 3. Nissan GT-R 206PP - $10000
9 | NewYork - 20
10 | 1. Trabant 601 11500PP - $50000
11 | 2. McLaren P1 987PP - $30000
12 | 3. Nissan GT-R 531PP - $20000
13 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/IO/test.000.002.in.txt:
--------------------------------------------------------------------------------
1 | register 3 Show Porsche Carrera 2017 550 4 300 100
2 | register 4 Performance McLaren P1 2016 650 2 400 200
3 | register 5 Performance Trabant 601 1988 2000 1 10000 1000
4 | open 1 Casual 20 Manhattan 100000
5 | open 2 Drag 14 Washington 100000
6 | participate 5 1
7 | participate 5 2
8 | park 3
9 | park 4
10 | park 5
11 | start 2
12 | tune 150 Turbo
13 | tune 100 Nitrous
14 | tune 50 Tires
15 | participate 3 1
16 | check 3
17 | check 4
18 | unpark 4
19 | participate 4 1
20 | start 1
21 | Cops Are Here
22 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/IO/test.000.002.out.txt:
--------------------------------------------------------------------------------
1 | Washington - 14
2 | 1. Trabant 601 3000PP - $50000
3 | Porsche Carrera 2017
4 | 850 HP, 100 m/h in 4 s
5 | 450 Suspension force, 100 Durability
6 | 300 *
7 | McLaren P1 2016
8 | 1275 HP, 100 m/h in 2 s
9 | 450 Suspension force, 200 Durability
10 | Add-ons: Turbo, Nitrous, Tires
11 | Manhattan - 20
12 | 1. Trabant 601 11500PP - $50000
13 | 2. McLaren P1 1287PP - $30000
14 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/IO/test.001.in.txt:
--------------------------------------------------------------------------------
1 | register 1 Performance Trabant 601 1988 20000 1 10000 1000
2 | park 1
3 | open 1 Drift 5 East-Side 2000
4 | participate 1 1
5 | start 1
6 | unpark 1
7 | participate 1 1
8 | park 1
9 | tune 100 TurboXXX
10 | check 1
11 | start 1
12 | check 1
13 | Cops Are Here
14 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/IO/test.001.out.txt:
--------------------------------------------------------------------------------
1 | Cannot start the race with zero participants.
2 | Trabant 601 1988
3 | 30000 HP, 100 m/h in 1 s
4 | 7500 Suspension force, 1000 Durability
5 | Add-ons: None
6 | East-Side - 5
7 | 1. Trabant 601 8500PP - $1000
8 | Trabant 601 1988
9 | 30000 HP, 100 m/h in 1 s
10 | 7500 Suspension force, 1000 Durability
11 | Add-ons: None
12 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/IO/test.002.in.txt:
--------------------------------------------------------------------------------
1 | register 1 Performance BMV M92 2013 300 4 150 75
2 | register 2 Show Maserati Levante 2015 400 6 250 100
3 | register 3 Performance Nissan GT-R 2017 550 4 300 100
4 | register 4 Performance McLaren P1 2016 650 2 400 200
5 | register 5 Performance Trabant 601 1988 50000 1 10000 1000
6 | open 1 Drag 5 SofiaAirport 100000
7 | open 2 Drift 3 SofiaStreets 50000
8 | open 3 Casual 20 Malibu 75000
9 | park 1
10 | park 2
11 | park 3
12 | participate 4 1
13 | participate 5 1
14 | participate 1 1
15 | participate 2 1
16 | participate 3 1
17 | start 1
18 | tune 100 Turbo
19 | check 3
20 | unpark 1
21 | unpark 2
22 | unpark 3
23 | park 5
24 | check 5
25 | tune 5000 Nitrous
26 | check 5
27 | unpark 5
28 | participate 5 2
29 | start 3
30 | start 2
31 | participate 1 3
32 | participate 2 3
33 | participate 3 3
34 | participate 4 3
35 | participate 5 3
36 | start 3
37 | Cops Are Here
38 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/IO/test.002.out.txt:
--------------------------------------------------------------------------------
1 | SofiaAirport - 5
2 | 1. Trabant 601 75000PP - $50000
3 | 2. McLaren P1 487PP - $30000
4 | Nissan GT-R 2017
5 | 925 HP, 100 m/h in 4 s
6 | 275 Suspension force, 100 Durability
7 | Add-ons: Turbo
8 | Trabant 601 1988
9 | 75000 HP, 100 m/h in 1 s
10 | 7500 Suspension force, 1000 Durability
11 | Add-ons: None
12 | Trabant 601 1988
13 | 80000 HP, 100 m/h in 1 s
14 | 10000 Suspension force, 1000 Durability
15 | Add-ons: Nitrous
16 | Cannot start the race with zero participants.
17 | SofiaStreets - 3
18 | 1. Trabant 601 11000PP - $25000
19 | Malibu - 20
20 | 1. Trabant 601 91000PP - $37500
21 | 2. McLaren P1 987PP - $22500
22 | 3. Nissan GT-R 606PP - $15000
23 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/IO/test.003.in.txt:
--------------------------------------------------------------------------------
1 | register 1 Show Moskvich 412 1980 1000 1000 1000 1000
2 | register 2 Show Jigula 2101 1970 1000 1000 1000 1000
3 | register 3 Show Pirin-Fiat Punto 1990 1000 1000 1000 1000
4 | open 1 Casual 20 Sofia 20000
5 | park 1
6 | park 2
7 | participate 1 1
8 | start 1
9 | tune 1000 Tires
10 | check 1
11 | check 2
12 | unpark 1
13 | unpark 2
14 | park 3
15 | tune 2000 Bumpers
16 | participate 3 1
17 | start 1
18 | unpark 3
19 | check 3
20 | participate 1 1
21 | participate 2 1
22 | open 2 Drift 5 SofiaStreets 50000
23 | participate 1 2
24 | participate 2 2
25 | participate 3 2
26 | start 2
27 | start 1
28 | Cops Are Here
29 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/IO/test.003.out.txt:
--------------------------------------------------------------------------------
1 | Cannot start the race with zero participants.
2 | Moskvich 412 1980
3 | 2000 HP, 100 m/h in 1000 s
4 | 1500 Suspension force, 1000 Durability
5 | 1000 *
6 | Jigula 2101 1970
7 | 2000 HP, 100 m/h in 1000 s
8 | 1500 Suspension force, 1000 Durability
9 | 1000 *
10 | Cannot start the race with zero participants.
11 | Pirin-Fiat Punto 1990
12 | 3000 HP, 100 m/h in 1000 s
13 | 2000 Suspension force, 1000 Durability
14 | 2000 *
15 | SofiaStreets - 5
16 | 1. Pirin-Fiat Punto 3000PP - $25000
17 | 2. Moskvich 412 2500PP - $15000
18 | 3. Jigula 2101 2500PP - $10000
19 | Sofia - 20
20 | 1. Moskvich 412 2502PP - $10000
21 | 2. Jigula 2101 2502PP - $6000
22 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/IO/test.004.in.txt:
--------------------------------------------------------------------------------
1 | register 1 Performance Trabant 601 1988 2000 1 10000 1000
2 | open 1 Casual 20 SofiaStreets 50000
3 | open 2 Casual 20 SofiaStreets 40000
4 | open 3 Casual 20 SofiaStreets 30000
5 | participate 1 1
6 | participate 1 2
7 | participate 1 3
8 | park 1
9 | tune 2000 Turbo
10 | check 1
11 | start 1
12 | park 1
13 | tune 2000 Nitrous
14 | check 1
15 | start 2
16 | park 1
17 | tune 2000 Chipset
18 | check 1
19 | start 3
20 | park 1
21 | tune 20000 Turbo
22 | tune 10000 Nitrous
23 | tune 5000 Chipset
24 | check 1
25 | open 4 Casual 200 TestRace 1000
26 | participate 1 4
27 | start 4
28 | Cops Are Here
29 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/IO/test.004.out.txt:
--------------------------------------------------------------------------------
1 | Trabant 601 1988
2 | 3000 HP, 100 m/h in 1 s
3 | 7500 Suspension force, 1000 Durability
4 | Add-ons: None
5 | SofiaStreets - 20
6 | 1. Trabant 601 11500PP - $25000
7 | Trabant 601 1988
8 | 3000 HP, 100 m/h in 1 s
9 | 7500 Suspension force, 1000 Durability
10 | Add-ons: None
11 | SofiaStreets - 20
12 | 1. Trabant 601 11500PP - $20000
13 | Trabant 601 1988
14 | 3000 HP, 100 m/h in 1 s
15 | 7500 Suspension force, 1000 Durability
16 | Add-ons: None
17 | SofiaStreets - 20
18 | 1. Trabant 601 11500PP - $15000
19 | Trabant 601 1988
20 | 38000 HP, 100 m/h in 1 s
21 | 25000 Suspension force, 1000 Durability
22 | Add-ons: Turbo, Nitrous, Chipset
23 | Cannot start the race with zero participants.
24 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/Structure.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSharpFundamentals/CSharp-OOP-Basics_June2017/0a02761c0ef65ea7fe26efeae3661062a3b8a4c1/NeedForSpeed/Tests/Structure/Structure.zip
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.000.001.in.txt:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using System;
3 |
4 | [TestFixture]
5 | public class T00TestClassExists
6 | {
7 | private const string ClassNotExists = "Class '%s' not exist";
8 |
9 | // Class names
10 | private Type[] classes =
11 | {
12 | typeof(Car),
13 | typeof(ShowCar),
14 | typeof(PerformanceCar),
15 | typeof(Garage),
16 | typeof(Race),
17 | typeof(CasualRace),
18 | typeof(DragRace),
19 | typeof(DriftRace)
20 | };
21 |
22 | [Test]
23 | public void AssertExistingClasses()
24 | {
25 | foreach (var className in classes)
26 | {
27 | AssertClassExists(className);
28 | }
29 | }
30 |
31 | private void AssertClassExists(Type className)
32 | {
33 | Assert.IsNotNull(className, ClassNotExists);
34 | }
35 | }
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.000.001.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.000.002.in.txt:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using System;
3 | using System.Reflection;
4 |
5 | [TestFixture]
6 | public class T00TestCarsConstructors
7 | {
8 | // Class names
9 | private Type[] classes =
10 | {
11 | typeof(Car),
12 | typeof(ShowCar),
13 | typeof(PerformanceCar),
14 | };
15 |
16 | private string[] ctorParameters = {"String", "String", "Int32", "Int32", "Int32", "Int32", "Int32"};
17 |
18 | [Test]
19 | public void TestMethod()
20 | {
21 | foreach (var className in classes)
22 | {
23 | AssertConstructors(className);
24 | }
25 | }
26 |
27 | private void AssertConstructors(Type className)
28 | {
29 | ConstructorInfo[] constructors = className.GetConstructors(BindingFlags.Instance | BindingFlags.Public);
30 |
31 | foreach (var ctor in constructors)
32 | {
33 | var parameters = ctor.GetParameters();
34 | Assert.IsTrue(parameters.Length == ctorParameters.Length);
35 | for (int i = 0; i < ctorParameters.Length; i++)
36 | {
37 | Assert.AreEqual(parameters[i].ParameterType.Name, ctorParameters[i], "Constructor parameters are in wrong order");
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.000.002.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.000.003.in.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Reflection;
4 | using NUnit.Framework;
5 |
6 | [TestFixture]
7 | public class T00TestRacesConstructors
8 | {
9 | // Class names
10 | private Type[] classes =
11 | {
12 | typeof(Race),
13 | typeof(DragRace),
14 | typeof(DriftRace),
15 | typeof(CasualRace)
16 | };
17 |
18 | private string[] ctorParameters = { "Int32", "String", "Int32"};
19 |
20 | [Test]
21 | public void TestMethod()
22 | {
23 | foreach (var className in classes)
24 | {
25 | AssertConstructors(className);
26 | }
27 | }
28 |
29 | private void AssertConstructors(Type className)
30 | {
31 | ConstructorInfo[] constructors = className.GetConstructors(BindingFlags.Instance | BindingFlags.Public);
32 |
33 | foreach (var ctor in constructors)
34 | {
35 | var parameters = ctor.GetParameters();
36 | Assert.IsTrue(parameters.Length == ctorParameters.Length);
37 | for (int i = 0; i < ctorParameters.Length; i++)
38 | {
39 | Assert.AreEqual(parameters[i].ParameterType.Name, ctorParameters[i], "Constructor parameters are in wrong order");
40 | }
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.000.003.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.001.in.txt:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using System;
3 | using System.Reflection;
4 |
5 | [TestFixture]
6 | public class T01TestForNonPrivateFields
7 | {
8 | // Class names
9 | private Type[] classes =
10 | {
11 | typeof(Car),
12 | typeof(ShowCar),
13 | typeof(PerformanceCar),
14 | typeof(Garage),
15 | typeof(Race),
16 | typeof(CasualRace),
17 | typeof(DragRace),
18 | typeof(DriftRace)
19 | };
20 |
21 | [Test]
22 | public void TestMethod()
23 | {
24 | foreach (var className in classes)
25 | {
26 | AssertFields(className);
27 | }
28 | }
29 |
30 | private void AssertFields(Type className)
31 | {
32 | var fields = className.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
33 | foreach (var fieldInfo in fields)
34 | {
35 | Assert.IsTrue(fieldInfo.IsPrivate, $"{fieldInfo.Name} in {className.Name} is NOT Private");
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.001.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.002.in.txt:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using System;
3 | [TestFixture]
4 | public class T02TestAbstractClasses
5 | {
6 | // Class names
7 | private Type[] classes =
8 | {
9 | typeof(Car),
10 | typeof(Race),
11 | };
12 |
13 | [Test]
14 | public void TestMethod()
15 | {
16 | foreach (var className in classes)
17 | {
18 | Assert.IsTrue(className.IsAbstract, $"{className.Name} is NOT abstarct");
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.002.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.003.in.txt:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using System;
3 |
4 | [TestFixture]
5 | public class T03TestCarHierarchy
6 | {
7 | // Class names
8 | private Type[] classes =
9 | {
10 | typeof(ShowCar),
11 | typeof(PerformanceCar)
12 | };
13 |
14 | private Type parentClass = typeof(Car);
15 |
16 | [Test]
17 | public void TestMethod()
18 | {
19 | foreach (var className in classes)
20 | {
21 | Assert.IsTrue(CheckHierarchy(className));
22 | }
23 | }
24 |
25 | private bool CheckHierarchy(Type className)
26 | {
27 | var baseClass = className.BaseType;
28 | while (baseClass != typeof(object))
29 | {
30 | if (baseClass == parentClass)
31 | {
32 | return true;
33 | }
34 | baseClass = baseClass.BaseType;
35 | }
36 | return false;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.003.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.004.in.txt:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using System;
3 | using System.ComponentModel.Design;
4 |
5 | [TestFixture]
6 | public class T04TestRaceHierarchy
7 | {
8 | // Class names
9 | private Type[] classes =
10 | {
11 | typeof(CasualRace),
12 | typeof(DriftRace),
13 | typeof(DragRace)
14 | };
15 |
16 | private Type parentClass = typeof(Race);
17 |
18 | [Test]
19 | public void TestMethod()
20 | {
21 | foreach (var className in classes)
22 | {
23 | Assert.IsTrue(CheckHierarchy(className));
24 | }
25 | }
26 |
27 | private bool CheckHierarchy(Type className)
28 | {
29 | var baseClass = className.BaseType;
30 | while (baseClass != typeof(object))
31 | {
32 | if (baseClass == parentClass)
33 | {
34 | return true;
35 | }
36 | baseClass = baseClass.BaseType;
37 | }
38 | return false;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.004.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.005.in.txt:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Linq;
4 | using System.Reflection;
5 | using NUnit.Framework;
6 |
7 | [TestFixture]
8 | class T05TestReadOnlyCollection
9 | {
10 | // Class names
11 | private Type[] classes =
12 | {
13 | typeof(PerformanceCar),
14 | typeof(ShowCar),
15 | typeof(Garage),
16 | typeof(CasualRace),
17 | typeof(DragRace),
18 | typeof(DriftRace)
19 | };
20 |
21 | [Test]
22 | public void AssertExistingClasses()
23 | {
24 | foreach (var className in classes)
25 | {
26 | AssertReadOnlyCollections(className.GetProperties());
27 | }
28 | }
29 |
30 | private void AssertReadOnlyCollections(PropertyInfo[] getProperties)
31 | {
32 | foreach (var propertyInfo in getProperties)
33 | {
34 | var typeOf = propertyInfo.GetMethod.ReturnType;
35 | var interfaces = typeOf.GetInterfaces();
36 | if (interfaces.Contains(typeof(IEnumerable)) && typeOf != typeof(string))
37 | {
38 | Assert.IsTrue(propertyInfo.SetMethod == null || propertyInfo.CanWrite || propertyInfo.SetMethod.IsPublic);
39 | }
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/NeedForSpeed/Tests/Structure/test.005.out.txt:
--------------------------------------------------------------------------------
1 | Test Passed!
--------------------------------------------------------------------------------
/NeedForSpeed/Utilities/Constants.cs:
--------------------------------------------------------------------------------
1 | namespace NeedForSpeed.Utilities
2 | {
3 | public static class Constants
4 | {
5 | public const string INPUT_TERMINATING_COMMAND = "Cops Are Here";
6 |
7 | public const string RACE_HAS_NO_PARTICIPANTS_MESSAGE = "Cannot start the race with zero participants.";
8 |
9 | public const int MAXIMUM_PERCENTAGE = 100;
10 |
11 | public const int PERFORMANCE_CAR_HORSEPOWER_PERCENTAGE_MODIFIER = 50;
12 |
13 | public const int PERFORMANCE_CAR_SUSPENSION_PERCENTAGE_MODIFIER = 25;
14 |
15 | public const int TUNING_SUSPENSION_MODIFIER = 2;
16 |
17 | public const int CASUAL_RACE_MAXIMUM_WINNERS = 3;
18 |
19 | public const int DRAG_RACE_MAXIMUM_WINNERS = 3;
20 |
21 | public const int DRIFT_RACE_MAXIMUM_WINNERS = 3;
22 |
23 | public const int CIRCUIT_RACE_MAXIMUM_WINNERS = 4;
24 |
25 | public const int NORMAL_RACE_FIRST_PLACE_PRIZE_PERCENTAGE = 50;
26 |
27 | public const int NORMAL_RACE_SECOND_PLACE_PRIZE_PERCENTAGE = 30;
28 |
29 | public const int NORMAL_RACE_THIRD_PLACE_PRIZE_PERCENTAGE = 20;
30 |
31 | public const int CIRCUIT_RACE_FIRST_PLACE_PRIZE_PERCENTAGE = 40;
32 |
33 | public const int CIRCUIT_RACE_SECOND_PLACE_PRIZE_PERCENTAGE = 30;
34 |
35 | public const int CIRCUIT_RACE_THIRD_PLACE_PRIZE_PERCENTAGE = 20;
36 |
37 | public const int CIRCUIT_RACE_FOURTH_PLACE_PRIZE_PERCENTAGE = 10;
38 |
39 | public const int TIME_LIMIT_RACE_FIRST_PLACE_PRIZE_PERCENTAGE = 100;
40 |
41 | public const int TIME_LIMIT_RACE_SECOND_PLACE_PRIZE_PERCENTAGE = 50;
42 |
43 | public const int TIME_LIMIT_RACE_THIRD_PLACE_PRIZE_PERCENTAGE = 30;
44 |
45 | public const int TIME_LIMIT_RACE_SILVER_TIME_SECONDS_OFFSET = 15;
46 | }
47 | }
--------------------------------------------------------------------------------
/NeedForSpeed/Utilities/InputParser.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NeedForSpeed.Utilities
8 | {
9 | public class InputParser
10 | {
11 | public List parseInput(string inputLine)
12 | {
13 | return new List(inputLine.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries));
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------