---
# System prepended metadata

title: C#作業 - 20.10.20.10
tags: [C#, 作業]

---

# C#作業 - 20.10.20.10

	
    class Invoice : 發票類別
		屬性
			int Price : 未稅金額
			int Tax : 營業稅, ReadOnly
			int InclusivePrice : 含稅金額, ReadOnly

		建構函數
			Invoice(int price, double taxRate=0.05)

	class EStore :在建構函數傳入營業稅率
		private int CalcTax(int price) :計算營業稅
		public Invoice IssueInvoice(int price) : 開立發票, 傳回 Invoice 型別的物件
        




---
```csharp=

using System;

namespace ConsoleApp1
{
	internal class Program
	{
		static void Main(string[] args)
		{
			EStore shopping = new EStore();
			Invoice invoice = shopping.IssueInvoice(199);
			Console.WriteLine($"未稅金額:  {invoice.Price}");
			Console.WriteLine($"　　稅金:  {invoice.Tax}");
			Console.WriteLine($"　總金額:  {invoice.InclusivePrice}");
		}
	}
	public class Invoice
	{
		public int Price { get; set; }
		public int Tax { get; private set; }
		public int InclusivePrice { get; private set; }
		public Invoice(int price, double taxRate = 0.05)
		{
			this.Price = price;
			this.Tax = (int)Math.Round((price * taxRate), 0, MidpointRounding.AwayFromZero);
			this.InclusivePrice = Price + Tax;
		}
	}

	public class EStore
	{
		public double TaxRate { get; set; }
		public EStore(double taxRate = 0.05)
		{
			this.TaxRate = taxRate;
		}
		private int CalcTax(int price)
		{
			return (int)Math.Round((price * TaxRate), 0, MidpointRounding.AwayFromZero);
		}
		public Invoice IssueInvoice(int price)
		{
			return new Invoice(price, TaxRate);
		}
	}
}

```


---
排版與顯示問題感謝佳恩與子元同學的幫忙 :)

###### tags: `C#` `作業`


