Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace BusLib
- {
- public abstract class BaseBus
- {
- protected string model;
- 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'};
- public string Model
- {
- get
- {
- return model;
- }
- set
- {
- if (model.Length < 5)
- {
- foreach(char i in model)
- {
- if (AllowedSymbols.Contains(i))
- {
- continue;
- }
- else
- {
- throw new ArgumentException($"Model {model} is not allowed");
- }
- }
- }
- else
- {
- throw new ArgumentException($"Model {model} is not allowed");
- }
- }
- }
- protected double power;
- public double Power
- {
- get
- {
- return power;
- }
- set
- {
- if (power < 50)
- {
- throw new ArgumentException("Power cannot be less 50 h.p.");
- }
- else
- {
- power = value;
- }
- }
- }
- protected uint seatCount;
- public uint SeatCount
- {
- get
- {
- return seatCount;
- }
- set
- {
- if (seatCount < 8)
- {
- throw new ArgumentException("Bus cannot have less than 8 seats");
- }
- else
- {
- seatCount = value;
- }
- }
- }
- public override string ToString()
- {
- return $"Model: {model}; Power: {power}; SeatCount {seatCount}.";
- }
- abstract public int Transport();
- public BaseBus(string model, int power, uint seatCount)
- {
- this.model = model;
- this.power = power;
- this.seatCount = seatCount;
- }
- }
- public class BigBus: BaseBus
- {
- public BigBus(string model, int power, uint seatCount) : base(model, power, seatCount)
- {
- this.model = model;
- this.power = power;
- this.seatCount = seatCount;
- }
- public override string ToString()
- {
- return "BigBus"+base.ToString();
- }
- public override int Transport()
- {
- Random rnd = new Random();
- int RandomPassengers = rnd.Next(1, (int)SeatCount+1);
- Console.WriteLine($"BigBus {Model} transported {RandomPassengers} passengers");
- return RandomPassengers;
- }
- }
- public class MiniBus: BaseBus
- {
- public MiniBus(string model, int power, uint seatCount) : base(model, power, seatCount)
- {
- this.model = model;
- this.power = power;
- this.seatCount = seatCount;
- }
- public override string ToString()
- {
- return "MiniBus" + base.ToString();
- }
- public override int Transport()
- {
- Console.WriteLine($"MiniBus {Model}(with power {Power}) transported {SeatCount} passengers");
- return (int)SeatCount;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement