Java Reference
In-Depth Information
this. code # code;
this. employee # employee;
this. customer # customer;
open # true ;
}
}
The VolatileDB class implements the functionalities defined by the inter-
face DBManager . It implements a non-persistent database. The database is
initialized with the same data whenever the application starts. Four vectors
( items , employees , customers and transactions ) hold the data. The methods are
very simple because they perform an indexed access to the vectors. Only the
method buy() is slightly more complex: it recovers the information on the
current transaction, if existent, then gets the required item and updates its
quantity.
package MarketDB;
import java.util.Vector;
public class VolatileDB implements DBManager {
static Vector items # new Vector();
static Vector employees # new Vector();
static Vector customers # new Vector();
static Vector transactions # new Vector();
public VolatileDB() {
items.add( new Item(1,"Beer",1.5,1000));
items.add( new Item(2,"Peanuts",0.5,1000));
items.add( new Item(3,"Cookies",2.2,500));
employees.add( new Employee(1,"Yee Emplo","111"));
customers.add( new Customer(1,"John Doe"));
customers.add( new Customer(1,"Jane Doe"));
}
public Employee getEmployee( long code) {
return (Employee)employees.get(( int )code-1);
}
public Customer getCustomer( long code) {
return (Customer)customers.get(( int )code-1);
}
public Item getItem( long code) {
return (Item)items.get(( int )code-1);
}
public long startTransaction( long customer,
long employee)
throws Exception {
Customer cust # getCustomer(customer);
if (cust ## null ) throw
new Exception("Customer non existent");
Employee emp # getEmployee(employee);
Search WWH ::




Custom Search