Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace BusLib
  8. {
  9.     public abstract class BaseBus
  10.     {
  11.         protected string model;
  12.         private List <char> AllowedSymbols = new List<char> {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','W','Z'};
  13.         public string Model
  14.         {
  15.             get
  16.             {
  17.                 return model;
  18.             }
  19.             set
  20.             {
  21.                 if (model.Length < 5)
  22.                 {
  23.                     foreach(char i in model)
  24.                     {
  25.                         if (AllowedSymbols.Contains(i))
  26.                         {
  27.                             continue;
  28.                         }
  29.                         else
  30.                         {
  31.                             throw new ArgumentException($"Model {model} is not allowed");
  32.                         }
  33.                     }
  34.                 }
  35.                 else
  36.                 {
  37.                     throw new ArgumentException($"Model {model} is not allowed");
  38.                 }
  39.             }
  40.         }
  41.         protected double power;
  42.         public double Power
  43.         {
  44.             get
  45.             {
  46.                 return power;
  47.             }
  48.             set
  49.             {
  50.                 if (power < 50)
  51.                 {
  52.                     throw new ArgumentException("Power cannot be less 50 h.p.");
  53.                 }
  54.                 else
  55.                 {
  56.                     power = value;
  57.                 }
  58.             }
  59.         }
  60.         protected uint seatCount;
  61.         public uint SeatCount
  62.         {
  63.             get
  64.             {
  65.                 return seatCount;
  66.             }
  67.             set
  68.             {
  69.                 if (seatCount < 8)
  70.                 {
  71.                     throw new ArgumentException("Bus cannot have less than 8 seats");
  72.                 }
  73.                 else
  74.                 {
  75.                     seatCount = value;
  76.                 }
  77.             }
  78.         }
  79.         public override string ToString()
  80.         {
  81.             return $"Model: {model}; Power: {power}; SeatCount {seatCount}.";
  82.         }
  83.         abstract public int Transport();
  84.         public BaseBus(string model, int power, uint seatCount)
  85.         {
  86.             this.model = model;
  87.             this.power = power;
  88.             this.seatCount = seatCount;
  89.         }
  90.     }
  91.     public class BigBus: BaseBus
  92.     {
  93.         public BigBus(string model, int power, uint seatCount) : base(model, power, seatCount)
  94.         {
  95.             this.model = model;
  96.             this.power = power;
  97.             this.seatCount = seatCount;
  98.         }
  99.         public override string ToString()
  100.         {
  101.             return "BigBus"+base.ToString();
  102.         }
  103.         public override int Transport()
  104.         {
  105.             Random rnd = new Random();
  106.             int RandomPassengers = rnd.Next(1, (int)SeatCount+1);
  107.             Console.WriteLine($"BigBus {Model} transported {RandomPassengers} passengers");
  108.             return RandomPassengers;
  109.         }
  110.     }
  111.     public class MiniBus: BaseBus
  112.     {
  113.         public MiniBus(string model, int power, uint seatCount) : base(model, power, seatCount)
  114.         {
  115.             this.model = model;
  116.             this.power = power;
  117.             this.seatCount = seatCount;
  118.         }
  119.         public override string ToString()
  120.         {
  121.             return "MiniBus" + base.ToString();
  122.         }
  123.         public override int Transport()
  124.         {
  125.             Console.WriteLine($"MiniBus {Model}(with power {Power}) transported {SeatCount} passengers");
  126.             return (int)SeatCount;
  127.         }
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement