Advertisement
4DM3M

12

Jan 3rd, 2022
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Drafty
  5. {
  6.     class Program
  7.     {
  8.         class Continent
  9.         {
  10.             public string Name { get; set; }
  11.  
  12.             public double square { get; set; }
  13.  
  14.             public Continent(string name, double square = 1000)
  15.             {
  16.                 this.Name = name;
  17.                 this.square = square;
  18.             }
  19.  
  20.             public void GetInfo()
  21.             {
  22.                 Console.WriteLine($"Continent name: {this.Name}, square: {this.square}");
  23.             }
  24.         }
  25.  
  26.         class Ocean
  27.         {
  28.             public string Name { get; set; }
  29.         }
  30.  
  31.         class Island
  32.         {
  33.             public string Name { get; set; }
  34.  
  35.             public int Population { get; set; }
  36.         }
  37.  
  38.         class Planet
  39.         {
  40.             List<Continent> conCount;
  41.  
  42.             public string Name { get; private set; }
  43.  
  44.             public Planet(string name, int continentsCount)
  45.             {
  46.                 this.Name = name;
  47.                 this.conCount = new List<Continent>();
  48.  
  49.                 for (int i=0; i<continentsCount; i++)
  50.                 {
  51.                     AddContinent("какой-то континент");
  52.                 }
  53.             }
  54.            
  55.             public void GetInfo()
  56.             {
  57.                 Console.WriteLine($"Планета: {this.Name}, количество материков: {this.conCount.Count}");
  58.             }
  59.  
  60.             public void AddContinent(string name, double square = 1000)
  61.             {
  62.                 this.conCount.Add(new Continent(name, square));
  63.             }
  64.  
  65.             public void AddContinent(params string[] name)
  66.             {
  67.                 for (int i=0; i<name.Length; i++)
  68.                 {
  69.                     this.conCount.Add(new Continent(name[i]));
  70.                 }
  71.             }
  72.  
  73.             public void GetContinentName(int index)
  74.             {
  75.                 if (index >= this.conCount.Count || index < 0)
  76.                 {
  77.                     Console.WriteLine("Такого континента нет");
  78.                     return;
  79.                 }
  80.  
  81.                 Console.WriteLine($"Континент: {this.conCount[index].Name}");
  82.             }
  83.         }
  84.  
  85.  
  86.         static void Main(string[] args)
  87.         {
  88.             Planet earth = new Planet("earth", 0);
  89.             earth.AddContinent("Asia", "Africa", "North America", "South America", "Antarctida", "Europe", "Australia");
  90.  
  91.             earth.GetContinentName(2);
  92.             earth.GetInfo();
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement