Browse code
Initial
fiddlerwoaroof authored on 27/04/2016 06:15:59
Showing 5 changed files
Showing 5 changed files
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,94 @@ |
1 |
+note |
|
2 |
+ description: "This is the {ACCOUNT}." |
|
3 |
+ author: "Edward Langley" |
|
4 |
+ date: "$Date$" |
|
5 |
+ revision: "$Revision$" |
|
6 |
+ |
|
7 |
+class |
|
8 |
+ ACCOUNT |
|
9 |
+ |
|
10 |
+create |
|
11 |
+ open, |
|
12 |
+ make |
|
13 |
+ |
|
14 |
+feature |
|
15 |
+ balance: INTEGER |
|
16 |
+ owner: PERSON |
|
17 |
+ minimum_balance: INTEGER = 1000 |
|
18 |
+ transactions: LINKED_LIST [TRANSACTION] |
|
19 |
+ |
|
20 |
+ open (who: STRING initial: INTEGER) |
|
21 |
+ local |
|
22 |
+ person: PERSON |
|
23 |
+ do |
|
24 |
+ create person.make (who) |
|
25 |
+ make(person, initial) |
|
26 |
+ end |
|
27 |
+ |
|
28 |
+ print_transactions |
|
29 |
+ do |
|
30 |
+ from |
|
31 |
+ transactions.start |
|
32 |
+ until |
|
33 |
+ transactions.off |
|
34 |
+ loop |
|
35 |
+ transactions.item.show |
|
36 |
+ print ("%N") |
|
37 |
+ transactions.forth |
|
38 |
+ end |
|
39 |
+ end |
|
40 |
+ |
|
41 |
+ deposit (sum: INTEGER) |
|
42 |
+ require |
|
43 |
+ sum > 0 |
|
44 |
+ do |
|
45 |
+ add (sum) |
|
46 |
+ add_transaction ("deposit", sum) |
|
47 |
+ ensure |
|
48 |
+ balance = old balance + sum |
|
49 |
+ end |
|
50 |
+ |
|
51 |
+ withdraw (sum: INTEGER) |
|
52 |
+ require |
|
53 |
+ sum > 0 |
|
54 |
+ sum <= balance - minimum_balance |
|
55 |
+ do |
|
56 |
+ add (-sum) |
|
57 |
+ add_transaction ("withdrawal", -sum) |
|
58 |
+ ensure |
|
59 |
+ balance = old balance - sum |
|
60 |
+ end |
|
61 |
+ |
|
62 |
+ may_withdraw (sum: INTEGER): BOOLEAN |
|
63 |
+ do |
|
64 |
+ Result := (balance >= sum + minimum_balance) |
|
65 |
+ end |
|
66 |
+ |
|
67 |
+feature {NONE} |
|
68 |
+ |
|
69 |
+ add_transaction (type: STRING amount: INTEGER) |
|
70 |
+ local |
|
71 |
+ transaction: TRANSACTION |
|
72 |
+ do |
|
73 |
+ create transaction.make (type, amount) |
|
74 |
+ transactions.put_front (transaction) |
|
75 |
+ end |
|
76 |
+ |
|
77 |
+ add (sum: INTEGER) |
|
78 |
+ do |
|
79 |
+ balance := balance + sum |
|
80 |
+ end |
|
81 |
+ |
|
82 |
+ make (person: PERSON initial: INTEGER) |
|
83 |
+ require |
|
84 |
+ initial >= minimum_balance |
|
85 |
+ do |
|
86 |
+ create transactions.make |
|
87 |
+ balance := initial |
|
88 |
+ owner := person |
|
89 |
+ end |
|
90 |
+ |
|
91 |
+invariant |
|
92 |
+ balance >= minimum_balance |
|
93 |
+ |
|
94 |
+end |
0 | 95 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,49 @@ |
1 |
+note |
|
2 |
+ description: "menus application root class" |
|
3 |
+ date: "$Date$" |
|
4 |
+ revision: "$Revision$" |
|
5 |
+ |
|
6 |
+class |
|
7 |
+ APPLICATION |
|
8 |
+ |
|
9 |
+inherit |
|
10 |
+ ARGUMENTS |
|
11 |
+ |
|
12 |
+create |
|
13 |
+ make |
|
14 |
+ |
|
15 |
+feature |
|
16 |
+ person: PERSON |
|
17 |
+ acc: ACCOUNT |
|
18 |
+ balance: INTEGER |
|
19 |
+ |
|
20 |
+feature {NONE} -- Initialization |
|
21 |
+ |
|
22 |
+ make |
|
23 |
+ -- Run application. |
|
24 |
+ do |
|
25 |
+ --| Add your code here |
|
26 |
+ create acc.open ("Bob Johnson", 2300) |
|
27 |
+ person := acc.owner |
|
28 |
+ balance := acc.balance |
|
29 |
+ |
|
30 |
+ print (person.name + "%N--------------%N") |
|
31 |
+ |
|
32 |
+ acc.deposit (2300) |
|
33 |
+ print ("Initial: ") |
|
34 |
+ print (balance) |
|
35 |
+ print (" %N") |
|
36 |
+ |
|
37 |
+ if acc.may_withdraw (50) then |
|
38 |
+ acc.withdraw (3600) |
|
39 |
+ end |
|
40 |
+ print ("Final: ") |
|
41 |
+ print (acc.balance) |
|
42 |
+ print (" %N") |
|
43 |
+ |
|
44 |
+ print ("%N%NLedger:%N--------%N") |
|
45 |
+ |
|
46 |
+ acc.print_transactions |
|
47 |
+ end |
|
48 |
+ |
|
49 |
+end |
0 | 50 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,19 @@ |
1 |
+<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
+<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="menus" uuid="B5FB2A21-2758-42AE-99DB-65DCBF047013"> |
|
3 |
+ <target name="menus"> |
|
4 |
+ <root feature="make" class="APPLICATION"/> |
|
5 |
+ <option warning="true"> |
|
6 |
+ <assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/> |
|
7 |
+ </option> |
|
8 |
+ <setting name="console_application" value="true"/> |
|
9 |
+ <precompile name="base_pre" location="$ISE_PRECOMP/base-safe.ecf"/> |
|
10 |
+ <library name="base" location="$ISE_LIBRARY/library/base/base-safe.ecf"/> |
|
11 |
+ <cluster name="menus" location=".\" recursive="true"> |
|
12 |
+ <file_rule> |
|
13 |
+ <exclude>/EIFGENs$</exclude> |
|
14 |
+ <exclude>/.svn$</exclude> |
|
15 |
+ <exclude>/CVS$</exclude> |
|
16 |
+ </file_rule> |
|
17 |
+ </cluster> |
|
18 |
+ </target> |
|
19 |
+</system> |
0 | 20 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,21 @@ |
1 |
+note |
|
2 |
+ description: "Summary description for {PERSON}." |
|
3 |
+ author: "" |
|
4 |
+ date: "$Date$" |
|
5 |
+ revision: "$Revision$" |
|
6 |
+ |
|
7 |
+class |
|
8 |
+ PERSON |
|
9 |
+ |
|
10 |
+create |
|
11 |
+ make |
|
12 |
+ |
|
13 |
+feature |
|
14 |
+ name: STRING |
|
15 |
+ |
|
16 |
+feature {NONE} |
|
17 |
+ make (myname: String) |
|
18 |
+ do |
|
19 |
+ name := myname |
|
20 |
+ end |
|
21 |
+end |
0 | 22 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,30 @@ |
1 |
+note |
|
2 |
+ description: "Summary description for {TRANSACTION}." |
|
3 |
+ author: "" |
|
4 |
+ date: "$Date$" |
|
5 |
+ revision: "$Revision$" |
|
6 |
+ |
|
7 |
+class |
|
8 |
+ TRANSACTION |
|
9 |
+ |
|
10 |
+create |
|
11 |
+ make |
|
12 |
+ |
|
13 |
+feature |
|
14 |
+ type: STRING |
|
15 |
+ value: INTEGER |
|
16 |
+ |
|
17 |
+ show |
|
18 |
+ do |
|
19 |
+ print (type + " ") |
|
20 |
+ print (value) |
|
21 |
+ end |
|
22 |
+ |
|
23 |
+feature {NONE} |
|
24 |
+ make (in_type: STRING in_value: INTEGER) |
|
25 |
+ do |
|
26 |
+ type := in_type |
|
27 |
+ value := in_value |
|
28 |
+ end |
|
29 |
+ |
|
30 |
+end |