Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace zad6
- {
- abstract class Item : IComparable
- {
- protected string title;
- protected string author;
- protected double price;
- public abstract double VAT
- {
- get;
- }
- public abstract double returnPriceBrutto
- {
- get;
- }
- public override string ToString()
- {
- return String.Format("{0} {1} {2}", author , title , this.returnPriceBrutto);
- }
- public int CompareTo(object ob)
- {
- Item i1 = (Item) ob;
- if (this.returnPriceBrutto > i1.returnPriceBrutto)
- {
- return 1;
- }
- else if (this.returnPriceBrutto == i1.returnPriceBrutto)
- {
- return 0;
- }
- return -1;
- }
- public class ItemComparer : IComparer<Object>
- {
- public int Compare(Object x, Object y)
- {
- Item t1 = (Item)x;
- Item t2 = (Item)y;
- return string.Compare(t1.title, t2.title);
- }
- }
- }
- class Book : Item
- {
- protected string ISBN;
- protected uint pageNumber;
- protected string publisher;
- protected double vat;
- public Book(string title, string author, string ISBN, uint pageNumber, string publisher, double price, double vat)
- {
- this.price = price;
- this.title = title;
- this.author = author;
- this.ISBN = ISBN;
- this.pageNumber = pageNumber;
- this.publisher = publisher;
- this.vat = vat;
- }
- public override double VAT
- {
- get
- {
- return vat;
- }
- }
- public override double returnPriceBrutto
- {
- get
- {
- return Math.Round(price * (1 + vat), 2);
- }
- }
- public override string ToString()
- {
- return base.ToString()+String.Format(" {0} {1} {2}",ISBN,pageNumber,publisher);
- }
- public double WartoscVAT()
- {
- return returnPriceBrutto - price;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Book b1 = new Book("Pan Tadeusz", "Mickiewicz", "89312AKTA", 512, "PWN", 25.50, 0.08);
- Book b2 = new Book("Krzyżacy", "Sienkiewicz", "815132BGAT", 394, "Operon", 29.73, 0.08);
- Console.WriteLine(b1.ToString());
- Console.WriteLine(b2.ToString());
- Console.WriteLine(b1.CompareTo(b2));
- Book[] tablicaBook = new Book[2];
- tablicaBook[0] = b1;
- tablicaBook[1] = b2;
- Console.WriteLine(tablicaBook[0].ToString());
- Console.WriteLine(tablicaBook[1].ToString());
- Array.Sort(tablicaBook, new Item.ItemComparer());
- Console.WriteLine(tablicaBook[0].ToString());
- Console.WriteLine(tablicaBook[1].ToString());
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement