public static int CountOfLess35Captain(Port port) { int sum = 0; for (int i = 0; i < port.elems.Count; i++) { // лучше не придумал if (port.elems[i] is Boat) { Boat boat = new Boat(); boat = (Boat)port.elems[i]; if (boat.CaptainAge < 35) { sum += 1; } } if (port.elems[i] is Corvette) { Corvette corvette = new Corvette(); corvette = (Corvette)port.elems[i]; if (corvette.CaptainAge < 35) { sum += 1; } } if (port.elems[i] is Sailboat) { Sailboat sailboat = new Sailboat(); sailboat = (Sailboat)port.elems[i]; if (sailboat.CaptainAge < 35) { sum += 1; } } if (port.elems[i] is Ship) { Ship ship = new Ship(); ship = (Ship)port.elems[i]; if (ship.CaptainAge < 35) { sum += 1; } } if (port.elems[i] is Streamer) { Streamer streamer = new Streamer(); streamer = (Streamer)port.elems[i]; if (streamer.CaptainAge < 35) { sum += 1; } } } return(sum); }
static void Main(string[] args) { Boat boat = new Boat("Pobeda", 12); Corvette corvette = new Corvette("Beda", 10); Sailboat sailboat = new Sailboat("Ne Beda", 5, 30); Sailboat sailboat2 = new Sailboat("Ne LeBeda", 5, 60); Sailboat sailboat3 = new Sailboat("LeBeda", 5, 90); Ship ship = new Ship("Bedi s bashkoi", 18); Streamer streamer = new Streamer("Po obedal", 4, 20); Streamer streamer2 = new Streamer("Po obedal", 4, 40); Test test = new Test(); Car car = new Car(); Train train = new Train(); //задание 4 OutEx4 outex4; outex4.showInform(); // задание 5 if (boat is Car) { Console.WriteLine("\nboat is car"); } else { Console.WriteLine("\nboat is not car"); }; if (car is Car) { Console.WriteLine("car is car\n"); } else { Console.WriteLine("car is not car\n"); }; //ссылка на интерфейс Interface1 Itest; Itest = test as Test; TransportEl[] arr = { boat, corvette, ship, sailboat, streamer }; Printer printer = new Printer(); foreach (object obj in arr) { printer.IAmPrinting(obj); } //lab6 Console.WriteLine($"Average displacement on silboats -- {Control.AverageDisplacementOnSailboats()}"); Console.WriteLine($"Average seats number on streamers -- {Control.AverageSeats()}"); boat.captain.age = 12; ship.captain.age = 27; corvette.captain.age = 44; sailboat.captain.age = 19; streamer.captain.age = 77; Port port = new Port(); port.Add(boat); port.Add(ship); port.Add(corvette); port.Add(sailboat); port.Add(streamer); port.Add(streamer2); port.Remove(streamer2); Control control; Console.WriteLine($"Number of captains with age less then 35 -- {Control.CountOfLess35Captain(port)}\n"); //Lab7 try { int a = 100; int b = a / 0; } catch (DivideByZeroException ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.Source); Console.WriteLine(ex.TargetSite + "\n"); } try { int[] array = new int[10]; array[20] = 20; } catch (IndexOutOfRangeException ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.TargetSite + "\n"); } try { if (TransportEl.SailboatsCount > 2) { throw new SailboatsOverflow(sailboat); } } catch (SailboatsOverflow ex) { Console.WriteLine(ex.Message); Console.WriteLine($"Source: {ex.Source}\n"); } try { new OutOfRangeExceptions(boat.captain.age, boat); new OutOfRangeExceptions(sailboat.captain.age, sailboat); new OutOfRangeExceptions(ship.captain.age, ship); new OutOfRangeExceptions(corvette.captain.age, corvette); new OutOfRangeExceptions(streamer.captain.age, streamer); } catch { } int flag = 0; try { void Test(int num) { if (num < 4) { flag = 1; throw new OOP_Lab7.MyExceptions.ArgumentException(); } } Test(3); } catch (OOP_Lab7.MyExceptions.ArgumentException ex) { Console.WriteLine(ex.Message); } finally { if (flag == 0) { Console.WriteLine("test passed"); } } int MyCourse = 2; Debug.Assert(MyCourse == 3, "LOL, u on the second course, boy"); }
static void Main(string[] args) { Boat boat = new Boat("Pobeda", 12); Corvette corvette = new Corvette("Beda", 10); Sailboat sailboat = new Sailboat("Ne Beda", 5, 30); Sailboat sailboat2 = new Sailboat("Ne LeBeda", 5, 60); Sailboat sailboat3 = new Sailboat("LeBeda", 5, 90); Ship ship = new Ship("Bedi s bashkoi", 18); Streamer streamer = new Streamer("Po obedal", 4, 20); Streamer streamer2 = new Streamer("Po obedal", 4, 40); Test test = new Test(); Car car = new Car(); Train train = new Train(); //задание 4 OutEx4 outex4; outex4.showInform(); // задание 5 if (boat is Car) { Console.WriteLine("\nboat is car"); } else { Console.WriteLine("\nboat is not car"); }; if (car is Car) { Console.WriteLine("car is car\n"); } else { Console.WriteLine("car is not car\n"); }; //ссылка на интерфейс Interface1 Itest; Itest = test as Test; TransportEl[] arr = { boat, corvette, ship, sailboat, streamer }; Printer printer = new Printer(); foreach (object obj in arr) { printer.IAmPrinting(obj); } //lab6 Console.WriteLine($"Average displacement on silboats -- {Control.AverageDisplacementOnSailboats()}"); Console.WriteLine($"Average seats number on streamers -- {Control.AverageSeats()}"); boat.captain.age = 12; ship.captain.age = 27; corvette.captain.age = 44; sailboat.captain.age = 19; streamer.captain.age = 77; Port port = new Port(); port.Add(boat); port.Add(ship); port.Add(corvette); port.Add(sailboat); port.Add(streamer); port.Add(streamer2); port.Remove(streamer2); Control control; Console.WriteLine($"Number of captains with age less then 35 -- {Control.CountOfLess35Captain(port)}"); }