nat2chars : nat -> seqofchar
nat2chars(n) == if n = 0 then [] elseif n < 10 then [nat2char(n)] else (nat2chars(n div 10)) ^ [ nat2char(n mod 10)];
nat2string : nat -> seqofchar
nat2string(n) == if n = 0 then"0" else nat2chars(n)
operations
pure public GetTill: TillId ==> Till
GetTill(tid) == return tills(tid);
public Main: () ==> Main
Main() ==
(clock.SetDate("150999"); let c1 = newCard(123456,1,1),
c2 = newCard(123457,2,2),
c3 = newCard(123458,3,3),
c4 = newCard(123459,4,4),
c5 = newCard(123460,5,5),
c6 = newCard(123461,6,5),
c7 = newCard(123462,7,5) in let peter = new Cardholder("Peter Gorm Larsen", "Granvej 24"),
paul = new Cardholder("Paul Mukherjee", "Rugaardsvej 47"),
sten = new Cardholder("Sten Agerholm", "Teisensvej ??"),
kim = new Cardholder("Kim Sunesen", "??"),
CSK = new Cardholder("CSK","Forskerparken 10A") in let pglacc1 = new Account({1 |-> peter},5000),
saacc1 = new Account({2 |-> sten},0),
ksacc1 = new Account({3 |-> kim},9000),
pmacc1 = new Account({4 |-> paul},6000),
ifacc1 = new Account({5 |-> peter,
6 |-> sten,
7 |-> CSK},3000),
pglid1 = 1,
said1 = 2,
ksid1 = 3,
pmid1 = 4,
ifid1 = 5 in
(resource := new CentralResource(clock,new Letterbox());
resource.AddAccount(pglid1,pglacc1);
resource.AddAccount(said1,saacc1);
resource.AddAccount(ksid1,ksacc1);
resource.AddAccount(pmid1,pmacc1);
resource.AddAccount(ifid1,ifacc1);
tills := {1 |-> SetupTill(1,new Till()),
2 |-> SetupTill(2,new Till()),
3 |-> SetupTill(3,new Till()),
4 |-> SetupTill(4,new Till())};
cards := [c1,c2,c3,c4,c5,c6,c7];
));
SetupTill : nat * Till ==> Till
SetupTill(i,t) == let c = new Channel(),
lt = new LocalTill(c, resource),
lr = new LocalResource(c) in
(start(lt);
ltills := ltills ++ { i |-> lt};
t.Set(lr));
public EnterCardAtTill : nat * nat * nat ==> ()
EnterCardAtTill(tillNum, cardNum, pin) ==
(tills(tillNum).InsertCard(cards(cardNum)); let validRes1 = tills(tillNum).Validate(pin) in let msg = cases validRes1:
<Fail> -> tStr(tillNum) ^"Validate card failed",
<Retained> -> tStr(tillNum) ^"Card Retained",
<PinNotOk> -> "Validate Unsuccessful",
<PinOk> -> tStr(tillNum) ^"Validate Successful", others -> tStr(tillNum) ^"Unknown Message" endin
mb.put(msg); -- Make till 1 fail as soon as the card is entered if tillNum = 1 then Fail(tillNum)) pre tillNum insetdom tills;
public WithdrawalAtTill : nat * nat ==> ()
WithdrawalAtTill(tillNum, amount) == let wd1 = tills(tillNum).MakeWithdrawal(amount) in let msghdr =tStr(tillNum) ^"Withdrawal ("^nat2string(amount) ^")"in if <Fail> = wd1 then mb.put(msghdr ^ " Failed") elseifnot wd1 then mb.put(msghdr ^ " Unsuccessful") else mb.put(msghdr ^ " Successful");
public GetBalanceAtTill : nat ==> ()
GetBalanceAtTill (tillNum) == let bal1 = tills(tillNum).GetBalance() in ifnil = bal1 then mb.put(tStr(tillNum) ^ "Balance not known for this account") elseif <Fail> = bal1 then mb.put(tStr(tillNum) ^"Balance Failed") else mb.put(tStr(tillNum) ^ "Balance is " ^ nat2string(bal1) );
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.