-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSHBStock.swift
executable file
·75 lines (55 loc) · 2.38 KB
/
CSHBStock.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// CStockHolding.swift
// SeungHoBack_C0663173_Assignment
//
// Created by shoong on 6/1/16.
// Copyright © 2016 SnowBack. All rights reserved.
//
import Foundation
class CSHBStock: CustomStringConvertible {
private var fPurchaseSharePrice_: NSDecimalNumber!
private var fCurrentSharePrice_: NSDecimalNumber!
private var nNumberOfShares_: NSDecimalNumber!
private var strCompanyName_: String
private var formatterForCurrency_ = NSNumberFormatter()
private var formatterForNumber_ = NSNumberFormatter()
init(fPurchaseSharePrice: NSDecimalNumber, fCurrentSharePrice: NSDecimalNumber, nNumberOfShares: NSDecimalNumber, strCompanyName: String) {
formatterForCurrency_.numberStyle = NSNumberFormatterStyle.CurrencyStyle
formatterForNumber_.numberStyle = NSNumberFormatterStyle.DecimalStyle
self.fPurchaseSharePrice_ = fPurchaseSharePrice
self.fCurrentSharePrice_ = fCurrentSharePrice
self.nNumberOfShares_ = nNumberOfShares
self.strCompanyName_ = strCompanyName
}
func CalcCostInDollars() -> NSDecimalNumber {
return fPurchaseSharePrice_ * nNumberOfShares_
}
func CalcValueInDollars() -> NSDecimalNumber {
return fCurrentSharePrice_ * nNumberOfShares_
}
func getPurchaseSharePrice() -> NSDecimalNumber {
return fPurchaseSharePrice_
}
func getCurrentSharePrice() -> NSDecimalNumber {
return fCurrentSharePrice_
}
func getNumberOfShares() -> NSDecimalNumber {
return nNumberOfShares_
}
func getCompanyName() -> String {
return strCompanyName_
}
func getFormatForCurrency() -> NSNumberFormatter {
return formatterForCurrency_
}
func getFormatForNumber() -> NSNumberFormatter {
return formatterForNumber_
}
var description: String {
return String(format: "%@ %@ %@ %@",
formatStock(self.strCompanyName_, fieldWidth: 20),
formatStock(formatterForCurrency_.stringFromNumber(self.fPurchaseSharePrice_)!, fieldWidth: 15),
formatStock(formatterForCurrency_.stringFromNumber(self.fCurrentSharePrice_)!, fieldWidth: 15),
formatStock(formatterForNumber_.stringFromNumber(self.nNumberOfShares_)!, fieldWidth: 15))
}
}