Class ORDER
class ORDER
inherit
DISPLAYABLE
DB_ACCESS
DB_ITEM
creation
make
feature
line_items : ARRAY [ LINE_ITEM ];
total_cost : INTEGER;
tax : REAL;
tax_percents: INTEGER;
customer : CUSTOMER;
make is
-- initializes the new object
do
!!line_items.make (1,0);
actual_count := 1;
tax_percents := 20
end
save is
do
db.save_order (current)
end
update_taxes is
-- calculate the total sales taxes
do
tax := total_cost * tax_percents/100.0
end
update_total is
-- compute the total amount
local
i : INTEGER
do
total_cost := 0
from
i := 1;
until
i > line_items.count
loop
total_cost := total_cost + line_items.item (i).cost
i := i + 1
end
end
set_customer (c: CUSTOMER) is
do
customer := c
end
feature -- line item
actual_line_item: LINE_ITEM
line_index : INTEGER
actual_count: INTEGER;
empty_line_item (g: GOOD) is
do
!!actual_line_item.make (g,actual_count)
end
add_line_item (line_itm: LINE_ITEM) is
-- store new line item into the array
do
line_items.force (line_itm, line_items.count+1)
end
delete_line_item (pos: INTEGER) is
-- remove the line_item at position "pos"
require
valid_pos : pos > 0 and then pos <= line_items.count
do
line_items.remove (pos)
line_items.resize (1, line_items.count-1)
end
end -- class ORDER
Class CUSTOMER
class CUSTOMER
inherit
DISPLAYABLE
DB_ACCESS
DB_ITEM
creation
make
feature
name: STRING
street: STRING
town: STRING
turnover: REAL
make is
do
name := ""
street := ""
town := ""
end
increment_turnover (n: REAL) is
do
turnover := turnover + n
end
save is
do
db.save_customer (current)
end
valid_customer : BOOLEAN is
do
Result := name /= Void and then
name.count > 0
end
end -- class CUSTOMER
Class GOOD
class GOOD
inherit
DISPLAYABLE
DB_ACCESS
DB_ITEM
creation
make
feature
description: STRING
price,
store: INTEGER
make is
do
description := "new item"
end
increment_store (n: INTEGER) is
do
store := store + n
end
save is
do
db.save_good (current)
end
valid_good : BOOLEAN is
do
Result := description /= Void and then
not description.empty and then
price >= 0
end
end -- class GOOD
Class LINE_ITEM
class LINE_ITEM
creation
make
feature
count : INTEGER; -- how many items ?
item : GOOD
make (g: GOOD; c: INTEGER) is
do
count := c;
item := g;
end
cost : INTEGER is
do
Result := item.price * count
end
end -- class LINE_ITEM
Copyright ©
Object Tools -- info@object-tools.com
Last updated: $Date: 2005/02/02 11:51:14 $