Advertisement
Guest User

Untitled

a guest
Jun 15th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.37 KB | None | 0 0
  1. public class RestaurantService {
  2.     private ArrayList<Product> allProducts =  new ArrayList<Product>();
  3.     private ArrayList<Order> allOrders = new ArrayList<Order>();
  4.    
  5.     private OrderDAO oDao = new OrderDAO();
  6.     private ProductDAO pDao = new ProductDAO();
  7.     private OrderProductDAO opDao = new OrderProductDAO();
  8.    
  9.    
  10.    
  11.     public void addProduct(int id, String nm, int sk, double pr){
  12.         if(allProducts.contains(nm)){
  13.             throw new IllegalArgumentException("Product Bestaat al!");
  14.            
  15.         }
  16.         else{
  17.             Product p = new Product(id, sk, nm, pr);
  18.             allProducts.add(p);
  19.         }
  20.     }
  21.    
  22.     public void addOrderForTable(int productID, int amount, Order o){
  23.         OrderProduct oP = new OrderProduct(productID, amount);
  24.         o.addProduct(oP);
  25.     }
  26.    
  27.     public List<Product> showAllProducts() throws ClassNotFoundException{
  28.         return pDao.findAll();
  29.     }
  30.    
  31.     public Product findProductbyID(int productID) throws ClassNotFoundException{
  32.         Product p = pDao.findByID(productID);
  33.         return p;
  34.     }
  35.    
  36.     public List<OrderProduct> showAllOrderedProducts(int tableNR, Order o) throws ClassNotFoundException {
  37.         return opDao.findOrderByTableNR(tableNR);
  38.     }
  39.    
  40.     public List<Order> showAllTables() throws ClassNotFoundException {
  41.         return oDao.findAllTables();
  42.     }
  43.    
  44.     public void deleteProduct(int productID) throws ClassNotFoundException {
  45.         Product p = pDao.findByID(productID);
  46.        
  47.         if (p != null) {
  48.             pDao.delete(p);
  49.         } else throw new IllegalArgumentException("Id does not exist!");
  50.     }
  51. }
  52.  
  53. import java.util.ArrayList;
  54.  
  55.  
  56. public class Order {
  57.     private int orderID;
  58.     private int tableNR;
  59.     private ArrayList<OrderProduct> deBesteldeProducten;
  60.    
  61.     public Order(int orderID, int tableNR){
  62.         this.orderID = orderID;
  63.         this.tableNR = tableNR;
  64.     }
  65.    
  66.     public int getOrderID(){
  67.         return orderID;
  68.     }
  69.     public int getTableNR(){
  70.         return tableNR;
  71.     }
  72.    
  73.     public void addProduct(OrderProduct oP){
  74.         deBesteldeProducten.add(oP);
  75.     }
  76.    
  77.     public ArrayList<OrderProduct> getOrderProduct(){
  78.         return deBesteldeProducten;
  79.    
  80.     }
  81.    
  82.     public double orderBedrag(){
  83.         double total = 0;
  84.         for(OrderProduct oP : deBesteldeProducten){
  85.             total += oP.productPrice();
  86.         }
  87.         return total;
  88.     }
  89.    
  90. }
  91.  
  92. package ordermap.model;
  93.  
  94. import java.util.Collections;
  95. import java.util.List;
  96.  
  97.  
  98. public class OrderProduct {
  99.     private int amount;
  100.     private Order order;
  101.     private Product hetProduct;
  102.    
  103.     public OrderProduct(Order order, int amount){
  104.         this.amount = amount;
  105.         this.order = order;
  106.         this.hetProduct = getHetProduct();
  107.        
  108.     }
  109.    
  110.     public int getAmount(){
  111.         return amount;
  112.     }
  113.    
  114.     public Order getOrder(){
  115.         return order;
  116.     }
  117.    
  118.     public void setOrder(Order order){
  119.         this.order = order;
  120.     }
  121.    
  122.     public Product getHetProduct(){
  123.         return hetProduct;
  124.     }
  125.     public void setProduct(Product hetProduct){
  126.         this.hetProduct = hetProduct;
  127.     }
  128.    
  129.     public double productPrice(){
  130.         double total = 0;
  131.         total = hetProduct.getPrice() * amount;
  132.         return total;
  133.     }
  134. }
  135.  
  136. package ordermap.model;
  137.  
  138. public class Product {
  139.     private int productID;
  140.     private int stock;
  141.     private String name;
  142.     private double price;
  143.    
  144.    
  145.     public Product(int id, int sk, String nm, double pr){
  146.         productID = id;
  147.         stock = sk;
  148.         name = nm;
  149.         price = pr;
  150.     }
  151.    
  152.     public int getProductID(){
  153.         return productID;
  154.     }
  155.    
  156.     public int getStock(){
  157.         return stock;
  158.     }
  159.    
  160.     public String getName(){
  161.         return name;
  162.     }
  163.    
  164.     public double getPrice(){
  165.         return price;
  166.     }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement