diff --git a/Lesson_3/Task_1/Classes/Computer.cs b/Lesson_3/Task_1/Classes/Computer.cs new file mode 100644 index 0000000..efd265a --- /dev/null +++ b/Lesson_3/Task_1/Classes/Computer.cs @@ -0,0 +1,117 @@ +namespace Classes; + +using Lists; +using Methods; + +class Computer +{ + public Motherboard Motherboard { get; set; } + public List Rams { get; set; } = new List(); + public List Cpus { get; set; } = new List(); + public List Gpus { get; set; } = new List(); + public List Drives { get; set; } = new List(); + public int Price { get; set; } = 0; + + public void DisplayInstalledMotherboard() + { + Console.WriteLine("Motherboard: "); + (new MotherboardMethods()).DisplayMotherboard(Motherboard); + } + + public void DisplayInstalledRams() + { + Console.WriteLine($"RAM ({Motherboard.RamType}): {Motherboard.UsedRamSlots}/{Motherboard.RamSlots}"); + foreach (Ram ram in Rams) + (new RamMethods()).DisplayRam(ram); + } + + public void DisplayInstalledCpus() + { + Console.WriteLine($"CPUs ({Motherboard.Socket}): {Motherboard.UsedCpuSlots}/{Motherboard.CpuSlots}"); + foreach (Cpu cpu in Cpus) + (new CpuMethods()).DisplayCpu(cpu); + } + + public void DisplayInstalledGpus() + { + Console.WriteLine("GPUs:"); + foreach (Gpu gpu in Gpus) + (new GpuMethods()).DisplayGpu(gpu); + } + + public void DisplayInstalledDrives() + { + Console.WriteLine($"Drives (PATA {Motherboard.UsedPataSlots}/{Motherboard.PataSlots}, SATA {Motherboard.UsedSataSlots}/{Motherboard.SataSlots}):"); + foreach (Drive drive in Drives) + (new DriveMethods()).DisplayDrive(drive); + } + + public void Display() + { + DisplayInstalledMotherboard(); + DisplayInstalledRams(); + DisplayInstalledCpus(); + DisplayInstalledGpus(); + DisplayInstalledDrives(); + } + + public void Replace(Motherboard motherboard) + { + Motherboard = motherboard; + Rams.Clear(); + Cpus.Clear(); + Gpus.Clear(); + Drives.Clear(); + Price = motherboard.Price; + } + + public void Checkout(int money) + { + while (true) + { + int choice; + Display(); + + if (!Rams.Any() || !Cpus.Any() || !Gpus.Any() || !Drives.Any()) + Console.WriteLine("\nThis computer lacks some details."); + + Console.WriteLine($"\nTotal cost: {Price}"); + if (money - Price < 0) + Console.WriteLine("You cannot afford this computer."); + + Console.WriteLine("Remove RAMs [1]\nRemove CPUs [2]\nRemove GPUs [3]\nRemove Drives [4]\nReplace motherboard (removes everything else) [5]\nGo back [6]"); + if (int.TryParse(Console.ReadLine(), out choice)) + { + switch (choice) + { + case 1: + (new RamMethods()).DisplayRamList(this, Rams, true); + break; + case 2: + (new CpuMethods()).DisplayCpuList(this, Cpus, true); + break; + case 3: + (new GpuMethods()).DisplayGpuList(this, Gpus, true); + break; + case 4: + (new DriveMethods()).DisplayDriveList(this, Drives, true); + break; + case 5: + Motherboard motherboard = (new MotherboardMethods()).DisplayMotherboardList(); + this.Replace(motherboard); + break; + case 6: + goto Back; + } + } + } + Back: + Console.WriteLine("Going back…"); + } + + public Computer(Motherboard motherboard) + { + Motherboard = motherboard; + Price = motherboard.Price; + } +} diff --git a/Lesson_3/Task_1/Classes/Cpu.cs b/Lesson_3/Task_1/Classes/Cpu.cs new file mode 100644 index 0000000..10b9505 --- /dev/null +++ b/Lesson_3/Task_1/Classes/Cpu.cs @@ -0,0 +1,8 @@ +namespace Classes; + +class Cpu : Detail +{ + public string Socket { get; set; } + public int Cores { get; set; } + public int Frequency { get; set; } +} diff --git a/Lesson_3/Task_1/Classes/Detail.cs b/Lesson_3/Task_1/Classes/Detail.cs new file mode 100644 index 0000000..6a5416f --- /dev/null +++ b/Lesson_3/Task_1/Classes/Detail.cs @@ -0,0 +1,9 @@ +namespace Classes; + +class Detail +{ + public int Price { get; set; } + public string Supplier { get; set; } + public string Country { get; set; } + public string Name { get; set; } +} diff --git a/Lesson_3/Task_1/Classes/Drive.cs b/Lesson_3/Task_1/Classes/Drive.cs new file mode 100644 index 0000000..eaab24c --- /dev/null +++ b/Lesson_3/Task_1/Classes/Drive.cs @@ -0,0 +1,9 @@ +namespace Classes; + +class Drive : Detail +{ + public int Size { get; set; } + public int Speed { get; set; } + public string Interface { get; set; } + public int? Lifetime { get; set; } +} diff --git a/Lesson_3/Task_1/Classes/Gpu.cs b/Lesson_3/Task_1/Classes/Gpu.cs new file mode 100644 index 0000000..ec9c3f2 --- /dev/null +++ b/Lesson_3/Task_1/Classes/Gpu.cs @@ -0,0 +1,7 @@ +namespace Classes; + +class Gpu : Detail +{ + public int Memory { get; set; } + public int Speed { get; set; } +} diff --git a/Lesson_3/Task_1/Classes/Motherboard.cs b/Lesson_3/Task_1/Classes/Motherboard.cs new file mode 100644 index 0000000..0c7acce --- /dev/null +++ b/Lesson_3/Task_1/Classes/Motherboard.cs @@ -0,0 +1,15 @@ +namespace Classes; + +class Motherboard : Detail +{ + public string RamType { get; set; } + public int RamSlots { get; set; } + public int UsedRamSlots {get; set; } + public string Socket { get; set; } + public int CpuSlots {get; set; } + public int UsedCpuSlots {get; set; } + public int PataSlots { get; set; } + public int UsedPataSlots {get; set; } + public int SataSlots { get; set; } + public int UsedSataSlots {get; set; } +} diff --git a/Lesson_3/Task_1/Classes/Ram.cs b/Lesson_3/Task_1/Classes/Ram.cs new file mode 100644 index 0000000..83cd318 --- /dev/null +++ b/Lesson_3/Task_1/Classes/Ram.cs @@ -0,0 +1,7 @@ +namespace Classes; + +class Ram : Detail +{ + public string Type { get; set; } + public int Size { get; set; } +} diff --git a/Lesson_3/Task_1/Lists/CpusForSale.cs b/Lesson_3/Task_1/Lists/CpusForSale.cs new file mode 100644 index 0000000..25722d8 --- /dev/null +++ b/Lesson_3/Task_1/Lists/CpusForSale.cs @@ -0,0 +1,40 @@ +namespace Lists; + +using Classes; + +class CpusForSale +{ + public List Hardware { get; set; } = new List + { + new Cpu + { + Price = 1000, + Supplier = "Company 1", + Country = "Country 1", + Name = "CPU 1", + Socket = "Socket 1", + Cores = 1, + Frequency = 2000 + }, + new Cpu + { + Price = 2000, + Supplier = "Company 2", + Country = "Country 2", + Name = "CPU 2", + Socket = "Socket 1", + Cores = 2, + Frequency = 3000 + }, + new Cpu + { + Price = 3000, + Supplier = "Company 3", + Country = "Country 3", + Name = "CPU 3", + Socket = "Socket 2", + Cores = 4, + Frequency = 2000 + } + }; +} diff --git a/Lesson_3/Task_1/Lists/DrivesForSale.cs b/Lesson_3/Task_1/Lists/DrivesForSale.cs new file mode 100644 index 0000000..599fbbf --- /dev/null +++ b/Lesson_3/Task_1/Lists/DrivesForSale.cs @@ -0,0 +1,41 @@ +namespace Lists; + +using Classes; + +class DrivesForSale +{ + public List Hardware { get; set; } = new List + { + new Drive + { + Price = 1000, + Supplier = "Company 1", + Country = "Country 1", + Name = "Drive 1", + Size = 240, + Speed = 100, + Interface = "PATA" + }, + new Drive + { + Price = 2000, + Supplier = "Company 2", + Country = "Country 2", + Name = "Drive 2", + Size = 480, + Speed = 200, + Interface = "SATA" + }, + new Drive + { + Price = 3000, + Supplier = "Company 3", + Country = "Country 3", + Name = "Drive 3", + Size = 250, + Speed = 400, + Interface = "SATA", + Lifetime = 70 + } + }; +} diff --git a/Lesson_3/Task_1/Lists/GpusForSale.cs b/Lesson_3/Task_1/Lists/GpusForSale.cs new file mode 100644 index 0000000..266c10f --- /dev/null +++ b/Lesson_3/Task_1/Lists/GpusForSale.cs @@ -0,0 +1,37 @@ +namespace Lists; + +using Classes; + +class GpusForSale +{ + public List Hardware { get; set; } = new List + { + new Gpu + { + Price = 1000, + Supplier = "Company 1", + Country = "Country 1", + Name = "GPU 1", + Memory = 2048, + Speed = 2000 + }, + new Gpu + { + Price = 2000, + Supplier = "Company 2", + Country = "Country 2", + Name = "GPU 2", + Memory = 4096, + Speed = 3000 + }, + new Gpu + { + Price = 3000, + Supplier = "Company 3", + Country = "Country 3", + Name = "GPU 3", + Memory = 8192, + Speed = 4000 + } + }; +} diff --git a/Lesson_3/Task_1/Lists/MotherboardsForSale.cs b/Lesson_3/Task_1/Lists/MotherboardsForSale.cs new file mode 100644 index 0000000..5919da2 --- /dev/null +++ b/Lesson_3/Task_1/Lists/MotherboardsForSale.cs @@ -0,0 +1,49 @@ +namespace Lists; + +using Classes; + +class MotherboardsForSale +{ + public List Hardware { get; set; } = new List + { + new Motherboard + { + Price = 1000, + Supplier = "Company 1", + Country = "Country 1", + Name = "Motherboard 1", + RamType = "DDR2", + RamSlots = 2, + Socket = "Socket 1", + CpuSlots = 1, + PataSlots = 2, + SataSlots = 2 + }, + new Motherboard + { + Price = 2000, + Supplier = "Company 2", + Country = "Country 2", + Name = "Motherboard 2", + RamType = "DDR3", + RamSlots = 4, + Socket = "Socket 1", + CpuSlots = 1, + PataSlots = 1, + SataSlots = 4 + }, + new Motherboard + { + Price = 3000, + Supplier = "Company 3", + Country = "Country 3", + Name = "Motherboard 3", + RamType = "DDR4", + RamSlots = 4, + Socket = "Socket 2", + CpuSlots = 1, + PataSlots = 0, + SataSlots = 4 + } +}; +} diff --git a/Lesson_3/Task_1/Lists/RamsForSale.cs b/Lesson_3/Task_1/Lists/RamsForSale.cs new file mode 100644 index 0000000..53820f7 --- /dev/null +++ b/Lesson_3/Task_1/Lists/RamsForSale.cs @@ -0,0 +1,37 @@ +namespace Lists; + +using Classes; + +class RamsForSale +{ + public List Hardware { get; set; } = new List + { + new Ram + { + Price = 1000, + Supplier = "Company 1", + Country = "Country 1", + Name = "RAM 1", + Type = "DDR2", + Size = 2048 + }, + new Ram + { + Price = 2000, + Supplier = "Company 2", + Country = "Country 2", + Name = "RAM 2", + Type = "DDR3", + Size = 4096 + }, + new Ram + { + Price = 4000, + Supplier = "Company 3", + Country = "Country 3", + Name = "RAM 3", + Type = "DDR4", + Size = 8192 + } + }; +} diff --git a/Lesson_3/Task_1/Methods/Cpu.cs b/Lesson_3/Task_1/Methods/Cpu.cs new file mode 100644 index 0000000..cca2559 --- /dev/null +++ b/Lesson_3/Task_1/Methods/Cpu.cs @@ -0,0 +1,70 @@ +namespace Methods; + +using Classes; +using Lists; + +class CpuMethods +{ + public bool PurchaseCpu(Cpu cpu, Computer computer) + { + if (cpu.Socket == computer.Motherboard.Socket && computer.Motherboard.UsedCpuSlots != computer.Motherboard.CpuSlots) + { + computer.Motherboard.UsedCpuSlots++; + computer.Cpus.Add(cpu); + computer.Price += cpu.Price; + return true; + } + return false; + } + + public void RemoveCpu(Cpu cpu, Computer computer) + { + computer.Motherboard.UsedCpuSlots--; + computer.Cpus.Remove(cpu); + computer.Price -= cpu.Price; + } + + public void DisplayCpu(Cpu cpu) + { + Console.WriteLine($"{cpu.Name} manufactured by {cpu.Supplier} from {cpu.Country}, socket {cpu.Socket}, cores: {cpu.Cores}, frequency {cpu.Frequency} MHz, costs {cpu.Price} ¤"); + } + + public void DisplayCpuList(Computer computer, List data, bool remove = false) + { + if (!data.Any()) + { + Console.WriteLine("No data available."); + return; + } + + foreach (Cpu cpu in data) + DisplayCpu(cpu); + + while (true) + { + try + { + Console.Write("Enter the CPU name: "); + string? input = Console.ReadLine(); + var selected = (from cpu in data where cpu.Name == input select cpu).First(); + if (!remove) + { + if (PurchaseCpu(selected, computer)) + Console.WriteLine("Purchased."); + else + Console.WriteLine("This CPU cannot be installed in your computer."); + } + else + { + RemoveCpu(selected, computer); + Console.WriteLine("Removed."); + } + return; + } + catch (InvalidOperationException) + { + Console.WriteLine("Not found."); + } + } + } +} diff --git a/Lesson_3/Task_1/Methods/Drive.cs b/Lesson_3/Task_1/Methods/Drive.cs new file mode 100644 index 0000000..10b65a3 --- /dev/null +++ b/Lesson_3/Task_1/Methods/Drive.cs @@ -0,0 +1,77 @@ +namespace Methods; + +using Classes; +using Lists; + +class DriveMethods +{ + public bool PurchaseDrive(Drive drive, Computer computer) + { + if ((drive.Interface == "PATA" && computer.Motherboard.UsedPataSlots != computer.Motherboard.PataSlots) || (drive.Interface == "SATA" && computer.Motherboard.UsedSataSlots != computer.Motherboard.SataSlots)) + { + if (drive.Interface == "PATA") + computer.Motherboard.UsedPataSlots++; + else + computer.Motherboard.UsedSataSlots++; + computer.Drives.Add(drive); + computer.Price += drive.Price; + return true; + } + return false; + } + + public void RemoveDrive(Drive drive, Computer computer) + { + if (drive.Interface == "PATA") + computer.Motherboard.UsedPataSlots--; + else + computer.Motherboard.UsedSataSlots--; + computer.Drives.Remove(drive); + computer.Price -= drive.Price; + } + + public void DisplayDrive(Drive drive) + { + string? SsdAdditional = drive.Lifetime != null ? $"lifetime {drive.Lifetime} TBW, " : ""; + Console.WriteLine($"{drive.Name} manufactured by {drive.Supplier} from {drive.Country}, size {drive.Size} GB, speed {drive.Speed} MB/s, interface {drive.Interface}, {SsdAdditional}costs {drive.Price} ¤"); + } + + public void DisplayDriveList(Computer computer, List data, bool remove = false) + { + if (!data.Any()) + { + Console.WriteLine("No data available."); + return; + } + + foreach (Drive drive in data) + DisplayDrive(drive); + + while (true) + { + try + { + Console.Write("Enter the drive name: "); + string? input = Console.ReadLine(); + var selected = (from drive in data where drive.Name == input select drive).First(); + if (!remove) + { + if (PurchaseDrive(selected, computer)) + Console.WriteLine("Purchased."); + else + Console.WriteLine("This drive cannot be installed in your computer."); + } + else + { + RemoveDrive(selected, computer); + Console.WriteLine("Removed."); + } + return; + } + catch (InvalidOperationException) + { + Console.WriteLine("Not found."); + } + } + } +} diff --git a/Lesson_3/Task_1/Methods/Gpu.cs b/Lesson_3/Task_1/Methods/Gpu.cs new file mode 100644 index 0000000..457fe24 --- /dev/null +++ b/Lesson_3/Task_1/Methods/Gpu.cs @@ -0,0 +1,61 @@ +namespace Methods; + +using Classes; +using Lists; + +class GpuMethods +{ + public void PurchaseGpu(Gpu gpu, Computer computer) + { + computer.Gpus.Add(gpu); + computer.Price += gpu.Price; + } + + public void RemoveGpu(Gpu gpu, Computer computer) + { + computer.Gpus.Remove(gpu); + computer.Price -= gpu.Price; + } + + public void DisplayGpu(Gpu gpu) + { + Console.WriteLine($"{gpu.Name} manufactured by {gpu.Supplier} from {gpu.Country}, memory {gpu.Memory} GB, speed {gpu.Speed} MHz, costs {gpu.Price} ¤"); + } + + public void DisplayGpuList(Computer computer, List data, bool remove = false) + { + if (!data.Any()) + { + Console.WriteLine("No data available."); + return; + } + + foreach (Gpu gpu in data) + DisplayGpu(gpu); + + while (true) + { + try + { + Console.Write("Enter the GPU name to purchase: "); + string? input = Console.ReadLine(); + var selected = (from gpu in data where gpu.Name == input select gpu).First(); + if (!remove) + { + PurchaseGpu(selected, computer); + Console.WriteLine("Purchased."); + } + else + { + RemoveGpu(selected, computer); + Console.WriteLine("Removed."); + } + return; + } + catch (InvalidOperationException) + { + Console.WriteLine("Not found."); + } + } + } +} diff --git a/Lesson_3/Task_1/Methods/Motherboard.cs b/Lesson_3/Task_1/Methods/Motherboard.cs new file mode 100644 index 0000000..2575437 --- /dev/null +++ b/Lesson_3/Task_1/Methods/Motherboard.cs @@ -0,0 +1,41 @@ +namespace Methods; + +using Classes; +using Lists; + +class MotherboardMethods +{ + public void PurchaseMotherboard(Motherboard motherboard, Computer computer) + { + computer.Motherboard = motherboard; + computer.Price += motherboard.Price; + } + + public void DisplayMotherboard(Motherboard motherboard) + { + Console.WriteLine($"{motherboard.Name} manufactured by {motherboard.Supplier} from {motherboard.Country}, RAM type {motherboard.RamType}, slots {motherboard.RamSlots}, socket {motherboard.Socket}, CPU slots {motherboard.CpuSlots}, PATA slots {motherboard.PataSlots}, SATA slots {motherboard.SataSlots}, costs {motherboard.Price} ¤"); + } + + public Motherboard DisplayMotherboardList() + { + List motherboards = (new MotherboardsForSale()).Hardware; + foreach (Motherboard motherboard in motherboards) + DisplayMotherboard(motherboard); + while (true) + { + try + { + Console.Write("Enter the motherboard name to purchase: "); + string? input = Console.ReadLine(); + var selected = (from motherboard in motherboards where motherboard.Name == input select motherboard).First(); + Console.WriteLine("Purchased."); + return selected; + } + catch (InvalidOperationException) + { + Console.WriteLine("Not found."); + } + } + } + +} diff --git a/Lesson_3/Task_1/Methods/Ram.cs b/Lesson_3/Task_1/Methods/Ram.cs new file mode 100644 index 0000000..de061d5 --- /dev/null +++ b/Lesson_3/Task_1/Methods/Ram.cs @@ -0,0 +1,70 @@ +namespace Methods; + +using Classes; +using Lists; + +class RamMethods +{ + public bool PurchaseRam(Ram ram, Computer computer) + { + if (ram.Type == computer.Motherboard.RamType && computer.Motherboard.UsedRamSlots != computer.Motherboard.RamSlots) + { + computer.Motherboard.UsedRamSlots++; + computer.Rams.Add(ram); + computer.Price += ram.Price; + return true; + } + return false; + } + + public void RemoveRam(Ram ram, Computer computer) + { + computer.Motherboard.UsedRamSlots--; + computer.Rams.Remove(ram); + computer.Price -= ram.Price; + } + + public void DisplayRam(Ram ram) + { + Console.WriteLine($"{ram.Name} manufactured by {ram.Supplier} from {ram.Country}, type {ram.Type}, size {ram.Size} GB, costs {ram.Price} ¤"); + } + + public void DisplayRamList(Computer computer, List data, bool remove = false) + { + if (!data.Any()) + { + Console.WriteLine("No data available."); + return; + } + + foreach (Ram ram in data) + DisplayRam(ram); + + while (true) + { + try + { + Console.Write("Enter the RAM name: "); + string? input = Console.ReadLine(); + var selected = (from ram in data where ram.Name == input select ram).First(); + if (!remove) + { + if (PurchaseRam(selected, computer)) + Console.WriteLine("Purchased."); + else + Console.WriteLine("This RAM cannot be installed in your computer."); + } + else + { + RemoveRam(selected, computer); + Console.WriteLine("Removed."); + } + return; + } + catch (InvalidOperationException) + { + Console.WriteLine("Not found."); + } + } + } +} diff --git a/Lesson_3/Task_1/Program.cs b/Lesson_3/Task_1/Program.cs new file mode 100644 index 0000000..93ad28b --- /dev/null +++ b/Lesson_3/Task_1/Program.cs @@ -0,0 +1,49 @@ +using Classes; +using Lists; +using Methods; + +int money; + +while (true) +{ + Console.Write("Enter how much money you can afford to spend: "); + if (int.TryParse(Console.ReadLine(), out money)) + break; +} + +Console.WriteLine("Choose a motherboard first."); +Motherboard motherboard = (new MotherboardMethods()).DisplayMotherboardList(); +Computer computer = new Computer(motherboard); + +while (true) +{ + int choice; + Console.WriteLine("RAMs [1]\nCPUs [2]\nGPUs [3]\nDrives [4]\nCheckout [5]\nQuit [6]"); + Console.Write("Enter a number: "); + if (int.TryParse(Console.ReadLine(), out choice)) + { + switch (choice) + { + case 1: + (new RamMethods()).DisplayRamList(computer, (new RamsForSale()).Hardware); + break; + case 2: + (new CpuMethods()).DisplayCpuList(computer, (new CpusForSale()).Hardware); + break; + case 3: + (new GpuMethods()).DisplayGpuList(computer, (new GpusForSale()).Hardware); + break; + case 4: + (new DriveMethods()).DisplayDriveList(computer, (new DrivesForSale()).Hardware); + break; + case 5: + computer.Checkout(money); + break; + case 6: + goto Exit; + } + } +} + +Exit: + Console.WriteLine("Goodbye."); diff --git a/Lesson_3/Task_1/Task_1.csproj b/Lesson_3/Task_1/Task_1.csproj new file mode 100644 index 0000000..f02677b --- /dev/null +++ b/Lesson_3/Task_1/Task_1.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + +