Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- // Гогарев Игорь БПИ 195_2 Вариант 13
- namespace ConsoleApp1
- {
- class Car
- {
- string name;
- int maxSpeed;
- public bool IsFast
- {
- get
- {
- if (maxSpeed >= 150)
- {
- return true;
- }
- return false;
- }
- }
- public Car(string name, int maxSpeed)
- {
- this.name = name;
- this.maxSpeed = maxSpeed;
- }
- public override string ToString()
- {
- return $"Название машины: {name}, макисмальная скорость: {maxSpeed}, свойство IsFast: {IsFast}";
- }
- }
- class Program
- {
- static Random rnd = new Random();
- static void Main()
- {
- do
- {
- try
- {
- int N;
- int count = 0;
- string name = "Car ";
- do
- {
- Console.WriteLine("Введите число N");
- } while (!int.TryParse(Console.ReadLine(), out N) | N < 1);
- Car[] array = new Car[N];
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = new Car(name + $"{i + 1}", rnd.Next(100, 200));
- Console.WriteLine(array[i]);
- if (array[i].IsFast)
- {
- count += 1;
- }
- }
- Console.WriteLine("Количество быстрых машин: " + count);
- Console.WriteLine("Для завершения программы введите ESCAPE, для продолжения - ENTER.");
- }
- catch (Exception e) {
- Console.WriteLine(e.Message);
- }
- } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement