-- A V Peterson 23-05-2002 class STORE_ITEM -- an item available in a store creation make feature itemcode : INTEGER -- a unique code identifying an item description : STRING -- a one-word description of an item wholesale_price : REAL -- the cost to the store retail_price : REAL -- the current retail price qty_in_stock : INTEGER -- the quantity of the item in stock make(icode: INTEGER; desc: STRING; wpr: REAL; rpr: REAL; qty: INTEGER) is -- Initialise a store_item with itemcode icode, -- description desc, wholesale price wpr, retail price rpr, -- qty_in_stock qty local do itemcode := icode description := clone(desc) wholesale_price := wpr retail_price := rpr qty_in_stock := qty end -- make print_store_item is -- Print attributes of the store item. local do io.put_integer_format(itemcode, 8); io.put_spaces(2) description.head(11) -- truncate description to 11 characters io.put_string(description); io.put_spaces(11 - description.count) my_print_real_format(wholesale_price, 10, 2) my_print_real_format(retail_price, 10, 2) io.put_integer_format(qty_in_stock, 8) io.put_new_line end -- print_store_item change_retail_price(newprice : REAL) is -- Update the retail price. require newprice > 0.0 local do retail_price := newprice ensure retail_price = newprice end -- change_retail_price add_stock(amount : INTEGER) is -- Increase the quantity of the item by amount. require amount >= 0 local do qty_in_stock := qty_in_stock + amount ensure qty_in_stock = old qty_in_stock + amount end -- add_stock sell_stock(amount : INTEGER) is -- Decrease the quantity of the item by amount. require amount >= 0 local do qty_in_stock := qty_in_stock - amount ensure qty_in_stock = old qty_in_stock - amount end -- sell_stock my_print_real_format(value : REAL; w, d : INTEGER) is -- Print a REAL value using a format with d places to the right -- of the decimal point and a minimum total width of w. local str : STRING k : INTEGER do str := value.to_string_format(d) k := str.count if w > k then io.put_spaces(w-k) end io.put_string(str) end -- my_print_real_format end -- class STORE_ITEM