import sale.*;
import log.*;
import users.*;
import data.*;
import data.ooimpl.*;
import java.io.*;
import java.util.*;
import java.lang.*;
import javax.swing.*;
public class VideoMachine extends Shop
{
private static Set customerSet = new HashSet();
public VideoMachine()
{
super();
String[] videos = {"Video 01", "Video 02", "Video 03", "Video 04",
"Video 05", "Video 06", "Video 07", "Video 08",
"Video 09", "Video 10"};
int[] buy = {5000, 5000, 5000, 5000, 5000, 4000, 4000, 4000, 3000, 3000};
int[] sell = {4000, 4000, 4000, 4000, 3500, 3500, 3500, 3500, 3000, 3000};
Catalog videoCatalog = new CatalogImpl("Video-Catalog");
addCatalog(videoCatalog);
for (int i = 0; i < videos.length; i++) {
videoCatalog.add(new VideoCassette (videos[i], new QuoteValue
(new IntegerValue (buy[i]), new IntegerValue (sell[i]))), null);
}
CountingStock cs = new CountingStockImpl("Video-Countingstock",
(CatalogImpl)videoCatalog);
addStock(cs);
Iterator cassettes = videoCatalog.keySet(null).iterator();
while (cassettes.hasNext()) {
cs.add((String)cassettes.next(), 5, null);
}
addCatalog(new CurrencyImpl("DM"));
MoneyBag coinSlot = new MoneyBagImpl("coin slot",
(CurrencyImpl)getCatalog("DM"));
coinSlot.add(CurrencyImpl.PFENNIG_STCK_1, 100000, null);
addStock(coinSlot);
}
public static void main (String[] args)
{
VideoMachine vidMachine = new VideoMachine();
setTheShop(vidMachine);
Counter c = new Counter("Video Rental");
c.attach(new DataBasketImpl());
c.attach(new User("SalespointUser"));
vidMachine.addSalesPoint(c);
JPasswordField jPasswordField1 = new JPasswordField();
JPasswordField jPasswordField2 = new JPasswordField();
JPanel jPasswordRequest = new JPanel();
jPasswordRequest.setLayout(new BoxLayout(jPasswordRequest,
BoxLayout.Y_AXIS));
jPasswordRequest.add(new JLabel("Enter the manger's password:"));
jPasswordRequest.add(jPasswordField1);
jPasswordRequest.add(new JLabel("Re-enter the manager's password:"));
jPasswordRequest.add(jPasswordField2);
do {
JOptionPane.showMessageDialog (null,
jPasswordRequest,
"Manager",
JOptionPane.QUESTION_MESSAGE);
}
while (!new String(jPasswordField1.getPassword()).equals(
new String(jPasswordField2.getPassword())));
Office.setPassword(new String(jPasswordField1.getPassword()));
vidMachine.setShopFrameTitle("Videoverleihautomat *** HOMECINEMA *** 24h");
vidMachine.start();
vidMachine.getShopFrame().setSize(640,480);
vidMachine.getShopFrame().validate();
}
public MenuSheet createShopMenuSheet()
{
MenuSheet msMenuBar = super.createShopMenuSheet();
MenuSheet msShopMenu =
(MenuSheet)msMenuBar.getTaggedItem (SHOP_MENU_TAG, true);
MenuSheetItem msLoadItem = (MenuSheetItem)msShopMenu.remove(LOAD_TAG);
MenuSheetItem msSaveItem = (MenuSheetItem)msShopMenu.remove(SAVE_TAG);
MenuSheetSeparator msSeparator =
(MenuSheetSeparator)msShopMenu.remove(SEPARATOR_TWO_TAG);
MenuSheetItem msQuitItem = (MenuSheetItem)msShopMenu.remove(QUIT_SHOP_TAG);
MenuSheetItem msManagerItem =
new MenuSheetItem("Open Office",
new sale.Action()
{
public void doAction (SaleProcess p, SalesPoint sp)
{
List l = getSalesPoints();
for (int i = 0; i < l.size(); i++) {
if (((SalesPoint)l.get(i)).getName() == "Office") {
javax.swing.JOptionPane.
showMessageDialog(null,
"There is an already an Office",
"Error",
javax.swing.JOptionPane.ERROR_MESSAGE);
return;
}
}
JPasswordField jPasswordField = new JPasswordField();
JPanel jPasswordRequest = new JPanel();
jPasswordRequest.setLayout(new BoxLayout(jPasswordRequest,
BoxLayout.Y_AXIS));
jPasswordRequest.add(new JLabel("Enter the manger's password:"));
jPasswordRequest.add(jPasswordField);
JOptionPane.showMessageDialog (null,
jPasswordRequest,
"Manager",
JOptionPane.QUESTION_MESSAGE);
if (Office.testPassword(new String(jPasswordField.getPassword()))) {
Office o = new Office("Office");
o.attach (new DataBasketImpl());
o.attach (new User("Manager"));
Shop.getTheShop().addSalesPoint (o);
}
else {
JOptionPane.showMessageDialog(null,
"Access denied!");
}
}
});
msShopMenu.add (msManagerItem);
msShopMenu.add (msSeparator);
msShopMenu.add (msLoadItem);
msShopMenu.add (msSaveItem);
msShopMenu.add (msSeparator);
msShopMenu.add (msQuitItem);
return msMenuBar;
}
public void quit()
{
if (Shop.getTheShop().shutdown (false)) {
System.exit (0);
}
}
public static void addCustomer(Customer customer)
{
customerSet.add(customer);
}
public static void removeCustomer(Customer customer)
{
customerSet.remove(customer);
Shop.getTheShop().removeStock(customer.getCustomerID());
}
public static Set getAllCustomer()
{
return customerSet.isEmpty() ? null : customerSet;
}
public static Customer getCustomerByID(String customerID)
{
Iterator i = customerSet.iterator();
while (i.hasNext()) {
Customer customer = (Customer)i.next();
if (customer.getCustomerID().equals(customerID))
return customer;
}
return null;
}
}