-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSHBInsertMenu.swift
executable file
·135 lines (102 loc) · 3.93 KB
/
CSHBInsertMenu.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
// CSHBRunMenu.swift
// SeungHoBack_C0663173_Assignment
//
// Created by shoong on 2016-06-16.
// Copyright © 2016 SnowBack. All rights reserved.
//
import Foundation
class CSHBInsertMenu: SHBPrintable {
var aryPrintable : [SHBPrintable] = []
func printMenu() {
var inputData = 0
while (inputData != aryPrintable.count) {
print("\n\n\n")
print("###################################################################")
print("############ Insert Menu ############")
print("###################################################################")
print("1. Insert a New Stock")
print("2. Insert New Random Stocks (unitl 8 stocks)")
print("3. Return to Main Menu")
print("###################################################################")
print(" Choose menu : ")
inputData = input(aryPrintable.count)
self.aryPrintable[inputData].printMenu()
}
}
}
class CSHBInsertNewStock: SHBPrintable {
func printMenu() {
var companyName: String = ""
var purchasePrice: Float = 0.0
var currentPrice: Float = 0.0
var shares: Int32 = 0
var conversionRate: Float = 0.0
print("\n\n\n")
print("############ Insert a New Stock ############")
while (true) {
print("Input Company Name : ")
companyName = inputNewStock()
if (true == CSHBStockManagement.singletonInstance.checkCompanyName(companyName)) {
print("this company name(\(companyName)) is already exist!!!")
continue
}
else {
break
}
}
while(true) {
print("Input purchase price : ")
if let data: Float = inputNewStock() {
purchasePrice = data
break
}
else {
print("Try to input again !!!")
}
}
while(true) {
print("Input current price : ")
if let data: Float = inputNewStock() {
currentPrice = data
break
}
else {
print("Try to input again !!!")
}
}
while(true) {
print("Input number of shares : ")
if let data: Int32 = input() {
shares = data
break
}
else {
print("Try to input again !!!")
}
}
while(true) {
print("Input conversion rate : (if this value is not 0, this stock will be generated to new foreign stock")
if let data: Float = inputNewStock() {
conversionRate = data
break
}
else {
print("Try to input again !!!")
}
}
CSHBStockManagement.singletonInstance.addNewStock(companyName, purchasePrice: purchasePrice, currentPrice: currentPrice, shares: shares, rate: conversionRate)
}
}
class CSHBInsertAllStock: SHBPrintable {
func printMenu() {
print("\n\n\n")
print("###################################################################")
print("####### Insert All Stocks #######")
print("####### automatically generate stocks until maximum 8 #######")
print("###################################################################")
CSHBStockManagement.singletonInstance.addAllStocks()
print("Press any key to return Insert Menu")
input(0)
}
}