Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

VladimirPetukhov avatar VladimirPetukhov 28 Точки

5.Book Library from Objects and Classes - Exercises 0/100???

Условие:

To model a book library, define classes to hold a book and a library.

The library must have a name and a list of books. The books must contain the title, author, publisher, release date (in dd.MM.yyyy format), ISBN-number and price.

Read a list of books, add them to the library and print the total sum of prices by author, ordered descending by price and then by author’s name lexicographically.

Books in the input will be in format {title} {author} {publisher} {release date} {ISBN} {price}.

The total prices must be printed formatted to the second decimal place.

Examples

Input

Output

5

LOTR Tolkien GeorgeAllen 29.07.1954 0395082999 30.00

Hobbit Tolkien GeorgeAll 21.09.1937 0395082888 10.25

HP1 JKRowling Bloomsbury 26.06.1997 0395082777 15.50

HP7 JKRowling Bloomsbury 21.07.2007 0395082666 20.00

AC OBowden PenguinBooks 20.11.2009 0395082555 14.00

Tolkien -> 40.25

JKRowling -> 35.50

OBowden -> 14.00

Hints

  • Create classes Book and Library with all the mentioned above properties:
  • an object of type Library.
  • Read the input and create a Book object for each book in the input.
  • Create a LINQ query that will sum the prices by author, order the results as requested.

Print the results

РЕШЕНИЕ:

 


using System.Globalization;
using System.Runtime.Remoting.Messaging;

namespace _5.Book_Library
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    public class Program
    {
        public class Book
        {
            public Book(string title, string author, string publisher, DateTime releaseDate, string isbn, decimal price)
            {
                Title = title;
                Author = author;
                Publisher = publisher;
                ReleaseDate = releaseDate;
                Isbn = isbn;
                Price = price;
            }

            public string Title { get; set; }

            public string Author{ get; set; }

            public string Publisher { get; set; }

            public DateTime ReleaseDate { get; set; }

            public string Isbn { get; set; }

            public decimal Price { get; set; }

        }
        public class Lybrary
        {
            public string Name { get; set; }

            public  new List<Book> Books { get; set; }
        }


        

        public static void Main()
        {
            var library=new Lybrary()
            {
                Name = "Prosveta",
                Books = new List<Book>()
            };
            var booksCount = int.Parse(Console.ReadLine());
            for (int i = 0; i < booksCount; i++)
            {
               // {title} {author} {publisher} {release date} {ISBN} {price}.
                var info = Console.ReadLine().Split(' ');
                var title = info[0];
                var author = info[1];
                var publisher = info[2];
                var releaseDate = DateTime.ParseExact(info[3], "dd.MM.yyyy", CultureInfo.InvariantCulture);
                var isbn = info[4];
                var price = Convert.ToDecimal(info[5]);

                var book = new Book(title, author, publisher, releaseDate, isbn, price);
                library.Books.Add(book);
                
            }
            var sortedLybrary = library
                .Books
                .Select(a => a.Author)
                .Distinct()
                .Select(a => new
                {
                    Author = a,
                    Sales = library.Books.Where(book => book.Author == a).Sum(p => p.Price)
                })
                .OrderByDescending(authorInfo => authorInfo.Sales)
                .ThenBy(a => a.Author)
                .ToList();
                
                
            
                
            foreach (var item in sortedLybrary)
            {
                Console.WriteLine($"{item.Author} -> {item.Sales:f2}");
            }
        }
    }
}

Тагове:
-3
Fundamentals Module
AlucardDracula avatar AlucardDracula 416 Точки

при мен дава 100/100 незнам какъв е проблемът при теб. 
Ето моето решение: ЛИНК

0
TeodorStefanovPld avatar TeodorStefanovPld 1274 Точки

сорри ама нищо,не се разбира какъв е проблема и какво. И така като плеснете тоя код ако мислете че е лесен за четене...

Pastebin или другите алтернативи са по-добре отколкото copy/paste направо...

1
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.