Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.univLille1.calp.distributeur
- import fr.univLille1.calp.basicFSM.Mealy
- import fr.univLille1.calp.basicFSM.FiniteStateMachine
- abstract class InputDistrib
- case class Coin(valeur: Double) extends InputDistrib
- case class Select(valeur: String) extends InputDistrib
- case object Cancel extends InputDistrib
- class VendingMachine(map: Map[String, Double]) extends FiniteStateMachine with Mealy {
- var contenue: Map[String, Double] = map
- case class State(sum: Double)
- type Input = InputDistrib
- type Output = String
- val init = State(0.0)
- override def outputT(s: State, l: Input): Output = (s, l) match {
- case(State(somme), Coin(v)) => "NoOutput"
- case(State(somme), Select(v)) => {
- if (somme >= contenue(v)) {
- var tmp = somme-contenue(v)
- "Deliver("+v+", "+tmp+")"
- } else {
- "NoOutput"
- }
- }
- case(State(somme), Cancel) => if (somme >= 0) "Change("+somme+")" else "NoOutput"
- }
- def transitionFunction(s: State, l: Input): State = (s, l) match {
- case(State(somme), Coin(v)) => State(somme+v)
- case(State(somme), Select(v)) => {
- if (somme >= (contenue(v))) {
- State(somme - (contenue(v)))
- } else {
- State(somme)
- }
- }
- case(State(somme), Cancel) => State(somme)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment