static void Main(string[] args) { // create new cd object (register) CD cd = new CD(); cd.Artist = "Sanni"; cd.Price = 25; // create new song object Song song = new Song(); song.Name = "Supernova"; song.Length = 210; Song song1 = new Song(); song1.Name = "Jos mä oon oikee"; song1.Length = 190; Song song2 = new Song(); song2.Name = "2080-luvulla"; song2.Length = 180; // add songs to cd cd.AddSong(song); cd.AddSong(song1); cd.AddSong(song2); // get one song from cd Song songget = cd.GetSong(0);// index = 0 cd.PrintData(); if (songget != null) { Console.WriteLine("First song in my cd is " + songget.ToString()); } else { Console.WriteLine("Can't find song in that index"); } Console.WriteLine(); string name = "2080-luvulla"; Console.WriteLine("Finding song with name: " + name); Song song5 = cd.FindSong(name); if (song5 != null) { Console.WriteLine(song5.ToString()); } else { Console.WriteLine("Can't find song with that name"); } Console.ReadLine(); }
static void Main(string[] args) { CD metal = new CD(); Song song1 = new Song { Name = "One", Artist = "Metallica", Length = 9, Price = "0.99e" }; Song song2 = new Song { Name = "Run to the Hills", Artist = "Iron Maiden", Length = 8, Price = "0.87e" }; Song song3 = new Song { Name = "Holy Diver", Artist = "Dio", Length = 6, Price = "0.55e" }; Song song4 = new Song { Name = "Nightmare", Artist = "Avenged Sevenfold", Length = 7, Price = "1.23e" }; Song song5 = new Song { Name = "Dystopia", Artist = "Megadeath", Length = 6, Price = "1.99e" }; metal.AddSong(song1); metal.AddSong(song2); metal.AddSong(song3); metal.AddSong(song4); metal.AddSong(song5); metal.PrintCollection(); Console.WriteLine("Pick a song from the CD: "); Song song6 = metal.GetSong(1); }