static void Main(string[] args) { double sum = 0; double sum2 = 0; Product[] products = new Product[6]; Book[] books = new Book[3]; books[0] = new Book(1, "Red Dragon", 5000, "Global"); books[1] = new Book(2, "Harry Potter", 4500, "NY"); books[2] = new Book(3, "Pinochio", 2000, "LA"); MobilePhone[] phones = new MobilePhone[3]; phones[0] = new MobilePhone(1, "Samsung", 1000, "KR"); phones[1] = new MobilePhone(2, "Iphone", 1999, "USA"); phones[2] = new MobilePhone(3, "Nokia", 300, "SW"); for (int i = 0; i < books.Length; i++) { sum += books[i].computeTax(); } for (int j = 0; j < phones.Length; j++) { sum2 += phones[j].computeTax(); } Console.WriteLine("Total tax book is : " + sum); Console.WriteLine("Total tax mobile phone is :" + sum2); }
public static MobilePhone ReadMobile(StreamReader streamReader) { MobilePhone c = new MobilePhone { Name = streamReader.ReadLine(), Campany = streamReader.ReadLine(), Price = streamReader.ReadLine(), Color = streamReader.ReadLine(), Memory = streamReader.ReadLine() }; return(c); }
static void Main(string[] args) { List <Product> arrProduct = new List <Product>(); Book bk1 = new Book(1, "Book1", 99.99, "ABC"); Book bk2 = new Book(2, "Book2", 50.99, "ABC"); Book bk3 = new Book(3, "Book3", 20.99, "ABC"); MobilePhone mb1 = new MobilePhone(4, "Samsung S3", 999.99, "Samsung"); MobilePhone mb2 = new MobilePhone(5, "Samsung S4", 1099.99, "Samsung"); MobilePhone mb3 = new MobilePhone(6, "Samsung S5", 3099.99, "Samsung"); arrProduct.Add(bk1); arrProduct.Add(bk2); arrProduct.Add(bk3); arrProduct.Add(mb1); arrProduct.Add(mb2); arrProduct.Add(mb3); double totalBookTax = 0; double totalMobileTax = 0; double totalTax = 0; for (int i = 0; i < arrProduct.Count; i++) { if (arrProduct[i].Id <= 3) { totalBookTax += arrProduct[i].ComputeTax(); } else { totalMobileTax += arrProduct[i].ComputeTax(); } } Console.WriteLine("Total book tax: " + totalBookTax); Console.WriteLine("Total mobile tax: " + totalMobileTax); totalTax = totalBookTax + totalMobileTax; Console.WriteLine("Total products Tax : " + totalTax); Console.ReadKey(); }
static void Main(string[] args) { double totalTax = 0; List <Product> productList = new List <Product>(); Product book1 = new Book(1, "hahahaha", "nguyen van A", 1000); productList.Add(book1); Product book2 = new Book(2, "dac nhan tam", "micheal", 2000); productList.Add(book2); Product book3 = new Book(3, "ca dao", "Tap Can Binh", 3000); productList.Add(book3); Product phone1 = new MobilePhone(4, "Iphone", "Apple", 6000); productList.Add(phone1); Product phone2 = new MobilePhone(5, "Note3", "SamSung", 9000); productList.Add(phone2); Product phone3 = new MobilePhone(6, "X5", "Sony", 10000); productList.Add(phone3); for (int i = 0; i < productList.Count; i++) { if (productList[i] is Book) { Console.WriteLine((i + 1) + ".Bookname: " + productList[i].name + " Price: " + productList[i].price + " Tax: " + productList[i].computeTax()); } else { Console.WriteLine((i + 1) + ".Phonename: " + productList[i].name + " Price: " + productList[i].price + " Tax: " + productList[i].computeTax()); } totalTax += productList[i].computeTax(); } Console.WriteLine("Total Tax: " + totalTax); }
public static void Main(string[] args) { Product[] array = new Product[6]; array[0] = new Book(1, "C#1", 10, "Hanh1"); array[1] = new Book(2, "C#1", 11, "Hanh2"); array[2] = new Book(3, "C#1", 12, "Hanh3"); array[3] = new MobilePhone(4, "C#1", 13, "Hanh1"); array[4] = new MobilePhone(5, "C#1", 14, "Hanh1"); array[5] = new MobilePhone(6, "C#1", 15, "Hanh1"); double taxBook = 0; for (int i = 0; i <= 2; i++) { taxBook += array[i].computeTax(); } double taxMobilePhone = 0; for (int i = 3; i <= 5; i++) { taxMobilePhone += array[i].computeTax(); } double computeTotaltax = 0; for (int i = 0; i < array.Length; i++) { computeTotaltax += array[i].computeTax(); } Console.WriteLine("Total tax of Book: " + taxBook); Console.WriteLine("Total tax of MobilePhone: " + taxMobilePhone); Console.WriteLine("Total tax : " + computeTotaltax); }