static void Main(string[] args) { List <Matrjoshka> boxOfMatrjoshkas = new List <Matrjoshka>(); Matrjoshka matrjoshka1 = new Matrjoshka("Matrjoshka1", "green", 10, "image1"); boxOfMatrjoshkas.Add(matrjoshka1); //Open Matrjoshkas Matrjoshka matrjoshka2 = matrjoshka1.OpenMatrjoshka("Matrjoshka2", "orange", "image2"); boxOfMatrjoshkas.Add(matrjoshka2); Matrjoshka matrjoshka3 = matrjoshka2.OpenMatrjoshka("Matrjohka3", "pink", "image3"); boxOfMatrjoshkas.Add(matrjoshka3); Matrjoshka matrjoshka4 = matrjoshka3.OpenMatrjoshka("Matrjohka4", "yellow", "image4"); boxOfMatrjoshkas.Add(matrjoshka4); Matrjoshka matrjoshka5 = matrjoshka4.OpenMatrjoshka("Matrjohka5", "blue", "image5"); boxOfMatrjoshkas.Add(matrjoshka5); foreach (Matrjoshka matrjoshka in boxOfMatrjoshkas) { Console.WriteLine($"A {matrjoshka.Color} {matrjoshka.Name} size {matrjoshka.Size} is in the box."); } Console.WriteLine($"There are {Matrjoshka.Count} matrjoshkas in the box."); //Take a matrjoshka from the box Console.WriteLine("What color matrjoshka would you take from the box?"); string userInput = Console.ReadLine(); for (int i = 0; i < boxOfMatrjoshkas.Count; i++) { if (boxOfMatrjoshkas[i].Color == userInput) { Console.WriteLine($"You have taken {boxOfMatrjoshkas[i].Name} from the box."); boxOfMatrjoshkas.Remove(boxOfMatrjoshkas[i]); Matrjoshka.Count--; break; } } Console.WriteLine(); foreach (Matrjoshka matrjoshka in boxOfMatrjoshkas) { Console.WriteLine($"Name:{matrjoshka.Name}, color: {matrjoshka.Color} is in the box"); } Console.WriteLine($"There are {Matrjoshka.Count} matrjoshkas in the box."); Console.ReadLine(); }
static void Main(string[] args) { List <Matrjoshka> boxOfMatrjoshkas = new List <Matrjoshka>(); Matrjoshka matrjoshka1 = new Matrjoshka("Matrjoshka1", "blue", 10, "image1"); //loome matrjoshka boxOfMatrjoshkas.Add(matrjoshka1); //open matrjoshkas Matrjoshka matrjoshka2 = matrjoshka1.OpenMatrjoshka("Matrjoshka2", "orange", "image2"); //paneme meetodi tööle mis loob uue matrjoshka matrjoshka1-st boxOfMatrjoshkas.Add(matrjoshka2); Matrjoshka matrjoshka3 = matrjoshka2.OpenMatrjoshka("Matrjoshka3", "red", "image3"); boxOfMatrjoshkas.Add(matrjoshka3); Matrjoshka matrjoshka4 = matrjoshka3.OpenMatrjoshka("Matrjoshka4", "black", "image4"); boxOfMatrjoshkas.Add(matrjoshka4); Matrjoshka matrjoshka5 = matrjoshka4.OpenMatrjoshka("Matrjoshka5", "purple", "image5"); boxOfMatrjoshkas.Add(matrjoshka5); foreach (Matrjoshka matrjoshka in boxOfMatrjoshkas) //matrjoska boxofmatrjoshka listis { Console.WriteLine($"A {matrjoshka.Color} {matrjoshka.Name} size {matrjoshka.Size} is in the box"); } Console.WriteLine($"There are {Matrjoshka.Count} matrjoshkas in the box"); Console.WriteLine("What color matrjoshka would you take from the box"); string userInput = Console.ReadLine(); for (int i = 0; i < boxOfMatrjoshkas.Count; i++) // count- gets number of elemnts conatined in the list { if (boxOfMatrjoshkas[i].Color == userInput) { Console.WriteLine($"You have taken {boxOfMatrjoshkas[i].Name} from the box"); boxOfMatrjoshkas.Remove(boxOfMatrjoshkas[i]); Matrjoshka.Count--; break; } } foreach (Matrjoshka matrjoshka in boxOfMatrjoshkas) { Console.WriteLine($"A {matrjoshka.Color} {matrjoshka.Name} size {matrjoshka.Size} is in the box"); } Console.WriteLine($"There are {Matrjoshka.Count} matrjoshkas in the box"); Console.ReadLine(); }
public Matrjoshka OpenMatrjoshka(string name, string color, string image) { Matrjoshka newMatrjoshka = new Matrjoshka(name, color, size - 2, image); return(newMatrjoshka); }
public Matrjoshka OpenMatrjoshka(string _name, string _color, string _image) { Matrjoshka newMatrjoshka = new Matrjoshka(_name, _color, size - 2, _image); return(newMatrjoshka); }