Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. class CalcTax {
  2.  
  3. var price: Double // 税抜き価格
  4. private(set) var taxRate: Double = 0.08 // 税率
  5. var priceIncludingTax: Double { // 税込価格
  6. get {
  7. return price * (1 + taxRate)
  8. }
  9.  
  10. set {
  11. self.price = newValue / 1.08
  12. }
  13. }
  14.  
  15. init(price: Double) { // 指定イニシャライザー
  16. self.price = price
  17. }
  18.  
  19. deinit {
  20. print("I will be die...")
  21. }
  22.  
  23. // 引数なしメソッド
  24. func describe() {
  25. print("税抜き価格 = ¥\(price), " + "税率 = \(taxRate * 100) %, "
  26. + "税込価格 = ¥\(priceIncludingTax)")
  27. }
  28.  
  29. // 異なるシグネチャーのメソッド定義
  30. func describe(newTaxRate: Double) {
  31. print("税抜き価格 = ¥\(price), " + "税率 = \(newTaxRate * 100) %, "
  32. + "税込価格 = ¥\(priceIncludingTax)")
  33. }
  34. }
  35.  
  36. let calcTax = CalcTax(price: 100)
  37. calcTax.describe()
  38. calcTax.describe(newTaxRate: 0.2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement