-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP5-VendingMachine.st
223 lines (172 loc) · 6.74 KB
/
P5-VendingMachine.st
1
Object subclass: #Moneda instanceVariableNames: 'valor' classVariableNames: '' poolDictionaries: '' category: 'VendingMachine-Practica5'!!Moneda methodsFor: 'accessing' stamp: 'ema 5/2/2018 13:01'!valor: anObject valor := anObject! !!Moneda methodsFor: 'accessing' stamp: 'ema 5/2/2018 13:01'!valor ^ valor! !"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!Moneda class instanceVariableNames: ''!!Moneda class methodsFor: 'accessing' stamp: 'ema 5/2/2018 13:02'!valor: real ^ self new valor: real! !Object subclass: #VendingMachine instanceVariableNames: 'stock dineroIngresado cantIngresada vuelto state precioBotella costoCompra' classVariableNames: '' poolDictionaries: '' category: 'VendingMachine-Practica5'!!VendingMachine methodsFor: 'as yet unclassified' stamp: 'ema 5/2/2018 12:57'!ingresar: unaMoneda "El cliente ingresa en la máquina una moneda de la denominaciónindicada. Devuelve true cuando alcanzó o superó el costo de lacompra, false en caso contrario." ^ state ingresar: unaMoneda en: self! !!VendingMachine methodsFor: 'as yet unclassified' stamp: 'ema 5/2/2018 16:01'!calcularVueltoActual ^ dineroIngresado - costoCompra ! !!VendingMachine methodsFor: 'as yet unclassified' stamp: 'ema 5/2/2018 13:44'!poseeVuelto ^ self calcularVueltoActual <= self vuelto! !!VendingMachine methodsFor: 'as yet unclassified' stamp: 'ema 5/2/2018 13:12'!dineroRestante ^ (cantIngresada * precioBotella ) - dineroIngresado ! !!VendingMachine methodsFor: 'as yet unclassified' stamp: 'ema 5/2/2018 12:49'!comprar: cantidadDeBotellas "Define la cantidad de botellas que el cliente desea comprar.Devuelve true si es posible hacer la compra, false casocontrario." ^ state comprar: cantidadDeBotellas con: self.! !!VendingMachine methodsFor: 'as yet unclassified' stamp: 'ema 5/2/2018 13:48'!confirmarCompra state confirmarCompraCon: self! !!VendingMachine methodsFor: 'as yet unclassified' stamp: 'ema 5/2/2018 14:47'!cancelarCompra state cancelarCompraCon: self! !!VendingMachine methodsFor: 'initialization' stamp: 'ema 5/2/2018 15:33'!initialize super initialize. stock :=0. state := IngresandoCantidadState new. dineroIngresado := 0. cantIngresada := 0. vuelto := 0. precioBotella := 3. costoCompra := 99! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 12:39'!dineroIngresado ^ dineroIngresado! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 12:39'!state: anObject state := anObject! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 13:38'!costoCompra ^ costoCompra! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 13:38'!costoCompra: anObject costoCompra := anObject! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 13:06'!precioBotella ^ precioBotella! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 13:06'!precioBotella: anObject precioBotella := anObject! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 12:39'!vuelto ^ vuelto! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 12:45'!cantIngresada ^ cantIngresada! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 12:39'!vuelto: anObject vuelto := anObject! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 12:39'!stock: anObject stock := anObject! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 12:39'!stock ^ stock! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 12:45'!cantIngresada: anObject cantIngresada := anObject! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 12:39'!state ^ state! !!VendingMachine methodsFor: 'accessing' stamp: 'ema 5/2/2018 12:39'!dineroIngresado: anObject dineroIngresado := anObject! !Object subclass: #VendingMachineState instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'VendingMachine-Practica5'!!VendingMachineState methodsFor: 'accessing' stamp: 'ema 5/2/2018 15:27'!ingresar: arg1 en: arg2 ^ self subclassResponsibility! !!VendingMachineState methodsFor: 'accessing' stamp: 'ema 5/2/2018 15:26'!cancelarCompraCon: arg1 ^ self subclassResponsibility! !!VendingMachineState methodsFor: 'accessing' stamp: 'ema 5/2/2018 15:28'!confirmarCompraCon: arg1 ^ self subclassResponsibility! !!VendingMachineState methodsFor: 'accessing' stamp: 'ema 5/2/2018 15:27'!comprar: arg1 con: arg2 ^ self subclassResponsibility! !VendingMachineState subclass: #IngresandoCantidadState instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'VendingMachine-Practica5'!!IngresandoCantidadState methodsFor: 'as yet unclassified' stamp: 'ema 5/2/2018 13:49'!ingresar: unaMoneda en: maquina! !!IngresandoCantidadState methodsFor: 'as yet unclassified' stamp: 'ema 5/2/2018 14:48'!cancelarCompraCon: maquina ! !!IngresandoCantidadState methodsFor: 'as yet unclassified' stamp: 'ema 5/2/2018 14:36'!confirmarCompraCon: maquina! !!IngresandoCantidadState methodsFor: 'as yet unclassified' stamp: 'ema 5/2/2018 13:40'!comprar: cantidadDeBotellas con: maquina cantidadDeBotellas <= maquina stock ifTrue: [ maquina cantIngresada: cantidadDeBotellas. maquina state: IngresandoMonedasState new. maquina costoCompra: cantidadDeBotellas * maquina precioBotella . Transcript show: 'El costo es de $' , maquina costoCompra asString. ^ true ] ifFalse: [ Transcript show: 'No hay suficiente stock.'. ^ false ]! !VendingMachineState subclass: #IngresandoMonedasState instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'VendingMachine-Practica5'!!IngresandoMonedasState methodsFor: 'as yet unclassified' stamp: 'ema 5/2/2018 14:50'!cancelarCompraCon: maquina maquina dineroIngresado: 0; cantIngresada: 0; state: IngresandoCantidadState new.! !!IngresandoMonedasState methodsFor: 'as yet unclassified' stamp: 'ema 5/2/2018 12:55'!comprar: cantidadDeBotellas con: maquina! !!IngresandoMonedasState methodsFor: 'accessing' stamp: 'ema 5/2/2018 15:40'!ingresar: unaMoneda en: maquina maquina dineroIngresado: maquina dineroIngresado + unaMoneda valor. maquina dineroIngresado >= maquina costoCompra ifTrue: [ Transcript show: 'Confirmar?'. ^ true ] ifFalse: [ Transcript show: 'Faltan $' , maquina dineroRestante asString. ^ false ]! !!IngresandoMonedasState methodsFor: 'accessing' stamp: 'ema 5/2/2018 15:54'!confirmarCompraCon: maquina maquina poseeVuelto ifTrue: [ Transcript show: 'Transaccion realizada con exito (vuelto $' , maquina calcularVueltoActual asString , ')'. maquina stock: maquina stock - maquina cantIngresada; vuelto: maquina vuelto + maquina costoCompra; state: IngresandoCantidadState new; dineroIngresado: 0; cantIngresada: 0 ] ifFalse: [ maquina cancelarCompra ]! !