Created
September 29, 2018 08:03
-
-
Save dproject21/29c134f515b2f8bb6a329fc0dd1be8b0 to your computer and use it in GitHub Desktop.
20180929 tddbc tokyo golang implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package vending | |
type VendingMachine struct { | |
haveMoney int | |
priceList map[string]int | |
} | |
func NewVendingMachine() *VendingMachine { | |
vendingMachine := new(VendingMachine) | |
m := make(map[string]int) | |
m["レッドブル"] = 200 | |
m["アサイードリンク"] = 300 | |
m["コーラ"] = 100 | |
m["烏龍茶"] = 100 | |
vendingMachine.priceList = m | |
return vendingMachine | |
} | |
func (v *VendingMachine) PushButton(drinkName string) string { | |
if v.haveMoney >= v.priceList[drinkName] { | |
v.haveMoney -= v.priceList[drinkName] | |
return drinkName | |
} | |
return "" | |
} | |
func (v *VendingMachine) InsertCoin(coin int) bool { | |
if coin == 100 || coin == 50 || coin == 10 || coin == 500 { | |
v.haveMoney += coin | |
return true | |
} | |
return false | |
} | |
func (v *VendingMachine) HaveMoney(value int) bool { | |
return value == v.haveMoney | |
} | |
func (v *VendingMachine) OnLightButton(drinkName string) bool { | |
if v.haveMoney >= v.priceList[drinkName] { | |
return true | |
} | |
return false | |
} | |
func (v *VendingMachine) BackMoney() int { | |
return v.haveMoney | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment