forked from larajz/lab19
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aTMcomponents.mli
87 lines (68 loc) · 3.06 KB
/
aTMcomponents.mli
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
(*
Component Behaviors of an ATM Machine
The functions here represent the component behaviors that an ATM
machine can take, including: prompting for and acquiring from the
customer some information (choosing an action or entering an account
id or an amount); presenting information to the customer; dispensing
cash.
Implementation of these behaviors is likely to require some database
of accounts, each with an id number, a customer name, and a current
balance.
*)
(* Customer account identifiers *)
type id = int
(* Possible actions that an ATM customer can perform *)
type action =
| Balance (* balance inquiry *)
| Withdraw of int (* withdraw an amount *)
| Deposit of int (* deposit an amount *)
| Next (* finish this customer and move on to the next one *)
| Finished (* shut down the ATM and exit entirely *)
;;
(*....................................................................
Initializing database of accounts
*)
(* A specification of a customer name and initial balance for
initializing the account database *)
type account_spec = {name : string; id : id; balance : int} ;;
(* initialize accts -- Establishes a database of accounts, each with a
name, aribtrary id, and balance. The names and balances are
initialized as per the `accts` provided. *)
val initialize : account_spec list -> unit ;;
(*....................................................................
Acquiring information from the customer
*)
(* acquire_id () -- Requests from the ATM customer and returns an id
(akin to entering one's ATM card), by prompting for an id number
and reading an id from stdin. *)
val acquire_id : unit -> id ;;
(* acquire_amount () -- Requests from the ATM customer and returns an
amount by prompting for an amount and reading an int from stdin. *)
val acquire_amount : unit -> int ;;
(* acquire_act () -- Requests from the user and returns an action to
be performed, as a value of type action *)
val acquire_act : unit -> action ;;
(*....................................................................
Querying and updating the account database
These functions all raise Not_found if there is no account with the
given id.
*)
(* get_balance id -- Returns the balance for the customer account with
the given id. *)
val get_balance : id -> int ;;
(* get_name id -- Returns the name associated with the customer
account with the given id. *)
val get_name : id -> string ;;
(* update_balance id amount -- Modifies the balance of the customer
account with the given id,setting it to the given amount. *)
val update_balance : id -> int -> unit ;;
(*....................................................................
Presenting information and cash to the customer
*)
(* present_message message -- Presents to the customer (on stdout) the
given message followed by a newline. *)
val present_message : string -> unit ;;
(* deliver_cash amount -- Dispenses the given amount of cash to the
customer (really just prints to stdout a message to that
effect). *)
val deliver_cash : int -> unit ;;