Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2.  
  3. // Гогарев Игорь БПИ 195_2 Вариант 13
  4.  
  5. namespace ConsoleApp1
  6. {
  7.     class Car
  8.     {
  9.         string name;
  10.         int maxSpeed;
  11.         public bool IsFast
  12.         {
  13.             get
  14.             {
  15.                 if (maxSpeed >= 150)
  16.                 {
  17.                     return true;
  18.                 }
  19.                 return false;
  20.             }
  21.         }
  22.         public Car(string name, int maxSpeed)
  23.         {
  24.             this.name = name;
  25.             this.maxSpeed = maxSpeed;
  26.         }
  27.         public override string ToString()
  28.         {
  29.             return $"Название машины: {name}, макисмальная скорость: {maxSpeed}, свойство IsFast: {IsFast}";
  30.         }
  31.     }
  32.  
  33.     class Program
  34.     {
  35.         static Random rnd = new Random();
  36.         static void Main()
  37.         {
  38.             do
  39.             {
  40.                 try
  41.                 {
  42.                     int N;
  43.                     int count = 0;
  44.                     string name = "Car ";
  45.                     do
  46.                     {
  47.                         Console.WriteLine("Введите число N");
  48.                     } while (!int.TryParse(Console.ReadLine(), out N) | N < 1);
  49.                     Car[] array = new Car[N];
  50.                     for (int i = 0; i < array.Length; i++)
  51.                     {
  52.                         array[i] = new Car(name + $"{i + 1}", rnd.Next(100, 200));
  53.                         Console.WriteLine(array[i]);
  54.                         if (array[i].IsFast)
  55.                         {
  56.                             count += 1;
  57.                         }
  58.                     }
  59.                     Console.WriteLine("Количество быстрых машин: " + count);
  60.                     Console.WriteLine("Для завершения программы введите ESCAPE, для продолжения - ENTER.");
  61.                 }
  62.                 catch (Exception e) {
  63.                     Console.WriteLine(e.Message);
  64.                 }
  65.             } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement