Beispiel #1
0
        static void Main(string[] args)
        {
            Init();// this method fills the arrays above with data

            // - print the mass of the earth on July 1895 XD

            /*
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░
             *  ░░███████░░░░░░░░░░███▒▒▒▒▒▒▒▒███░░░░░░
             *  ░░█▒▒▒▒▒▒█░░░░░░░███▒▒▒▒▒▒▒▒▒▒▒▒███░░░░
             *  ░░░█▒▒▒▒▒▒█░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░
             *  ░░░░█▒▒▒▒▒█░░░██▒▒▒▒▄██▄▒▒▒▒▄██▄▒▒▒███░
             *  ░░░░░█▒▒▒█░░░█▒▒▒▒▒▒████▒▒▒▒████▒▒▒▒▒██
             *  ░░░█████████████▒▒▒▒▀██▀▒▒▒▒▀██▀▒▒▒▒▒██
             *  ░░░█▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒██
             *  ░██▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒██▒▒▒▒▒▒▒▒▒██▒▒▒▒██
             *  ██▒▒▒███████████▒▒▒▒▒██▒▒▒▒▒▒▒██▒▒▒▒▒██
             *  █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒███████▒▒▒▒▒▒▒██
             *  ██▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░
             *  ░█▒▒▒███████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░░
             *  ░██▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░░░░░
             *  ░░████████████░░░████████████████░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░▄█████▄░▄███████▄░▄███████▄░██████▄░░
             *  ░░██▒▒▒▒█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░██▒▒▒▒▒░██▒▒▒▒▒██░██▒▒▒▒▒██░██▒▒▒██░░
             *  ░░██▒▒▒▀█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░▀█████▀░▀███████▀░▀███████▀░██████▀░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░▄█████░██▒▒▒▒██▀░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▀▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▒▒▒▒░█████▀░░░░░░░
             *  ░░░░██▒▒▒▒░██▄▒▄██░██▄▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░▀█████░▀█████▀░▀█████░██▒▒▒▒██▄░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             */

            // QUERIES!

            // - how many Songs start with the letter 'a' (case insensitive)
            // - how many artists end with letter 'a' (case insensitive)
            // - whats the name of the song with longest duration
            // - whats the total Duration of all Songs
            // - how many albums have Songs longer than 300 seconds
            // - print the names of the artists(separated with "--"), that have more than one album of PopRock genre
            // - print the name of the album that has highest Average duration of a song
            // - how many characters has the song that has the shortest Duration
            // - print the name and the genre of the album that has most songs
            // - print the name of the artist that has most songs
            // - print the type of the artist(SoloArtist/Band) that has most albums published before year 2000
            // - print the average song duration, of the album that has most songs

            // Bonus:
            // - print the longest song duration of the album that has least songs
            // - print the name of the album that has most songs that contain letter 'a' in the name
            // - print the name of the artist that has most songs that end with letter 'd'



            // ************ Don't mind the structure, focus on the lists declared on the beginning of Program.cs ****************

            // 3, 2, 1.... GO! :)



            Console.ForegroundColor = ConsoleColor.Green;


            // 1. How many Songs start with the letter 'a' (case insensitive)

            int songsWithA = Songs.Where(song => song.Name.ToLower().StartsWith('a')).Count();

            Console.WriteLine($"{songsWithA} Songs start with the letter 'a'");



            Console.WriteLine(new string('-', 60));



            // 2. How many artists end with letter 'a'(case insensitive)
            List <Artist> artistsEndWithA = Artists.Where(artist => artist.FullName.EndsWith('a')).ToList();

            artistsEndWithA.ForEach(artist => Console.WriteLine($"{artist.FullName.Length} artists end with letter 'a'. "));



            Console.WriteLine(new string('-', 60));



            // 3. Whats the name of the song with longest duration
            double longestDurationOf = Songs.Max(x => x.Duration);

            var longestDurationSong = Songs
                                      .Where(song => song.Duration == longestDurationOf)
                                      .Select(x => new { x.Name, x.Duration })
                                      .FirstOrDefault();

            Console.WriteLine($"The name of song with longest duration is: {longestDurationSong.Name} - {longestDurationSong.Duration} duration");



            Console.WriteLine(new string('-', 60));



            // 4. Whats the total Duration of all Songs
            double totalDurationOf = Songs.Sum(x => x.Duration);

            Console.WriteLine($"Total duration of All songs is - {totalDurationOf}");



            Console.WriteLine(new string('-', 60));



            // 5. How many albums have Songs longer than 300 seconds
            var songsLongerThan = Albums.Where(x => x.Songs.Max(x => x.Duration > 300)).Select(x => x.Name).Count();

            Console.WriteLine($"{songsLongerThan} albums have Songs longer than 300 seconds.");



            Console.WriteLine(new string('-', 60));



            // 6. Print the names of the artists(separated with "--"), that have more than one album of PopRock genre
            List <Artist> popRockArtists = Artists.Where(x => x.Albums.Max(x => x.Genre.Equals(Genre.PopRock))).ToList();

            Console.WriteLine("Pop Rock Artists Name: \n");
            popRockArtists.ForEach(x => Console.Write($"-- {x.FullName} \n"));



            Console.WriteLine(new string('-', 60));



            //7. Print the name of the album that has highest Average duration of a song
            var printAlbum = Albums.OrderByDescending(x => x.Songs.Average(x => x.Duration)).First();

            Console.WriteLine($"The name of the album that has highest Average duration of a song is {printAlbum.Name}.");



            Console.WriteLine(new string('-', 60));



            // 8. How many characters has the song that has the shortest Duration
            double shortSong = Songs.Min(x => x.Duration);

            var shortestDuration = Songs
                                   .Where(song => song.Duration == shortSong)
                                   .Select(x => x.Name)
                                   .SingleOrDefault();

            Console.WriteLine($"The Song with shortest duration have {shortestDuration.Length} characters");



            Console.WriteLine(new string('-', 60));



            // 9. Print the name and the genre of the album that has most songs
            double mostSongs = Albums.Max(x => x.Songs.Count);

            var mostSongsAlbum = Albums.Where(album => album.Songs.Count == mostSongs)
                                 .Select(x => new { x.Name, x.Genre })
                                 .SingleOrDefault();

            Console.WriteLine($"Name and the genre of the album that has most songs is {mostSongsAlbum.Name} - {mostSongsAlbum.Genre} Genre");



            Console.WriteLine(new string('-', 60));



            //10. Print the name of the artist that has most songs
            var songs = Albums.Max(x => x.Songs.Count);

            var mostSongsArtist = Artists.Where(x => x.Albums.Max(x => x.Songs.Count == songs))
                                  .Select(x => x.FullName)
                                  .SingleOrDefault();


            Console.WriteLine($"The name of the artist that has most songs is {mostSongsArtist}");



            Console.WriteLine(new string('-', 60));



            // 11. Print the type of the artist(SoloArtist/Band) that has most albums published before year 2000
            var albumYear = Albums.Where(x => x.Year < 2000)
                            .Select(x => x.Year)
                            .ToList();

            var printArtist = Artists.Where(x => x.Albums.Max(x => x.Name)
                                            .Equals(albumYear))
                              .Select(x => x.ArtistType)
                              .SingleOrDefault();


            Console.WriteLine($"Type of the artist that has most albums published before year 2000 is ({printArtist})");



            Console.WriteLine(new string('-', 60));



            // 12. Print the average song duration, of the album that has most songs
            double averageSongDuration = Albums.Max(x => x.Songs.Average(x => x.Duration));

            Console.WriteLine($"Average song duration of the album that has most songs is - {averageSongDuration}");


            //var averageSongDuration = Albums.OrderByDescending(a => a.Songs.Count)
            //                          .Select(a => a.Songs.Average(s => s.Duration))
            //                          .FirstOrDefault();
            //Console.WriteLine(averageSongDuration);



            Console.WriteLine(new string('-', 60));



            // Bonus:

            //1. Print the longest song duration of the album that has least songs
            double leastSongsAlbum = Albums.Min(x => x.Songs.Count());


            var longestSongDuration = Albums.Where(x => x.Songs.Count == leastSongsAlbum).Select(x => x.Songs).Take(1).ToList();

            longestSongDuration.ForEach(x => Console.WriteLine($"Longest song duration of two albums with the {x.Count} songs that has least song is - {x.Max(x => x.Duration)} duration, but I taked the first album."));



            Console.WriteLine(new string('-', 60));



            //2. Print the name of the album that has most songs that contain letter 'a' in the name
            var mostSongsWithA = Albums.OrderByDescending(x => x.Songs.Sum(x => x.Name.Take('a').Count()))
                                 .Select(x => x.Name)
                                 .FirstOrDefault();

            Console.WriteLine($"The name of the album that has most songs that contain letter 'a' in the name is {mostSongsWithA}");



            Console.WriteLine(new string('-', 60));



            //3. - Print the name of the artist that has most songs that end with letter 'd'
            var mostSongsWithD = Artists.OrderByDescending(x => x.Albums.Count(x => x.Songs.Max(x => x.Name.EndsWith('d'))))
                                 .Select(x => x.FullName)
                                 .FirstOrDefault();

            Console.WriteLine($"The name of the artist that has most songs that end with letter 'd' is {mostSongsWithD}");



            Console.ReadLine();
        }