Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Lab7
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { var Factory = new FactoryAF(); Factory.CreateCars(4); // создаем 4 автомобиля var c1 = new Customer("Иван"); Factory.Customers.Add(c1); var c2 = new Customer("Кот Виктор"); Factory.Customers.Add(c2); var c3 = new Customer("Петр"); Factory.Customers.Add(c3); var c4 = new Customer("Надежда"); Factory.Customers.Add(c4); var c5 = new Customer("Владислав"); Factory.Customers.Add(c5); Console.WriteLine("Покупатели:"); foreach(Customer c in Factory.Customers){ Console.WriteLine(c.Name); } Console.WriteLine("Автомобилей на складе: {0}", Factory.CarsInfo()); Factory.SaleCars(); Console.WriteLine("\n╔╗ ╔╗ ╔ ╔╗ ╔╗ ╔╗ ╔╗ ╔╗ ╗║╔ ╔╗\n║║ ╠╣ ║ ║║ ║║ ║║ ║║ ╠╣ ╠╬╣ ╠╣\n╠╝ ║║ ╚ ║║ ╠╝ ╚╝ ╩╩ ║║ ╝║╚ ║║\n\n╔╗ ╔╗ ╔╗ ║║║ ╔╗ ╔╗\n║║ ║║ ║║ ║║║ ║║ ╠╣\n║║ ╠╝ ╚╝ ╚╩╝ ╝║ ║║\n\nПокупатели:"); foreach(Customer c in Factory.Customers){ if(c.CustomerCar == null){Console.WriteLine("{0} не приобрел(а) автомобиль", c.Name);} else{Console.WriteLine("{0} приобрел(а) автомобиль с номером {1}",c.Name, c.CustomerCar.Number);} } Console.WriteLine("Автомобилей на складе: {0}", Factory.CarsInfo()); } } public class Engine { public Engine(int size){ Size = size; } public int Size; } public class Car { public Car(int number){ Number = number; e = new Engine(5); } public Engine e; public int Number; } public class Customer { public Customer(string name){ Name = name; } public Car CustomerCar; public string Name; } public class FactoryAF { private List<Car> Cars = new List<Car>(); public List<Customer> Customers = new List<Customer>(); public void SaleCars(){ foreach(Customer c in Customers){ c.CustomerCar = Cars.FirstOrDefault(); Cars.Remove(Cars.FirstOrDefault()); } Cars.Clear(); } public void CreateCars(int count){ for(int number = 1; number<=count; number++){ Cars.Add(new Car(number)); } } public int CarsInfo(){ return Cars.Count; } } }
run
|
edit
|
history
|
help
0
n!/x*x
exception implicit toString
Saga name NLog
sdefuy6j87uytgraxsd
base exterior
Cells with Odd Values in a Matrix
Fibonachi
Abstract Class
Fórum ➡ Finding STRONG tags that contain UL tags, using Regex class♦
Complex Variable Implementation in C#