Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
683 changes: 517 additions & 166 deletions nbproject/build-impl.xml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions nbproject/genfiles.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build.xml.data.CRC32=9890839f
build.xml.script.CRC32=e3f1649b
build.xml.stylesheet.CRC32=8064a381@1.75.2.48
build.xml.stylesheet.CRC32=f85dc8f2@1.104.0.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=9890839f
nbproject/build-impl.xml.script.CRC32=f1ae2812
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
nbproject/build-impl.xml.script.CRC32=e074d105
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.104.0.48
2 changes: 1 addition & 1 deletion nbproject/private/private.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
compile.on.save=true
user.properties.file=/Users/Sopnopriyo/Library/Application Support/NetBeans/8.2/build.properties
user.properties.file=C:\\Users\\melis\\AppData\\Roaming\\NetBeans\\15\\build.properties
15 changes: 11 additions & 4 deletions nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/Users/Sopnopriyo/Sopnopriyo/Restaurant-Management-System/src/restaurentsystem/item/ViewItem.java</file>
<file>file:/Users/Sopnopriyo/Sopnopriyo/Restaurant-Management-System/src/restaurentsystem/item/ItemMngmnt.java</file>
<file>file:/Users/Sopnopriyo/Sopnopriyo/Restaurant-Management-System/src/restaurantsystem/RestaurentManagement.java</file>
<file>file:/Users/Sopnopriyo/Sopnopriyo/Restaurant-Management-System/src/restaurentsystem/labour/DeleteLabour.java</file>
<file>file:/C:/Users/melis/eclipse-workspace/RepoTareaDisenoPatrones/restaurant-management-system/src/restaurantsystem/model/Iterator.java</file>
<file>file:/C:/Users/melis/eclipse-workspace/RepoTareaDisenoPatrones/restaurant-management-system/src/restaurantsystem/service/ManageService.java</file>
<file>file:/C:/Users/melis/eclipse-workspace/RepoTareaDisenoPatrones/restaurant-management-system/src/restaurantsystem/model/Cart.java</file>
<file>file:/C:/Users/melis/eclipse-workspace/RepoTareaDisenoPatrones/restaurant-management-system/src/restaurantsystem/model/Order.java</file>
<file>file:/C:/Users/melis/eclipse-workspace/RepoTareaDisenoPatrones/restaurant-management-system/src/restaurantsystem/model/Labour.java</file>
<file>file:/C:/Users/melis/eclipse-workspace/RepoTareaDisenoPatrones/restaurant-management-system/src/restaurantsystem/model/CartItem.java</file>
<file>file:/C:/Users/melis/eclipse-workspace/RepoTareaDisenoPatrones/restaurant-management-system/src/restaurantsystem/service/ItemService.java</file>
<file>file:/C:/Users/melis/eclipse-workspace/RepoTareaDisenoPatrones/restaurant-management-system/src/restaurantsystem/model/OrderLine.java</file>
<file>file:/C:/Users/melis/eclipse-workspace/RepoTareaDisenoPatrones/restaurant-management-system/src/restaurantsystem/model/IterableCollection.java</file>
<file>file:/C:/Users/melis/eclipse-workspace/RepoTareaDisenoPatrones/restaurant-management-system/src/restaurantsystem/model/Item.java</file>
<file>file:/C:/Users/melis/eclipse-workspace/RepoTareaDisenoPatrones/restaurant-management-system/src/restaurantsystem/model/CartIterator.java</file>
</group>
</open-files>
</project-private>
12 changes: 12 additions & 0 deletions nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ build.test.results.dir=${build.dir}/test/results
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.modulepath=\
${run.modulepath}
debug.test.classpath=\
${run.test.classpath}
debug.test.modulepath=\
${run.test.modulepath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
Expand All @@ -33,13 +37,17 @@ javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.modulepath=\
${javac.modulepath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
Expand All @@ -65,9 +73,13 @@ run.classpath=\
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
run.test.modulepath=\
${javac.test.modulepath}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
10 changes: 7 additions & 3 deletions src/restaurantsystem/component/item/AddItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@

import javax.swing.*;
import restaurantsystem.model.Item;
import restaurantsystem.service.ItemService;
import restaurantsystem.service.ConcreteFactory;
import restaurantsystem.service.Factory;
import restaurantsystem.service.ManageService;
import restaurantsystem.service.ServiceType;

/**
*
* @author Shahin
*/
public class AddItem extends javax.swing.JFrame {

private final ItemService itemService;
private final ManageService itemService;

/**
* Creates new form InsertItem
*/
public AddItem() {
initComponents();
this.itemService = new ItemService();
Factory fct = new ConcreteFactory();
this.itemService = fct.createService(ServiceType.ITEM_SERVICE);
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/restaurantsystem/component/labour/AddLabour.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@

import javax.swing.JOptionPane;
import restaurantsystem.model.Labour;
import restaurantsystem.service.ConcreteFactory;
import restaurantsystem.service.Factory;
import restaurantsystem.service.LabourService;
import restaurantsystem.service.ManageService;
import restaurantsystem.service.ServiceType;

/**
*
* @author Shahin
*/
public class AddLabour extends javax.swing.JFrame {

private final LabourService labourService;
private final ManageService labourService;

/**
* Creates new form InserLabour
*/
public AddLabour() {
initComponents();
this.labourService = new LabourService();
Factory fct = new ConcreteFactory();
this.labourService = fct.createService(ServiceType.LABOUR_SERVICE);
}

/**
Expand Down
14 changes: 10 additions & 4 deletions src/restaurantsystem/model/Cart.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @author Sopnopriyo
*/
public class Cart {
public class Cart implements IterableCollection{

private List<CartItem> cartItems;
private double totalPrice;
Expand All @@ -35,13 +35,19 @@ public void addItemToCart(CartItem cartItem) {

public double getTotalPrice() {
totalPrice = 0;
cartItems.forEach((cartItem) -> {
totalPrice += cartItem.getPrice();
});
CartIterator it = (CartIterator) createIterator();
while(it.hasNext()){
totalPrice += it.next().getPrice();
}
return totalPrice;
}

public void setTotalPrice(double totalPrice) {
this.totalPrice = totalPrice;
}

@Override
public Iterator createIterator() {
return new CartIterator(this);
}
}
31 changes: 31 additions & 0 deletions src/restaurantsystem/model/CartIterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package restaurantsystem.model;

/**
*
* @author melis
*/
public class CartIterator implements Iterator {
private Cart cart;
private int currentState = 0;

public CartIterator(Cart cart){
this.cart = cart;
}

@Override
public CartItem next() {
CartItem item = cart.getCartItems().get(currentState);
currentState ++;
return item;
}

@Override
public boolean hasNext() {
return cart.getCartItems().size()-1 != currentState;
}

}
13 changes: 13 additions & 0 deletions src/restaurantsystem/model/IterableCollection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package restaurantsystem.model;

/**
*
* @author melis
*/
public interface IterableCollection {
public Iterator createIterator();
}
14 changes: 14 additions & 0 deletions src/restaurantsystem/model/Iterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package restaurantsystem.model;

/**
*
* @author melis
*/
public interface Iterator<E> {
public E next();
public boolean hasNext();
}
25 changes: 25 additions & 0 deletions src/restaurantsystem/service/ConcreteFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package restaurantsystem.service;

/**
*
* @author melis
*/
public class ConcreteFactory extends Factory{

@Override
public ManageService createService(ServiceType type) {
switch(type){
case ITEM_SERVICE:
return new ItemService();
case LABOUR_SERVICE:
return new LabourService();
default:
return null;
}
}

}
13 changes: 13 additions & 0 deletions src/restaurantsystem/service/Factory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package restaurantsystem.service;

/**
*
* @author melis
*/
public abstract class Factory {
public abstract ManageService createService(ServiceType type);
}
5 changes: 4 additions & 1 deletion src/restaurantsystem/service/ItemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
*
* @author Sopnopriyo
*/
public class ItemService {
public class ItemService implements ManageService<Item>{

public ItemService() {
}

@Override
public List<Item> getAll() {
List<Item> items = new ArrayList<>();
try (Scanner scanner = new Scanner(new FileInputStream("storage/item.txt"))) {
Expand Down Expand Up @@ -58,6 +59,7 @@ public Item getItemByIndex(int index) {
return null;
}

@Override
public void create(Item item) {
try (PrintWriter pw = new PrintWriter(new FileOutputStream("storage/item.txt", true))) {
pw.println(item.getName() + "," + item.getPrice() + "," + item.getQuantity());
Expand All @@ -66,6 +68,7 @@ public void create(Item item) {
}
}

@Override
public synchronized boolean delete(String name) {

List<Item> itemList = getAll();
Expand Down
13 changes: 10 additions & 3 deletions src/restaurantsystem/service/LabourService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
*
* @author Sopnopriyo
*/
public class LabourService {
public class LabourService implements ManageService<Labour>{

public LabourService() {
}

@Override
public List<Labour> getAll() {
List<Labour> labourList = new ArrayList<>();
try (Scanner scanner = new Scanner(new FileInputStream("storage/labour.txt"))) {
Expand All @@ -50,6 +51,7 @@ public List<Labour> getAll() {
return labourList;
}

@Override
public void create(Labour labour) {
try (PrintWriter pw = new PrintWriter(new FileOutputStream("storage/labour.txt", true))) {
pw.println(labour.getId() + "," + labour.getName() + "," + labour.getSalary());
Expand All @@ -58,6 +60,7 @@ public void create(Labour labour) {
}
}

@Override
public synchronized boolean update(String sourceId, Labour updatedLabour) {
// Read all the items
List<Labour> labourList = getAll();
Expand Down Expand Up @@ -94,17 +97,20 @@ public synchronized boolean update(String sourceId, Labour updatedLabour) {
return true;
}

public synchronized void delete(String labourID) {
@Override
public synchronized boolean delete(String labourID) {
List<Labour> labourList = getAll();

boolean j = false;
// find the labour to be deleted
for (int i = 0; i < labourList.size(); i++) {

Labour labour = labourList.get(i);

if (labour.getId().equalsIgnoreCase(labourID)) {
labourList.remove(labour);
return true;
}

}

try {
Expand All @@ -122,5 +128,6 @@ public synchronized void delete(String labourID) {
} catch (FileNotFoundException ex) {
Logger.getLogger(LabourService.class.getName()).log(Level.SEVERE, null, ex);
}
return j;
}
}
18 changes: 18 additions & 0 deletions src/restaurantsystem/service/ManageService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package restaurantsystem.service;

import java.util.List;

/**
*
* @author melis
*/
public interface ManageService<E> {
public List<E> getAll();
public void create(E type);
public boolean update(String id, E type);
public boolean delete(String type);
}
14 changes: 14 additions & 0 deletions src/restaurantsystem/service/ServiceType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Enum.java to edit this template
*/
package restaurantsystem.service;

/**
*
* @author melis
*/
public enum ServiceType {
ITEM_SERVICE,
LABOUR_SERVICE
}