Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CalcTax {
- var price: Double // 税抜き価格
- private(set) var taxRate: Double = 0.08 // 税率
- var priceIncludingTax: Double { // 税込価格
- get {
- return price * (1 + taxRate)
- }
- set {
- self.price = newValue / 1.08
- }
- }
- init(price: Double) { // 指定イニシャライザー
- self.price = price
- }
- deinit {
- print("I will be die...")
- }
- // 引数なしメソッド
- func describe() {
- print("税抜き価格 = ¥\(price), " + "税率 = \(taxRate * 100) %, "
- + "税込価格 = ¥\(priceIncludingTax)")
- }
- // 異なるシグネチャーのメソッド定義
- func describe(newTaxRate: Double) {
- print("税抜き価格 = ¥\(price), " + "税率 = \(newTaxRate * 100) %, "
- + "税込価格 = ¥\(priceIncludingTax)")
- }
- }
- let calcTax = CalcTax(price: 100)
- calcTax.describe()
- calcTax.describe(newTaxRate: 0.2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement