From 72603a2df0e2338cd5f90731a6e2564595d26193 Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Thu, 11 Jun 2020 15:19:13 +0300 Subject: [PATCH 01/48] trying --- src/{Controller => controller}/AutoFuncController.java | 2 +- src/{Controller => controller}/ItemController.java | 2 +- src/{Controller => controller}/ManagerController.java | 2 +- src/{Controller => controller}/MemberController.java | 2 +- src/{Controller => controller}/PurchaseController.java | 2 +- src/{Controller => controller}/StoreController.java | 2 +- src/{Controller => controller}/WorkerController.java | 2 +- src/driver/MVCDriver.java | 4 ++-- src/{Model => model}/AutoFuncModel.java | 0 src/{Model => model}/ItemModel.java | 0 src/{Model => model}/ManagerModel.java | 0 src/{Model => model}/MemberModel.java | 0 src/{Model => model}/PurchaseModel.java | 0 src/{Model => model}/StoreModel.java | 0 src/{Model => model}/WorkerModel.java | 0 src/{Model => model}/entities/Item.java | 0 src/{Model => model}/entities/Manager.java | 0 src/{Model => model}/entities/Member.java | 0 src/{Model => model}/entities/Pants.java | 0 src/{Model => model}/entities/Person.java | 0 src/{Model => model}/entities/Purchase.java | 0 src/{Model => model}/entities/Shirt.java | 0 src/{Model => model}/entities/Shoe.java | 0 src/{Model => model}/entities/Worker.java | 0 src/{View => view}/UserInterface.java | 5 +---- src/{View => view}/ViewInterface.java | 4 ++-- 26 files changed, 12 insertions(+), 15 deletions(-) rename src/{Controller => controller}/AutoFuncController.java (96%) rename src/{Controller => controller}/ItemController.java (98%) rename src/{Controller => controller}/ManagerController.java (98%) rename src/{Controller => controller}/MemberController.java (98%) rename src/{Controller => controller}/PurchaseController.java (98%) rename src/{Controller => controller}/StoreController.java (99%) rename src/{Controller => controller}/WorkerController.java (97%) rename src/{Model => model}/AutoFuncModel.java (100%) rename src/{Model => model}/ItemModel.java (100%) rename src/{Model => model}/ManagerModel.java (100%) rename src/{Model => model}/MemberModel.java (100%) rename src/{Model => model}/PurchaseModel.java (100%) rename src/{Model => model}/StoreModel.java (100%) rename src/{Model => model}/WorkerModel.java (100%) rename src/{Model => model}/entities/Item.java (100%) rename src/{Model => model}/entities/Manager.java (100%) rename src/{Model => model}/entities/Member.java (100%) rename src/{Model => model}/entities/Pants.java (100%) rename src/{Model => model}/entities/Person.java (100%) rename src/{Model => model}/entities/Purchase.java (100%) rename src/{Model => model}/entities/Shirt.java (100%) rename src/{Model => model}/entities/Shoe.java (100%) rename src/{Model => model}/entities/Worker.java (100%) rename src/{View => view}/UserInterface.java (94%) rename src/{View => view}/ViewInterface.java (60%) diff --git a/src/Controller/AutoFuncController.java b/src/controller/AutoFuncController.java similarity index 96% rename from src/Controller/AutoFuncController.java rename to src/controller/AutoFuncController.java index 98cca1c..885446b 100644 --- a/src/Controller/AutoFuncController.java +++ b/src/controller/AutoFuncController.java @@ -1,5 +1,5 @@ package controller; -import View.*; +import view.*; import model.*; diff --git a/src/Controller/ItemController.java b/src/controller/ItemController.java similarity index 98% rename from src/Controller/ItemController.java rename to src/controller/ItemController.java index 1edd450..75c9f29 100644 --- a/src/Controller/ItemController.java +++ b/src/controller/ItemController.java @@ -1,5 +1,5 @@ package controller; -import View.*; +import view.*; import model.*; import model.entities.*; diff --git a/src/Controller/ManagerController.java b/src/controller/ManagerController.java similarity index 98% rename from src/Controller/ManagerController.java rename to src/controller/ManagerController.java index 8428892..905697b 100644 --- a/src/Controller/ManagerController.java +++ b/src/controller/ManagerController.java @@ -1,5 +1,5 @@ package controller; -import View.*; +import view.*; import model.*; import model.entities.Worker; diff --git a/src/Controller/MemberController.java b/src/controller/MemberController.java similarity index 98% rename from src/Controller/MemberController.java rename to src/controller/MemberController.java index 536f7f5..f3eeca1 100644 --- a/src/Controller/MemberController.java +++ b/src/controller/MemberController.java @@ -1,5 +1,5 @@ package controller; -import View.*; +import view.*; import model.*; import model.entities.Member; diff --git a/src/Controller/PurchaseController.java b/src/controller/PurchaseController.java similarity index 98% rename from src/Controller/PurchaseController.java rename to src/controller/PurchaseController.java index a24332d..68e255c 100644 --- a/src/Controller/PurchaseController.java +++ b/src/controller/PurchaseController.java @@ -1,5 +1,5 @@ package controller; -import View.*; +import view.*; import model.*; import model.entities.Member; import model.entities.Purchase; diff --git a/src/Controller/StoreController.java b/src/controller/StoreController.java similarity index 99% rename from src/Controller/StoreController.java rename to src/controller/StoreController.java index ae6affd..6672226 100644 --- a/src/Controller/StoreController.java +++ b/src/controller/StoreController.java @@ -1,5 +1,5 @@ package controller; -import View.*; +import view.*; import model.*; import model.entities.*; diff --git a/src/Controller/WorkerController.java b/src/controller/WorkerController.java similarity index 97% rename from src/Controller/WorkerController.java rename to src/controller/WorkerController.java index 2e58fb1..8a6f11b 100644 --- a/src/Controller/WorkerController.java +++ b/src/controller/WorkerController.java @@ -1,5 +1,5 @@ package controller; -import View.*; +import view.*; import model.*; import model.entities.Worker; diff --git a/src/driver/MVCDriver.java b/src/driver/MVCDriver.java index 25f216d..268362d 100644 --- a/src/driver/MVCDriver.java +++ b/src/driver/MVCDriver.java @@ -1,6 +1,6 @@ package driver; -import View.UserInterface; -import View.ViewInterface; +import view.UserInterface; +import view.ViewInterface; import controller.OpenController; import model.OpenModel; diff --git a/src/Model/AutoFuncModel.java b/src/model/AutoFuncModel.java similarity index 100% rename from src/Model/AutoFuncModel.java rename to src/model/AutoFuncModel.java diff --git a/src/Model/ItemModel.java b/src/model/ItemModel.java similarity index 100% rename from src/Model/ItemModel.java rename to src/model/ItemModel.java diff --git a/src/Model/ManagerModel.java b/src/model/ManagerModel.java similarity index 100% rename from src/Model/ManagerModel.java rename to src/model/ManagerModel.java diff --git a/src/Model/MemberModel.java b/src/model/MemberModel.java similarity index 100% rename from src/Model/MemberModel.java rename to src/model/MemberModel.java diff --git a/src/Model/PurchaseModel.java b/src/model/PurchaseModel.java similarity index 100% rename from src/Model/PurchaseModel.java rename to src/model/PurchaseModel.java diff --git a/src/Model/StoreModel.java b/src/model/StoreModel.java similarity index 100% rename from src/Model/StoreModel.java rename to src/model/StoreModel.java diff --git a/src/Model/WorkerModel.java b/src/model/WorkerModel.java similarity index 100% rename from src/Model/WorkerModel.java rename to src/model/WorkerModel.java diff --git a/src/Model/entities/Item.java b/src/model/entities/Item.java similarity index 100% rename from src/Model/entities/Item.java rename to src/model/entities/Item.java diff --git a/src/Model/entities/Manager.java b/src/model/entities/Manager.java similarity index 100% rename from src/Model/entities/Manager.java rename to src/model/entities/Manager.java diff --git a/src/Model/entities/Member.java b/src/model/entities/Member.java similarity index 100% rename from src/Model/entities/Member.java rename to src/model/entities/Member.java diff --git a/src/Model/entities/Pants.java b/src/model/entities/Pants.java similarity index 100% rename from src/Model/entities/Pants.java rename to src/model/entities/Pants.java diff --git a/src/Model/entities/Person.java b/src/model/entities/Person.java similarity index 100% rename from src/Model/entities/Person.java rename to src/model/entities/Person.java diff --git a/src/Model/entities/Purchase.java b/src/model/entities/Purchase.java similarity index 100% rename from src/Model/entities/Purchase.java rename to src/model/entities/Purchase.java diff --git a/src/Model/entities/Shirt.java b/src/model/entities/Shirt.java similarity index 100% rename from src/Model/entities/Shirt.java rename to src/model/entities/Shirt.java diff --git a/src/Model/entities/Shoe.java b/src/model/entities/Shoe.java similarity index 100% rename from src/Model/entities/Shoe.java rename to src/model/entities/Shoe.java diff --git a/src/Model/entities/Worker.java b/src/model/entities/Worker.java similarity index 100% rename from src/Model/entities/Worker.java rename to src/model/entities/Worker.java diff --git a/src/View/UserInterface.java b/src/view/UserInterface.java similarity index 94% rename from src/View/UserInterface.java rename to src/view/UserInterface.java index aee1810..2f97433 100644 --- a/src/View/UserInterface.java +++ b/src/view/UserInterface.java @@ -1,9 +1,6 @@ -package View; +package view; import controller.*; -import model.MemberModel; - -import java.util.Scanner; public class UserInterface implements ViewInterface, Runnable { private AutoFuncController autoFuncController; diff --git a/src/View/ViewInterface.java b/src/view/ViewInterface.java similarity index 60% rename from src/View/ViewInterface.java rename to src/view/ViewInterface.java index cd1033a..7ed40fe 100644 --- a/src/View/ViewInterface.java +++ b/src/view/ViewInterface.java @@ -1,5 +1,5 @@ -package View; -import controller.*; +package view; + public interface ViewInterface { void start(); From c3569675d77269b566218ed5abf2c406339e750b Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Thu, 11 Jun 2020 15:23:35 +0300 Subject: [PATCH 02/48] trying 3 --- src/controller/AutoFuncController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/controller/AutoFuncController.java b/src/controller/AutoFuncController.java index 885446b..f7fbbad 100644 --- a/src/controller/AutoFuncController.java +++ b/src/controller/AutoFuncController.java @@ -15,8 +15,7 @@ public AutoFuncController(ViewInterface viewInterface, AutoFuncModel model) { public AutoFuncController() { } - - +//hellooooooo public void checkCurrentStockThread() { model.checkCurrentStockThread(); From 30818fa116f8f9a58c6dd52b8950c6bd9fffcfee Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Thu, 11 Jun 2020 15:40:07 +0300 Subject: [PATCH 03/48] working! --- src/controller/AutoFuncController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/AutoFuncController.java b/src/controller/AutoFuncController.java index f7fbbad..da0d649 100644 --- a/src/controller/AutoFuncController.java +++ b/src/controller/AutoFuncController.java @@ -15,7 +15,7 @@ public AutoFuncController(ViewInterface viewInterface, AutoFuncModel model) { public AutoFuncController() { } -//hellooooooo + public void checkCurrentStockThread() { model.checkCurrentStockThread(); From 66deca83d7408ecead6cdde25675b050cee26258 Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Thu, 11 Jun 2020 16:50:58 +0300 Subject: [PATCH 04/48] the start of the controller --- .../ProjectClothingStore.kotlin_module | Bin 0 -> 16 bytes .../ProjectClothingStore.kotlin_module | Bin 0 -> 16 bytes src/controller/AutoFuncController.java | 9 ++---- src/controller/ItemController.java | 18 ++++------- src/controller/ManagerController.java | 10 ++----- src/controller/MemberController.java | 10 ++----- src/controller/PurchaseController.java | 9 ++---- src/controller/StoreController.java | 28 +++++------------- src/controller/WorkerController.java | 9 ++---- src/driver/MVCDriver.java | 8 +---- src/model/ItemModel.java | 13 ++++---- src/model/StoreModel.java | 11 +++---- .../ProjectClothingStore.kotlin_module | Bin 0 -> 16 bytes src/view/UserInterface.java | 26 +++++----------- src/view/ViewInterface.java | 6 ---- 15 files changed, 43 insertions(+), 114 deletions(-) create mode 100644 production/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module create mode 100644 production/production/ProjectClothingStore/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module create mode 100644 src/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module delete mode 100644 src/view/ViewInterface.java diff --git a/production/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module b/production/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module new file mode 100644 index 0000000000000000000000000000000000000000..a49347afef10a9b5f95305e1058ba36adec7d6dd GIT binary patch literal 16 RcmZQzU|?ooU|@t|0RRA102TlM literal 0 HcmV?d00001 diff --git a/production/production/ProjectClothingStore/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module b/production/production/ProjectClothingStore/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module new file mode 100644 index 0000000000000000000000000000000000000000..a49347afef10a9b5f95305e1058ba36adec7d6dd GIT binary patch literal 16 RcmZQzU|?ooU|@t|0RRA102TlM literal 0 HcmV?d00001 diff --git a/src/controller/AutoFuncController.java b/src/controller/AutoFuncController.java index da0d649..c43b21c 100644 --- a/src/controller/AutoFuncController.java +++ b/src/controller/AutoFuncController.java @@ -4,16 +4,11 @@ public class AutoFuncController { - ViewInterface viewInterface; - AutoFuncModel model; - public AutoFuncController(ViewInterface viewInterface, AutoFuncModel model) { - this.viewInterface = viewInterface; - this.model = model; - } + protected AutoFuncModel model; public AutoFuncController() { - + this.model = new AutoFuncModel(); } public void checkCurrentStockThread() diff --git a/src/controller/ItemController.java b/src/controller/ItemController.java index 75c9f29..20509d5 100644 --- a/src/controller/ItemController.java +++ b/src/controller/ItemController.java @@ -5,41 +5,33 @@ public class ItemController { - ViewInterface viewInterface; - model.ItemModel model; - public ItemController(ViewInterface viewInterface, ItemModel model) { - this.viewInterface = viewInterface; - this.model = model; - } + protected model.ItemModel model; public ItemController() { - + this.model = new ItemModel(); } public Item searchItem(int id, int size) { return model.searchItem(id, size); } - public Item bestSellingProduct() { - return model.bestSellingProduct(); + public int bestSellingProduct() { + int x = model.bestSellingProduct().getItemId(); + return x; } public boolean isItemsInStock(Purchase pur) { return model.isItemsInStock(pur); } - public void addPants(Pants pants) { model.addPants(pants); } - public void addShoe(Shoe shoe) { model.addShoe(shoe); } - - public void addShirt(Shirt shirt) { model.addShirt(shirt); diff --git a/src/controller/ManagerController.java b/src/controller/ManagerController.java index 905697b..67512a1 100644 --- a/src/controller/ManagerController.java +++ b/src/controller/ManagerController.java @@ -5,16 +5,12 @@ public class ManagerController { - ViewInterface viewInterface; - model.ManagerModel model; - public ManagerController(ViewInterface viewInterface, ManagerModel model) { - this.viewInterface = viewInterface; - this.model = model; - } + protected model.ManagerModel model; - public ManagerController() { + public ManagerController() { + this.model = new ManagerModel(); } public String ChangeHourlySalary(int workerId, double newSalary) { diff --git a/src/controller/MemberController.java b/src/controller/MemberController.java index f3eeca1..00073ec 100644 --- a/src/controller/MemberController.java +++ b/src/controller/MemberController.java @@ -5,16 +5,12 @@ public class MemberController { - ViewInterface viewInterface; - model.MemberModel model; - public MemberController(ViewInterface viewInterface, MemberModel model) { - this.viewInterface = viewInterface; - this.model = model; - } + protected model.MemberModel model; - public MemberController() { + public MemberController() { + this.model = new MemberModel(); } public void addClubMember(Member m) diff --git a/src/controller/PurchaseController.java b/src/controller/PurchaseController.java index 68e255c..f2bace5 100644 --- a/src/controller/PurchaseController.java +++ b/src/controller/PurchaseController.java @@ -6,16 +6,11 @@ public class PurchaseController { - ViewInterface viewInterface; - model.PurchaseModel model; - public PurchaseController(ViewInterface viewInterface, PurchaseModel model) { - this.viewInterface = viewInterface; - this.model = model; - } + protected model.PurchaseModel model; public PurchaseController() { - + this.model = new PurchaseModel(); } diff --git a/src/controller/StoreController.java b/src/controller/StoreController.java index 6672226..e00d65b 100644 --- a/src/controller/StoreController.java +++ b/src/controller/StoreController.java @@ -7,23 +7,14 @@ public class StoreController { - ViewInterface viewInterface; - model.StoreModel model; - public StoreController(ViewInterface viewInterface, StoreModel model) { - this.viewInterface = viewInterface; - this.model = model; - } + protected model.StoreModel model; public StoreController() { - } - public static StoreModel getInstance() - { - return StoreModel.getInstance(); - } + public static ArrayList getAllPurchase() { return StoreModel.getAllPurchase(); @@ -44,6 +35,10 @@ public static ArrayList getWorkers() return StoreModel.getWorkers(); } + + + + public int averageSellingRate() { return model.averageSellingRate(); @@ -54,9 +49,7 @@ public int Login(int id, String password) return model.Login(id, password); } - - public boolean isManager(int id, String password) - { + public boolean isManager(int id, String password) { String idString =String.valueOf(id); if (idString == null || idString.trim().equals("") || password == null || password.trim().equals("")) { throw new IllegalArgumentException("Username or password must not be null"); @@ -70,8 +63,7 @@ public boolean isManager(int id, String password) return false; } - public boolean isWorker(int id, String password) - { + public boolean isWorker(int id, String password){ String idString =String.valueOf(id); if (idString == null || idString.trim().equals("") || password == null || password.trim().equals("")) { throw new IllegalArgumentException("Username or password must not be null"); @@ -84,8 +76,4 @@ public boolean isWorker(int id, String password) return false; } - - - - } diff --git a/src/controller/WorkerController.java b/src/controller/WorkerController.java index 8a6f11b..766a6b5 100644 --- a/src/controller/WorkerController.java +++ b/src/controller/WorkerController.java @@ -4,16 +4,11 @@ import model.entities.Worker; public class WorkerController { - ViewInterface viewInterface; - model.WorkerModel model; - public WorkerController(ViewInterface viewInterface, WorkerModel model) { - this.viewInterface = viewInterface; - this.model = model; - } + model.WorkerModel model; public WorkerController() { - + this.model = new WorkerModel(); } public void addWorker(Worker w) { diff --git a/src/driver/MVCDriver.java b/src/driver/MVCDriver.java index 268362d..61356e5 100644 --- a/src/driver/MVCDriver.java +++ b/src/driver/MVCDriver.java @@ -1,17 +1,11 @@ package driver; import view.UserInterface; -import view.ViewInterface; -import controller.OpenController; -import model.OpenModel; public class MVCDriver { public static void main(String[] args) { - ViewInterface view = new UserInterface(); + UserInterface view = new UserInterface(); view.start(); - - - } } diff --git a/src/model/ItemModel.java b/src/model/ItemModel.java index 0ca699d..97a4565 100644 --- a/src/model/ItemModel.java +++ b/src/model/ItemModel.java @@ -68,14 +68,13 @@ public boolean isItemsInStock(Purchase pur) { return true; } - public void addPants(Pants pants) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?);"; @@ -112,12 +111,11 @@ public void addPants(Pants pants) { } - public void addShoe(Shoe shoe) - { + public void addShoe(Shoe shoe) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; @@ -154,13 +152,12 @@ public void addShoe(Shoe shoe) } - public void addShirt(Shirt shirt) - { + public void addShirt(Shirt shirt) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; diff --git a/src/model/StoreModel.java b/src/model/StoreModel.java index 4684361..eac9735 100644 --- a/src/model/StoreModel.java +++ b/src/model/StoreModel.java @@ -34,7 +34,7 @@ public static ArrayList getAllPurchase() { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -148,7 +148,7 @@ public static ArrayList getClubMembers() { ClubMembers = new ArrayList(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -190,7 +190,7 @@ public static ArrayList getItems() { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -250,7 +250,7 @@ public static ArrayList getWorkers() { Workers = new ArrayList<>(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -309,8 +309,6 @@ public int averageSellingRate() { } - - public int Login(int id, String password) { int i; ArrayList Workers = null; @@ -345,7 +343,6 @@ public String isManager(int id, String password) { return null; } - public String isWorker(int id, String password) { try { int i = Login(id, password); diff --git a/src/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module b/src/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module new file mode 100644 index 0000000000000000000000000000000000000000..a49347afef10a9b5f95305e1058ba36adec7d6dd GIT binary patch literal 16 RcmZQzU|?ooU|@t|0RRA102TlM literal 0 HcmV?d00001 diff --git a/src/view/UserInterface.java b/src/view/UserInterface.java index 2f97433..7e3ef77 100644 --- a/src/view/UserInterface.java +++ b/src/view/UserInterface.java @@ -2,50 +2,40 @@ import controller.*; -public class UserInterface implements ViewInterface, Runnable { +public class UserInterface implements Runnable { private AutoFuncController autoFuncController; private ItemController itemController; private ManagerController managerController; private MemberController memberController; - private OpenController openController; private PurchaseController purchaseController; private StoreController storeController; private WorkerController workerController; - public UserInterface() { - autoFuncController = new AutoFuncController(); itemController = new ItemController(); managerController = new ManagerController(); memberController = new MemberController(); - openController = new OpenController(); purchaseController = new PurchaseController(); storeController = new StoreController(); workerController = new WorkerController(); - - - } - - - @Override public void start() { new Thread(this).run(); } - - + @Override public void run() { - System.out.println("Welcome to the clothing store management system"); - memberController.birthdayPointAuto(); - - - + workerScreen(); + } + public void workerScreen() + { + System.out.println("Welcome to the clothing store management system"); + System.out.print(itemController.bestSellingProduct()); } } \ No newline at end of file diff --git a/src/view/ViewInterface.java b/src/view/ViewInterface.java deleted file mode 100644 index 7ed40fe..0000000 --- a/src/view/ViewInterface.java +++ /dev/null @@ -1,6 +0,0 @@ -package view; - -public interface ViewInterface { - void start(); - -} From 77ba41ac5bceef94e82ea0a96b6c023be9dd77f2 Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Thu, 11 Jun 2020 17:45:26 +0300 Subject: [PATCH 05/48] new class --- src/controller/StoreController.java | 43 ---------------- src/model/AutoFuncModel.java | 1 + src/model/GeneralOpModel.java | 77 +++++++++++++++++++++++++++++ src/model/ItemModel.java | 1 - src/model/MemberModel.java | 5 -- src/model/PurchaseModel.java | 3 -- src/model/StoreModel.java | 63 ----------------------- 7 files changed, 78 insertions(+), 115 deletions(-) create mode 100644 src/model/GeneralOpModel.java diff --git a/src/controller/StoreController.java b/src/controller/StoreController.java index e00d65b..b3047f5 100644 --- a/src/controller/StoreController.java +++ b/src/controller/StoreController.java @@ -13,8 +13,6 @@ public class StoreController { public StoreController() { } - - public static ArrayList getAllPurchase() { return StoreModel.getAllPurchase(); @@ -35,45 +33,4 @@ public static ArrayList getWorkers() return StoreModel.getWorkers(); } - - - - - public int averageSellingRate() - { - return model.averageSellingRate(); - } - - public int Login(int id, String password) - { - return model.Login(id, password); - } - - public boolean isManager(int id, String password) { - String idString =String.valueOf(id); - if (idString == null || idString.trim().equals("") || password == null || password.trim().equals("")) { - throw new IllegalArgumentException("Username or password must not be null"); - } - String session = model.isManager(id, password); - if (session != null) { - System.out.println("Session token: " + session); - return true; - } - - return false; - } - - public boolean isWorker(int id, String password){ - String idString =String.valueOf(id); - if (idString == null || idString.trim().equals("") || password == null || password.trim().equals("")) { - throw new IllegalArgumentException("Username or password must not be null"); - } - String session = model.isWorker(id, password); - if (session != null) { - System.out.println("Session token: " + session); - return true; - } - - return false; - } } diff --git a/src/model/AutoFuncModel.java b/src/model/AutoFuncModel.java index 1f72c4e..10ad0ff 100644 --- a/src/model/AutoFuncModel.java +++ b/src/model/AutoFuncModel.java @@ -5,6 +5,7 @@ import java.util.ArrayList; public class AutoFuncModel implements Runnable { + public void checkCurrentStock() { int i; diff --git a/src/model/GeneralOpModel.java b/src/model/GeneralOpModel.java new file mode 100644 index 0000000..2311d7a --- /dev/null +++ b/src/model/GeneralOpModel.java @@ -0,0 +1,77 @@ +package model; + +import model.entities.Purchase; +import model.entities.Worker; + +import java.util.ArrayList; +import java.util.UUID; + +public class GeneralOpModel { + public GeneralOpModel() { + } + + public int averageSellingRate() { + int i=1; + int sum=0; + ArrayList pur = new ArrayList<>(); + try { + pur = StoreModel.getInstance().getAllPurchase(); + for (i = 0; i < pur.size(); i++) { + sum += pur.get(i).getShoppingRating(); + } + sum/=i; + } catch (Exception e) { + e.printStackTrace(); + } + return sum; + + } + + public int Login(int id, String password) { + int i; + ArrayList Workers = null; + try { + Workers = new ArrayList<>(); + Workers = StoreModel.getInstance().getWorkers(); + for (i = 0; i < Workers.size(); i++) { + if((Integer.valueOf(id) == Workers.get(i).getId() && Workers.get(i).getPassword().equals(password))) + { + return Workers.get(i).getId(); + } + } + } catch (Exception e) { + e.printStackTrace(); + + } + return -1; + } + + public String isManager(int id, String password) { + int i; + try { + i = Login(id, password); + if(i == 1) + { + return UUID.randomUUID().toString(); + } + + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public String isWorker(int id, String password) { + try { + int i = Login(id, password); + if(i != -1 && i != 1) + { + return UUID.randomUUID().toString(); + } + + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/src/model/ItemModel.java b/src/model/ItemModel.java index 97a4565..c43a040 100644 --- a/src/model/ItemModel.java +++ b/src/model/ItemModel.java @@ -198,5 +198,4 @@ public void addShirt(Shirt shirt) { } - } diff --git a/src/model/MemberModel.java b/src/model/MemberModel.java index b0a49f9..0c75918 100644 --- a/src/model/MemberModel.java +++ b/src/model/MemberModel.java @@ -11,7 +11,6 @@ public class MemberModel { public MemberModel() { } - public void addClubMember(Member m) { if (isExistsClubMember(m.getId()) == false) { @@ -136,8 +135,4 @@ public void updateMembersPoints(int price, Member m) { } } } - - - - } diff --git a/src/model/PurchaseModel.java b/src/model/PurchaseModel.java index f926018..791fb41 100644 --- a/src/model/PurchaseModel.java +++ b/src/model/PurchaseModel.java @@ -78,7 +78,6 @@ public int newPrice(int price, Member m) { } - public boolean updateStockMinus(Purchase pur) { int i, j; Connection connection = null; @@ -117,6 +116,4 @@ public boolean updateStockMinus(Purchase pur) { } return true; } - - } diff --git a/src/model/StoreModel.java b/src/model/StoreModel.java index eac9735..c200f61 100644 --- a/src/model/StoreModel.java +++ b/src/model/StoreModel.java @@ -292,70 +292,7 @@ public static ArrayList getWorkers() { return Workers; } - public int averageSellingRate() { - int i=1; - int sum=0; - ArrayList pur = new ArrayList<>(); - try { - pur = StoreModel.getInstance().getAllPurchase(); - for (i = 0; i < pur.size(); i++) { - sum += pur.get(i).getShoppingRating(); - } - sum/=i; - } catch (Exception e) { - e.printStackTrace(); - } - return sum; - - } - - public int Login(int id, String password) { - int i; - ArrayList Workers = null; - try { - Workers = new ArrayList<>(); - Workers = StoreModel.getInstance().getWorkers(); - for (i = 0; i < Workers.size(); i++) { - if((Integer.valueOf(id) == Workers.get(i).getId() && Workers.get(i).getPassword().equals(password))) - { - return Workers.get(i).getId(); - } - } - } catch (Exception e) { - e.printStackTrace(); - - } - return -1; - } - - public String isManager(int id, String password) { - int i; - try { - i = Login(id, password); - if(i == 1) - { - return UUID.randomUUID().toString(); - } - - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public String isWorker(int id, String password) { - try { - int i = Login(id, password); - if(i != -1 && i != 1) - { - return UUID.randomUUID().toString(); - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } } From 3d63915f51fa1c18e98e884e941a1c01cdb71fcb Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Fri, 12 Jun 2020 02:10:32 +0300 Subject: [PATCH 06/48] la --- src/controller/GeneralOpController.java | 40 ++++ src/controller/ItemController.java | 28 +-- src/controller/ManagerController.java | 4 +- src/controller/MemberController.java | 2 + src/controller/PurchaseController.java | 1 - src/model/GeneralOpModel.java | 21 +- src/model/ItemModel.java | 35 +-- src/model/ManagerModel.java | 4 +- src/model/MemberModel.java | 22 +- src/model/PurchaseModel.java | 6 +- src/model/StoreModel.java | 6 +- src/model/WorkerModel.java | 2 +- src/model/entities/Purchase.java | 1 - src/view/UserInterface.java | 142 +++++++++-- src/view/ViewFunc.java | 299 ++++++++++++++++++++++++ 15 files changed, 539 insertions(+), 74 deletions(-) create mode 100644 src/controller/GeneralOpController.java create mode 100644 src/view/ViewFunc.java diff --git a/src/controller/GeneralOpController.java b/src/controller/GeneralOpController.java new file mode 100644 index 0000000..864eaba --- /dev/null +++ b/src/controller/GeneralOpController.java @@ -0,0 +1,40 @@ +package controller; +import view.*; +import model.*; +import model.entities.*; + +public class GeneralOpController { + protected model.GeneralOpModel model; + + public GeneralOpController() { + this.model = new model.GeneralOpModel(); + } + + public double averageSellingRate() + { + return model.averageSellingRate(); + } + + public String Login(int id, String password) + { + return model.Login(id, password); + } + + public boolean isManager(int id, String password) { + String idString =String.valueOf(id); + String session = model.isManager(id, password); + if (session != null) { + return true; + } + return false; + } + + public boolean isWorker(int id, String password){ + String idString =String.valueOf(id); + String session = model.isWorker(id, password); + if (session != null) { + return true; + } + return false; + } +} diff --git a/src/controller/ItemController.java b/src/controller/ItemController.java index 20509d5..e53ab9d 100644 --- a/src/controller/ItemController.java +++ b/src/controller/ItemController.java @@ -14,26 +14,26 @@ public ItemController() { public Item searchItem(int id, int size) { - return model.searchItem(id, size); + return model.searchItem(id,size); } - public int bestSellingProduct() { - int x = model.bestSellingProduct().getItemId(); - return x; - } - public boolean isItemsInStock(Purchase pur) - { - return model.isItemsInStock(pur); + + public Item bestSellingProduct() { return model.bestSellingProduct(); } + + public boolean isAllItemsExist(Purchase pur) { + return model.isAllItemsExist(pur); } - public void addPants(Pants pants) - { + + public boolean isItemExists(int id, int size){return model.isItemExists(id,size);} + + public void addPants(Pants pants) { model.addPants(pants); } - public void addShoe(Shoe shoe) - { + + public void addShoe(Shoe shoe) { model.addShoe(shoe); } - public void addShirt(Shirt shirt) - { + + public void addShirt(Shirt shirt) { model.addShirt(shirt); } diff --git a/src/controller/ManagerController.java b/src/controller/ManagerController.java index 67512a1..c25383b 100644 --- a/src/controller/ManagerController.java +++ b/src/controller/ManagerController.java @@ -13,8 +13,8 @@ public ManagerController() { this.model = new ManagerModel(); } - public String ChangeHourlySalary(int workerId, double newSalary) { - return model.ChangeHourlySalary(workerId, newSalary); + public String changeHourlySalary(int workerId, int newSalary) { + return model.changeHourlySalary(workerId, newSalary); } public void addWorker(Worker w) { diff --git a/src/controller/MemberController.java b/src/controller/MemberController.java index 00073ec..2d9d883 100644 --- a/src/controller/MemberController.java +++ b/src/controller/MemberController.java @@ -28,6 +28,8 @@ public boolean isExistsClubMember(int id) return model.isExistsClubMember(id); } + public Member searchMember(int id){return model.searchMember(id);} + public void birthdayPointAuto() { model.birthdayPointAuto(); diff --git a/src/controller/PurchaseController.java b/src/controller/PurchaseController.java index f2bace5..a93acf9 100644 --- a/src/controller/PurchaseController.java +++ b/src/controller/PurchaseController.java @@ -13,7 +13,6 @@ public PurchaseController() { this.model = new PurchaseModel(); } - public Purchase lastPurchase(int memId) { return model.lastPurchase(memId); } diff --git a/src/model/GeneralOpModel.java b/src/model/GeneralOpModel.java index 2311d7a..49aef77 100644 --- a/src/model/GeneralOpModel.java +++ b/src/model/GeneralOpModel.java @@ -7,12 +7,9 @@ import java.util.UUID; public class GeneralOpModel { - public GeneralOpModel() { - } - - public int averageSellingRate() { + public double averageSellingRate() { int i=1; - int sum=0; + double sum=0; ArrayList pur = new ArrayList<>(); try { pur = StoreModel.getInstance().getAllPurchase(); @@ -27,7 +24,7 @@ public int averageSellingRate() { } - public int Login(int id, String password) { + public String Login(int id, String password) { int i; ArrayList Workers = null; try { @@ -36,21 +33,21 @@ public int Login(int id, String password) { for (i = 0; i < Workers.size(); i++) { if((Integer.valueOf(id) == Workers.get(i).getId() && Workers.get(i).getPassword().equals(password))) { - return Workers.get(i).getId(); + return Workers.get(i).getJobType(); } } } catch (Exception e) { e.printStackTrace(); } - return -1; + return "null"; } public String isManager(int id, String password) { - int i; + String i; try { i = Login(id, password); - if(i == 1) + if(i.equals("manager")) { return UUID.randomUUID().toString(); } @@ -63,8 +60,8 @@ public String isManager(int id, String password) { public String isWorker(int id, String password) { try { - int i = Login(id, password); - if(i != -1 && i != 1) + String i = Login(id, password); + if(i.equals("worker")) { return UUID.randomUUID().toString(); } diff --git a/src/model/ItemModel.java b/src/model/ItemModel.java index c43a040..4c72ae3 100644 --- a/src/model/ItemModel.java +++ b/src/model/ItemModel.java @@ -10,13 +10,13 @@ public class ItemModel { - public Item searchItem(int id, int size) { + public Item searchItem(int id, int size) { //if exist and in stock int i; ArrayList items = new ArrayList<>(); try { items = StoreModel.getInstance().getItems(); for (i = 0; i < items.size(); i++) { - if ((Integer.valueOf(id) == (items.get(i).getItemId()) && items.get(i).getSize() == size && items.get(i).getBaseStock() - items.get(i).getCurrentStock() > 0)) { + if (id == items.get(i).getItemId() && items.get(i).getSize() == size && (items.get(i).getBaseStock() - items.get(i).getCurrentStock()) > 0) { return items.get(i); } } @@ -25,7 +25,22 @@ public Item searchItem(int id, int size) { } Item NONE = new Shirt(); return NONE; + } + public boolean isItemExists(int id, int size) { + int i; + ArrayList items = new ArrayList<>(); + try { + items = StoreModel.getInstance().getItems(); + for (i = 0; i < items.size(); i++) { + if (id == items.get(i).getItemId() && items.get(i).getSize() == size) { + return true; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return false; } public Item bestSellingProduct() { @@ -47,19 +62,13 @@ public Item bestSellingProduct() { return temp; } - public boolean isItemsInStock(Purchase pur) { - int i, j; - - ArrayList items = new ArrayList<>(); + public boolean isAllItemsExist(Purchase pur) { + int i; try { - items = StoreModel.getInstance().getItems(); for (i = 0; i < pur.getItem().size(); i++) { - for (j = 0; j < items.size(); j++) { - if (pur.getItem().get(i).getItemId() == items.get(j).getItemId()) - if (items.get(j).getCurrentStock() <= 0) { - System.out.println("item number:" + pur.getItem().get(i).getItemId() + " is out of stock!!"); - return false; - } + if(!isItemExists(pur.getItem().get(i).getItemId(),pur.getItem().get(i).getSize())) { + System.out.println("item:" +pur.getItem().get(i).getItemId()+" is not exist!"); + return false; } } } catch (Exception e) { diff --git a/src/model/ManagerModel.java b/src/model/ManagerModel.java index 0c22927..f7952ef 100644 --- a/src/model/ManagerModel.java +++ b/src/model/ManagerModel.java @@ -4,7 +4,7 @@ public class ManagerModel extends WorkerModel { - public String ChangeHourlySalary(int workerId, double newSalary) { + public String changeHourlySalary(int workerId, int newSalary) { if (!isExistsWorker(workerId)) { return "worker are not registered!\n"; } @@ -13,7 +13,7 @@ public String ChangeHourlySalary(int workerId, double newSalary) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement stmt = connection.createStatement(); String strUpdate = "update workers set hourlysalary = " + newSalary + " where id =" + workerId; diff --git a/src/model/MemberModel.java b/src/model/MemberModel.java index 0c75918..ddbb8a9 100644 --- a/src/model/MemberModel.java +++ b/src/model/MemberModel.java @@ -17,7 +17,7 @@ public void addClubMember(Member m) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO clubmembers" + " (name, id, dateofbirth, pointgained) VALUES " + " (?, ?, ?, ?);"; @@ -56,7 +56,7 @@ public void deleteClubMember(int id) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement statement = connection.createStatement(); statement.executeUpdate(DELETE_USERS_SQL); System.out.println("Deletion was successfully"); @@ -87,6 +87,22 @@ public boolean isExistsClubMember(int id) { } + public Member searchMember(int id) { + int i; + ArrayList members = new ArrayList<>(); + try { + members = StoreModel.getInstance().getClubMembers(); + for (i = 0; i < members.size(); i++) { + if (Integer.valueOf(id) == (members.get(i).getId())) { + return members.get(i); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + public void birthdayPointAuto() { int i; ArrayList clubMembers; @@ -120,7 +136,7 @@ public void updateMembersPoints(int price, Member m) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement stmt = connection.createStatement(); String strUpdate = "update clubmembers set pointgained = pointgained +" + price + " where id =" + m.getId(); diff --git a/src/model/PurchaseModel.java b/src/model/PurchaseModel.java index 791fb41..3d92638 100644 --- a/src/model/PurchaseModel.java +++ b/src/model/PurchaseModel.java @@ -29,6 +29,8 @@ public Purchase lastPurchase(int memId) { public String selling(Purchase pur) { MemberModel memMod = new MemberModel(); + ItemModel itemModel = new ItemModel(); + if(!updateStockMinus(pur)) return "Purchase faild!"; @@ -41,7 +43,7 @@ public String selling(Purchase pur) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement stmt = connection.createStatement(); for(i=0;i getAllPurchase() { Shirt shirts = new Shirt(color, brand, gender,type, price, size, currentStock, baseStock, id, shirtsType); items.add(shirts); break; - case "pant": + case "pants": Pants pants = new Pants(color, brand, gender,type, price, size, currentStock, baseStock, id, pantsType); items.add(pants); break; @@ -115,7 +115,7 @@ public static ArrayList getAllPurchase() { Shirt shirts = new Shirt(color, brand, gender,type, price, size, currentStock, baseStock, id, shirtsType); items.add(shirts); break; - case "pant": + case "pants": Pants pants = new Pants(color, brand, gender,type, price, size, currentStock, baseStock, id, pantsType); items.add(pants); break; @@ -217,7 +217,7 @@ public static ArrayList getItems() { Shirt shirts = new Shirt(color, brand, gender, type, price, size, currentStock, baseStock, id, shirtsType); items.add(shirts); break; - case "pant": + case "pants": Pants pants = new Pants(color, brand, gender,type, price, size, currentStock, baseStock, id, pantsType); items.add(pants); break; diff --git a/src/model/WorkerModel.java b/src/model/WorkerModel.java index fc1f357..d6de904 100644 --- a/src/model/WorkerModel.java +++ b/src/model/WorkerModel.java @@ -15,7 +15,7 @@ public void addWorker(Worker w) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO workers" + " (name, id, dateofbirth, hourlysalary, numHourMonth, jobType, password) VALUES " + " (?, ?, ?, ?, ?, ?, ?);"; diff --git a/src/model/entities/Purchase.java b/src/model/entities/Purchase.java index 2ac3c87..46e56f1 100644 --- a/src/model/entities/Purchase.java +++ b/src/model/entities/Purchase.java @@ -15,5 +15,4 @@ public class Purchase { private ArrayList item; private int price; private int shoppingRating; - } diff --git a/src/view/UserInterface.java b/src/view/UserInterface.java index 7e3ef77..f5191c8 100644 --- a/src/view/UserInterface.java +++ b/src/view/UserInterface.java @@ -1,25 +1,12 @@ package view; -import controller.*; +import java.util.*; public class UserInterface implements Runnable { - private AutoFuncController autoFuncController; - private ItemController itemController; - private ManagerController managerController; - private MemberController memberController; - private PurchaseController purchaseController; - private StoreController storeController; - private WorkerController workerController; - + private ViewFunc viewFunc; public UserInterface() { - autoFuncController = new AutoFuncController(); - itemController = new ItemController(); - managerController = new ManagerController(); - memberController = new MemberController(); - purchaseController = new PurchaseController(); - storeController = new StoreController(); - workerController = new WorkerController(); + this.viewFunc = new ViewFunc(); } public void start() { @@ -28,14 +15,129 @@ public void start() { @Override public void run() { + for(int i=1;i<=3;i++) { + String str = viewFunc.login(); + if (str == "manager") { + managerScreen(); + return; + } + if (str == "worker") { + workerScreen(); + return; + } + if (str == "none") + System.out.println("try again! **num "+i+" (at the third try the program will close!)"); + } + System.out.println("you should remember your password for the next time..."); + } - workerScreen(); + public void workerScreen() + { + Scanner s = new Scanner(System.in); + while(true) { + System.out.println("Hello Worker!!"); + System.out.println("what do you want to do?(choose number)"); + System.out.println("1. search product by Id and size"); + System.out.println("2. add club member"); + System.out.println("3. delete club member"); + System.out.println("4. check if the club member exists"); + System.out.println("5. selling"); + System.out.println("6. watch last purchase"); + System.out.println("7. watch my monthly salary"); + System.out.println("Any other number to exit"); + int temp=s.nextInt(); + switch (temp) { + case 1: + viewFunc.searchItem(); + break; + case 2: + viewFunc.addClubMember(); + break; + case 3: + viewFunc.deleteClubMember(); + break; + case 4: + viewFunc.isMemberExists(); + break; + case 5: + viewFunc.selling(); + break; + case 6: + viewFunc.watchLastPurchase(); + break; + case 7: + viewFunc.watchMonthlySalary(); + break; + default: + System.out.println("***exit***)"); + return; + } + } } - public void workerScreen() + public void managerScreen() { - System.out.println("Welcome to the clothing store management system"); - System.out.print(itemController.bestSellingProduct()); + Scanner s = new Scanner(System.in); + while(true) { + System.out.println("Hello Manager!!"); + System.out.println("what do you want to do?(choose number)"); + System.out.println("1. search product by Id and size"); + System.out.println("2. add club member"); + System.out.println("3. delete club member"); + System.out.println("4. check if the club member exists"); + System.out.println("5. selling"); + System.out.println("6. watch last purchase"); + System.out.println("7. watch my monthly salary"); + System.out.println("8. watch average Selling Rate"); + System.out.println("9. find the best Selling Product"); + System.out.println("10. add new shoe/pants/shirt"); + System.out.println("11. Change Hourly Salary"); + System.out.println("12. add Worker"); + System.out.println("Any other number to exit"); + int temp=s.nextInt(); + switch (temp) { + case 1: + viewFunc.searchItem(); + break; + case 2: + viewFunc.addClubMember(); + break; + case 3: + viewFunc.deleteClubMember(); + break; + case 4: + viewFunc.isMemberExists(); + break; + case 5: + viewFunc.selling(); + break; + case 6: + viewFunc.watchLastPurchase(); + break; + case 7: + viewFunc.watchMonthlySalary(); + break; + case 8: + viewFunc.averageSellingRate(); + break; + case 9: + viewFunc.bestSellingProduct(); + break; + case 10: + viewFunc.addItem(); + break; + case 11: + viewFunc.changeHourlySalary(); + break; + case 12: + viewFunc.addWorker(); + break; + default: + System.out.println("***exit***"); + return; + } + } + } } \ No newline at end of file diff --git a/src/view/ViewFunc.java b/src/view/ViewFunc.java new file mode 100644 index 0000000..5afa67b --- /dev/null +++ b/src/view/ViewFunc.java @@ -0,0 +1,299 @@ +package view; + +import model.entities.*; + +import java.util.*; +import controller.*; +import java.io.IOException; + +public class ViewFunc{ + private AutoFuncController autoFuncController; + private ItemController itemController; + private ManagerController managerController; + private MemberController memberController; + private PurchaseController purchaseController; + private StoreController storeController; + private WorkerController workerController; + private GeneralOpController generalOpController; + + public ViewFunc() { + autoFuncController = new AutoFuncController(); + itemController = new ItemController(); + managerController = new ManagerController(); + memberController = new MemberController(); + purchaseController = new PurchaseController(); + storeController = new StoreController(); + workerController = new WorkerController(); + generalOpController = new GeneralOpController(); + } + + public String login(){ + Scanner s = new Scanner(System.in); + System.out.println("enter your id: "); + int id = s.nextInt(); + System.out.println("enter your password: "); + String pass = s.next(); + if(generalOpController.isManager(id,pass)) + return "manager"; + if(generalOpController.isWorker(id,pass)) + return "worker"; + return "none"; + } + + public void searchItem() { + int id, size; + Scanner s = new Scanner(System.in); + System.out.println("enter item id: "); + id = s.nextInt(); + System.out.println("enter the size: "); + size = s.nextInt(); + Item item = itemController.searchItem(id, size); + if(itemController.isItemExists(id,size)) + System.out.println("the product does not exist"); + else if (item.getItemId()<0) + System.out.println("the product doesn't in stock!"); + else { + System.out.println("the id:"+item.getItemId()); + System.out.println("the color:"+item.getColor()); + System.out.println("the brand:"+item.getBrand()); + System.out.println("the gender:"+item.getGender()); + System.out.println("the type:"+item.getType()); + System.out.println("the price:"+item.getPrice()); + System.out.println("the size:"+item.getSize()); + System.out.println("current Stock:"+item.getCurrentStock()); + System.out.println("base Stock:"+item.getBaseStock()); + switch (item.getType()) { + case "shirt": + Shirt shirt = (Shirt)item; + System.out.println("shirt Type:"+ shirt.getShirtType()); + break; + case "pants": + Pants pants = (Pants) item; + System.out.println("pants Type:"+pants.getPantsType()); + break; + case "shoe": + Shoe shoe = (Shoe)item; + System.out.println("drawstring Color:" + shoe.getDrawstringColor()); + break; + } + } + } + + public void addClubMember(){ + Scanner s = new Scanner(System.in); + System.out.println("enter member's name: "); + String name = s.next(); + System.out.println("enter birthday: "); + String birthday = s.next(); + System.out.println("enter id: "); + int id = s.nextInt(); + int gainedPoints = 0; + Member m = new Member(name,birthday,id,gainedPoints); + memberController.addClubMember(m); + System.out.println("action succeeded!"); + } + + public void deleteClubMember(){ + Scanner s = new Scanner(System.in); + System.out.println("enter member id: "); + int id = s.nextInt(); + memberController.deleteClubMember(id); + } + + public void isMemberExists() { + Scanner s = new Scanner(System.in); + System.out.println("enter member id: "); + int id = s.nextInt(); + if(memberController.isExistsClubMember(id)) + System.out.println("the member exists"); + else System.out.println("the member doesn't exist"); + } + + public void selling(){ + ArrayList items = new ArrayList(); + int price = 0, temp; + Scanner s = new Scanner(System.in); + System.out.println("how many items?"); + int num = s.nextInt(); + for(int i=0;i Date: Fri, 12 Jun 2020 22:09:37 +0300 Subject: [PATCH 07/48] =?UTF-8?q?=D7=A9=D7=99=D7=A0=D7=95=D7=99=D7=99?= =?UTF-8?q?=D7=9D=20=D7=A7=D7=98=D7=A0=D7=99=D7=9D=20=D7=91userinterface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/UserInterface.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/view/UserInterface.java b/src/view/UserInterface.java index f5191c8..8dff904 100644 --- a/src/view/UserInterface.java +++ b/src/view/UserInterface.java @@ -17,15 +17,15 @@ public void start() { public void run() { for(int i=1;i<=3;i++) { String str = viewFunc.login(); - if (str == "manager") { + if (str.equals( "manager")) { managerScreen(); return; } - if (str == "worker") { + if (str.equals("worker")) { workerScreen(); return; } - if (str == "none") + if (str.equals( "none")) System.out.println("try again! **num "+i+" (at the third try the program will close!)"); } System.out.println("you should remember your password for the next time..."); From 74b3007cc755b856d96e4e758fdc446acfa4a184 Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 12 Jun 2020 23:07:04 +0300 Subject: [PATCH 08/48] =?UTF-8?q?=D7=94=D7=95=D7=A1=D7=A4=D7=AA=20=D7=A4?= =?UTF-8?q?=D7=95=D7=A0=D7=A7=D7=A6=D7=99=D7=95=D7=AA=20=D7=90=D7=95=D7=98?= =?UTF-8?q?=D7=95'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/AutoFuncController.java | 4 +-- src/model/AutoFuncModel.java | 40 ++++++++++++-------------- src/model/ItemModel.java | 6 ++-- src/model/ManagerModel.java | 2 +- src/model/MemberModel.java | 6 ++-- src/model/PurchaseModel.java | 4 +-- src/model/StoreModel.java | 8 +++--- src/model/WorkerModel.java | 2 +- src/view/UserInterface.java | 4 ++- src/view/ViewFunc.java | 8 ++++++ 10 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/controller/AutoFuncController.java b/src/controller/AutoFuncController.java index c43b21c..731ab49 100644 --- a/src/controller/AutoFuncController.java +++ b/src/controller/AutoFuncController.java @@ -11,9 +11,9 @@ public AutoFuncController() { this.model = new AutoFuncModel(); } - public void checkCurrentStockThread() + public void checkCurrentStockTimerRunning() { - model.checkCurrentStockThread(); + model.runCheckCurrentStock(); } } diff --git a/src/model/AutoFuncModel.java b/src/model/AutoFuncModel.java index 10ad0ff..6477600 100644 --- a/src/model/AutoFuncModel.java +++ b/src/model/AutoFuncModel.java @@ -3,8 +3,14 @@ import model.entities.Item; import java.util.ArrayList; +import java.util.Date; +import java.util.Timer; +import java.util.TimerTask; + +import static java.lang.Thread.sleep; + +public class AutoFuncModel { -public class AutoFuncModel implements Runnable { public void checkCurrentStock() { int i; @@ -23,27 +29,17 @@ public void checkCurrentStock() { } } - @Override - public void run() { - checkCurrentStock(); - } - - - public void checkCurrentStockThread() { - int i; - try { - Runnable runnable = new AutoFuncModel(); - Thread t1 = new Thread(runnable); - for (i = 144; i > 0; i--) { // 10 minutes loop, All day long - t1.run(); - Thread.sleep(6000000); // 10 Minutes - } - - } catch (InterruptedException e) { - System.out.println("Thread interrupted."); - } - - } + public void runCheckCurrentStock() + { + TimerTask task = new TimerTask() { + @Override + public void run() { + checkCurrentStock(); + } + }; + Timer timer = new Timer(); + timer.schedule(task, new Date(), 300000); + } } diff --git a/src/model/ItemModel.java b/src/model/ItemModel.java index 4c72ae3..c107d8f 100644 --- a/src/model/ItemModel.java +++ b/src/model/ItemModel.java @@ -83,7 +83,7 @@ public void addPants(Pants pants) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?);"; @@ -124,7 +124,7 @@ public void addShoe(Shoe shoe) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; @@ -166,7 +166,7 @@ public void addShirt(Shirt shirt) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; diff --git a/src/model/ManagerModel.java b/src/model/ManagerModel.java index f7952ef..359f9ba 100644 --- a/src/model/ManagerModel.java +++ b/src/model/ManagerModel.java @@ -13,7 +13,7 @@ public String changeHourlySalary(int workerId, int newSalary) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); Statement stmt = connection.createStatement(); String strUpdate = "update workers set hourlysalary = " + newSalary + " where id =" + workerId; diff --git a/src/model/MemberModel.java b/src/model/MemberModel.java index ddbb8a9..f0c2c5b 100644 --- a/src/model/MemberModel.java +++ b/src/model/MemberModel.java @@ -17,7 +17,7 @@ public void addClubMember(Member m) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); String INSERT_USERS_SQL = "INSERT INTO clubmembers" + " (name, id, dateofbirth, pointgained) VALUES " + " (?, ?, ?, ?);"; @@ -56,7 +56,7 @@ public void deleteClubMember(int id) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); Statement statement = connection.createStatement(); statement.executeUpdate(DELETE_USERS_SQL); System.out.println("Deletion was successfully"); @@ -136,7 +136,7 @@ public void updateMembersPoints(int price, Member m) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); Statement stmt = connection.createStatement(); String strUpdate = "update clubmembers set pointgained = pointgained +" + price + " where id =" + m.getId(); diff --git a/src/model/PurchaseModel.java b/src/model/PurchaseModel.java index 3d92638..7409d3e 100644 --- a/src/model/PurchaseModel.java +++ b/src/model/PurchaseModel.java @@ -43,7 +43,7 @@ public String selling(Purchase pur) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); Statement stmt = connection.createStatement(); for(i=0;i getAllPurchase() { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -148,7 +148,7 @@ public static ArrayList getClubMembers() { ClubMembers = new ArrayList(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -190,7 +190,7 @@ public static ArrayList getItems() { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -250,7 +250,7 @@ public static ArrayList getWorkers() { Workers = new ArrayList<>(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); diff --git a/src/model/WorkerModel.java b/src/model/WorkerModel.java index d6de904..fc1f357 100644 --- a/src/model/WorkerModel.java +++ b/src/model/WorkerModel.java @@ -15,7 +15,7 @@ public void addWorker(Worker w) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); String INSERT_USERS_SQL = "INSERT INTO workers" + " (name, id, dateofbirth, hourlysalary, numHourMonth, jobType, password) VALUES " + " (?, ?, ?, ?, ?, ?, ?);"; diff --git a/src/view/UserInterface.java b/src/view/UserInterface.java index 8dff904..1795b16 100644 --- a/src/view/UserInterface.java +++ b/src/view/UserInterface.java @@ -15,6 +15,8 @@ public void start() { @Override public void run() { + viewFunc.birthDayAuto(); + viewFunc.autoFunc(); for(int i=1;i<=3;i++) { String str = viewFunc.login(); if (str.equals( "manager")) { @@ -25,7 +27,7 @@ public void run() { workerScreen(); return; } - if (str.equals( "none")) + if (str.equals("none")) System.out.println("try again! **num "+i+" (at the third try the program will close!)"); } System.out.println("you should remember your password for the next time..."); diff --git a/src/view/ViewFunc.java b/src/view/ViewFunc.java index 5afa67b..008ce48 100644 --- a/src/view/ViewFunc.java +++ b/src/view/ViewFunc.java @@ -296,4 +296,12 @@ public void addWorker(){ System.out.println("action succeeded!"); } + public void birthDayAuto() + { + memberController.birthdayPointAuto(); + } + public void autoFunc() + { + autoFuncController.checkCurrentStockTimerRunning(); + } } From 583c9d1436e35a248336c657d75b93fade6b9a48 Mon Sep 17 00:00:00 2001 From: Rafi Date: Sat, 13 Jun 2020 11:48:38 +0300 Subject: [PATCH 09/48] =?UTF-8?q?=D7=98=D7=A1=D7=98=D7=99=D7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../META-INF/ProjectClothingStore.kotlin_module | Bin .../META-INF/ProjectClothingStore.kotlin_module | Bin src/controller/AutoFuncController.java | 2 +- .../META-INF/ProjectClothingStore.kotlin_module | Bin 16 -> 0 bytes src/view/ViewFunc.java | 2 +- .../checkCurrentStockTest.java | 4 ++++ tests/generalOpControllerTests/LoginTest.java | 12 ++++++++++++ tests/itemControllerTests/addPantsTest.java | 4 ++++ tests/itemControllerTests/addShirtTest.java | 4 ++++ tests/itemControllerTests/addShoeTest.java | 4 ++++ .../bestSellingProductTest.java | 4 ++++ tests/itemControllerTests/searchItemTest.java | 4 ++++ tests/memberControllerTests/addClubMemberTest.java | 4 ++++ .../birthdayPointAutoTest.java | 4 ++++ .../purchaseControllerTests/lastPurchaseTest.java | 4 ++++ tests/purchaseControllerTests/sellingTest.java | 4 ++++ 16 files changed, 54 insertions(+), 2 deletions(-) rename production/{production/ProjectClothingStore => ProjectClothingStore/META-INF}/META-INF/ProjectClothingStore.kotlin_module (100%) rename production/{production/ProjectClothingStore/production => test}/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module (100%) delete mode 100644 src/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module create mode 100644 tests/autoFuncControllerTests/checkCurrentStockTest.java create mode 100644 tests/generalOpControllerTests/LoginTest.java create mode 100644 tests/itemControllerTests/addPantsTest.java create mode 100644 tests/itemControllerTests/addShirtTest.java create mode 100644 tests/itemControllerTests/addShoeTest.java create mode 100644 tests/itemControllerTests/bestSellingProductTest.java create mode 100644 tests/itemControllerTests/searchItemTest.java create mode 100644 tests/memberControllerTests/addClubMemberTest.java create mode 100644 tests/memberControllerTests/birthdayPointAutoTest.java create mode 100644 tests/purchaseControllerTests/lastPurchaseTest.java create mode 100644 tests/purchaseControllerTests/sellingTest.java diff --git a/production/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module b/production/ProjectClothingStore/META-INF/META-INF/ProjectClothingStore.kotlin_module similarity index 100% rename from production/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module rename to production/ProjectClothingStore/META-INF/META-INF/ProjectClothingStore.kotlin_module diff --git a/production/production/ProjectClothingStore/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module b/production/test/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module similarity index 100% rename from production/production/ProjectClothingStore/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module rename to production/test/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module diff --git a/src/controller/AutoFuncController.java b/src/controller/AutoFuncController.java index 731ab49..e947cfd 100644 --- a/src/controller/AutoFuncController.java +++ b/src/controller/AutoFuncController.java @@ -11,7 +11,7 @@ public AutoFuncController() { this.model = new AutoFuncModel(); } - public void checkCurrentStockTimerRunning() + public void checkCurrentStock() { model.runCheckCurrentStock(); } diff --git a/src/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module b/src/production/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module deleted file mode 100644 index a49347afef10a9b5f95305e1058ba36adec7d6dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16 RcmZQzU|?ooU|@t|0RRA102TlM diff --git a/src/view/ViewFunc.java b/src/view/ViewFunc.java index 008ce48..51798b7 100644 --- a/src/view/ViewFunc.java +++ b/src/view/ViewFunc.java @@ -302,6 +302,6 @@ public void birthDayAuto() } public void autoFunc() { - autoFuncController.checkCurrentStockTimerRunning(); + autoFuncController.checkCurrentStock(); } } diff --git a/tests/autoFuncControllerTests/checkCurrentStockTest.java b/tests/autoFuncControllerTests/checkCurrentStockTest.java new file mode 100644 index 0000000..22122d8 --- /dev/null +++ b/tests/autoFuncControllerTests/checkCurrentStockTest.java @@ -0,0 +1,4 @@ +package autoFuncControllerTests; + +public class checkCurrentStockTest { +} diff --git a/tests/generalOpControllerTests/LoginTest.java b/tests/generalOpControllerTests/LoginTest.java new file mode 100644 index 0000000..0e8b052 --- /dev/null +++ b/tests/generalOpControllerTests/LoginTest.java @@ -0,0 +1,12 @@ +package generalOpControllerTests; + +import org.junit.jupiter.api.Test; + +public class LoginTest { + + @Test + public void test() + { + + } +} diff --git a/tests/itemControllerTests/addPantsTest.java b/tests/itemControllerTests/addPantsTest.java new file mode 100644 index 0000000..b62c99f --- /dev/null +++ b/tests/itemControllerTests/addPantsTest.java @@ -0,0 +1,4 @@ +package itemControllerTests; + +public class addPantsTest { +} diff --git a/tests/itemControllerTests/addShirtTest.java b/tests/itemControllerTests/addShirtTest.java new file mode 100644 index 0000000..1fe7e98 --- /dev/null +++ b/tests/itemControllerTests/addShirtTest.java @@ -0,0 +1,4 @@ +package itemControllerTests; + +public class addShirtTest { +} diff --git a/tests/itemControllerTests/addShoeTest.java b/tests/itemControllerTests/addShoeTest.java new file mode 100644 index 0000000..f7a80e8 --- /dev/null +++ b/tests/itemControllerTests/addShoeTest.java @@ -0,0 +1,4 @@ +package itemControllerTests; + +public class addShoeTest { +} diff --git a/tests/itemControllerTests/bestSellingProductTest.java b/tests/itemControllerTests/bestSellingProductTest.java new file mode 100644 index 0000000..4e337b2 --- /dev/null +++ b/tests/itemControllerTests/bestSellingProductTest.java @@ -0,0 +1,4 @@ +package itemControllerTests; + +public class bestSellingProductTest { +} diff --git a/tests/itemControllerTests/searchItemTest.java b/tests/itemControllerTests/searchItemTest.java new file mode 100644 index 0000000..6830d56 --- /dev/null +++ b/tests/itemControllerTests/searchItemTest.java @@ -0,0 +1,4 @@ +package itemControllerTests; + +public class searchItemTest { +} diff --git a/tests/memberControllerTests/addClubMemberTest.java b/tests/memberControllerTests/addClubMemberTest.java new file mode 100644 index 0000000..6d2d986 --- /dev/null +++ b/tests/memberControllerTests/addClubMemberTest.java @@ -0,0 +1,4 @@ +package memberControllerTests; + +public class addClubMemberTest { +} diff --git a/tests/memberControllerTests/birthdayPointAutoTest.java b/tests/memberControllerTests/birthdayPointAutoTest.java new file mode 100644 index 0000000..d364fe1 --- /dev/null +++ b/tests/memberControllerTests/birthdayPointAutoTest.java @@ -0,0 +1,4 @@ +package memberControllerTests; + +public class birthdayPointAutoTest { +} diff --git a/tests/purchaseControllerTests/lastPurchaseTest.java b/tests/purchaseControllerTests/lastPurchaseTest.java new file mode 100644 index 0000000..979c5b7 --- /dev/null +++ b/tests/purchaseControllerTests/lastPurchaseTest.java @@ -0,0 +1,4 @@ +package purchaseControllerTests; + +public class lastPurchaseTest { +} diff --git a/tests/purchaseControllerTests/sellingTest.java b/tests/purchaseControllerTests/sellingTest.java new file mode 100644 index 0000000..392442d --- /dev/null +++ b/tests/purchaseControllerTests/sellingTest.java @@ -0,0 +1,4 @@ +package purchaseControllerTests; + +public class sellingTest { +} From e37ff491e4229f1fbf456d813753848c3e022a99 Mon Sep 17 00:00:00 2001 From: Rafi Date: Sat, 13 Jun 2020 14:21:07 +0300 Subject: [PATCH 10/48] =?UTF-8?q?=D7=98=D7=A1=D7=98=D7=99=D7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/GeneralOpModel.java | 12 ++++ src/model/ItemModel.java | 100 +++++++++++++++++++++------------- src/model/MemberModel.java | 8 ++- src/model/PurchaseModel.java | 3 +- src/model/WorkerModel.java | 10 +++- src/view/ViewFunc.java | 11 +++- 6 files changed, 98 insertions(+), 46 deletions(-) diff --git a/src/model/GeneralOpModel.java b/src/model/GeneralOpModel.java index 49aef77..b26ef2e 100644 --- a/src/model/GeneralOpModel.java +++ b/src/model/GeneralOpModel.java @@ -45,6 +45,12 @@ public String Login(int id, String password) { public String isManager(int id, String password) { String i; + String idString =String.valueOf(id); + if(idString == null || idString.trim().equals("") || password == null || password.trim().equals("")) + { + throw new IllegalArgumentException("id or password must not be null"); + } + try { i = Login(id, password); if(i.equals("manager")) @@ -59,6 +65,12 @@ public String isManager(int id, String password) { } public String isWorker(int id, String password) { + String idString =String.valueOf(id); + if(idString == null || idString.trim().equals("") || password == null || password.trim().equals("")) + { + throw new IllegalArgumentException("id or password must not be null"); + } + try { String i = Login(id, password); if(i.equals("worker")) diff --git a/src/model/ItemModel.java b/src/model/ItemModel.java index c107d8f..8f78512 100644 --- a/src/model/ItemModel.java +++ b/src/model/ItemModel.java @@ -78,49 +78,57 @@ public boolean isAllItemsExist(Purchase pur) { } public void addPants(Pants pants) { + if (!isItemExists(pants.getItemId(), pants.getSize())) { - - Connection connection = null; - try { - Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); - String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + - " (?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?);"; - - PreparedStatement preparedStatement = connection.prepareStatement(INSERT_USERS_SQL); - connection.setAutoCommit(false); - preparedStatement.setInt(1, pants.getItemId()); - preparedStatement.setString(2, pants.getColor()); - preparedStatement.setInt(3, pants.getPrice()); - preparedStatement.setString(4, pants.getType()); - preparedStatement.setInt(5, pants.getSize()); - preparedStatement.setString(6, pants.getBrand()); - preparedStatement.setString(7, pants.getGender()); - preparedStatement.setString(8, "null"); - preparedStatement.setString(9, pants.getPantsType()); - preparedStatement.setString(10, "null"); - preparedStatement.setInt(11, pants.getBaseStock()); - preparedStatement.setInt(12, pants.getCurrentStock()); - preparedStatement.addBatch(); - int[] updateCounts = preparedStatement.executeBatch(); - connection.commit(); - connection.setAutoCommit(true); - - - } catch (IllegalAccessException | InstantiationException | SQLException | ClassNotFoundException e) { - e.printStackTrace(); - } finally { + Connection connection = null; try { - connection.close(); - } catch (SQLException e) { + Class.forName("com.mysql.jdbc.Driver").newInstance(); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + + " (?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?);"; + + PreparedStatement preparedStatement = connection.prepareStatement(INSERT_USERS_SQL); + connection.setAutoCommit(false); + preparedStatement.setInt(1, pants.getItemId()); + preparedStatement.setString(2, pants.getColor()); + preparedStatement.setInt(3, pants.getPrice()); + preparedStatement.setString(4, pants.getType()); + preparedStatement.setInt(5, pants.getSize()); + preparedStatement.setString(6, pants.getBrand()); + preparedStatement.setString(7, pants.getGender()); + preparedStatement.setString(8, "null"); + preparedStatement.setString(9, pants.getPantsType()); + preparedStatement.setString(10, "null"); + preparedStatement.setInt(11, pants.getBaseStock()); + preparedStatement.setInt(12, pants.getCurrentStock()); + preparedStatement.addBatch(); + int[] updateCounts = preparedStatement.executeBatch(); + connection.commit(); + connection.setAutoCommit(true); + + + } catch (IllegalAccessException | InstantiationException | SQLException | ClassNotFoundException e) { e.printStackTrace(); + } finally { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } } + System.out.println("action succeeded!"); } + else { + System.out.println("the item is already exists!"); + + } + } + - } public void addShoe(Shoe shoe) { + if (!isItemExists(shoe.getItemId(), shoe.getSize())) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); @@ -137,7 +145,7 @@ public void addShoe(Shoe shoe) { preparedStatement.setInt(5, shoe.getSize()); preparedStatement.setString(6, shoe.getBrand()); preparedStatement.setString(7, shoe.getGender()); - preparedStatement.setString(8,shoe.getDrawstringColor()); + preparedStatement.setString(8, shoe.getDrawstringColor()); preparedStatement.setString(9, "null"); preparedStatement.setString(10, "null"); preparedStatement.setInt(11, shoe.getBaseStock()); @@ -156,13 +164,20 @@ public void addShoe(Shoe shoe) { } catch (SQLException e) { e.printStackTrace(); } - } + System.out.println("action succeeded!"); } + else { + System.out.println("the item is already exists!"); + + } + } - public void addShirt(Shirt shirt) { + + public void addShirt(Shirt shirt) { + if (!isItemExists(shirt.getItemId(), shirt.getSize())) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); @@ -181,7 +196,7 @@ public void addShirt(Shirt shirt) { preparedStatement.setString(7, shirt.getGender()); preparedStatement.setString(8, "null"); preparedStatement.setString(9, "null"); - preparedStatement.setString(10,shirt.getShirtType()); + preparedStatement.setString(10, shirt.getShirtType()); preparedStatement.setInt(11, shirt.getBaseStock()); preparedStatement.setInt(12, shirt.getCurrentStock()); @@ -199,7 +214,14 @@ public void addShirt(Shirt shirt) { } catch (SQLException e) { e.printStackTrace(); } + } + System.out.println("action succeeded!"); + } + else { + System.out.println("the item is already exists!"); + + } } @@ -207,4 +229,4 @@ public void addShirt(Shirt shirt) { } -} + diff --git a/src/model/MemberModel.java b/src/model/MemberModel.java index f0c2c5b..83a7f98 100644 --- a/src/model/MemberModel.java +++ b/src/model/MemberModel.java @@ -43,7 +43,11 @@ public void addClubMember(Member m) { } } - + System.out.println("action succeeded!"); + } + else + { + System.out.println("the member is already exists!"); } } @@ -65,6 +69,8 @@ public void deleteClubMember(int id) { e.printStackTrace(); } + System.out.println("action succeed!"); + } else { System.out.println("Unable to delete, no such user in the system"); } diff --git a/src/model/PurchaseModel.java b/src/model/PurchaseModel.java index 7409d3e..298d97b 100644 --- a/src/model/PurchaseModel.java +++ b/src/model/PurchaseModel.java @@ -23,8 +23,7 @@ public Purchase lastPurchase(int memId) { } catch (Exception e) { e.printStackTrace(); } - Purchase p = new Purchase(); - return p; + return null; } public String selling(Purchase pur) { diff --git a/src/model/WorkerModel.java b/src/model/WorkerModel.java index fc1f357..a5d6e39 100644 --- a/src/model/WorkerModel.java +++ b/src/model/WorkerModel.java @@ -43,8 +43,16 @@ public void addWorker(Worker w) { } + System.out.println("action succeeded!"); + } - } + else { + System.out.println("the item is already exists!"); + + } + + } + public String watchMonthlySalary(int workerId) { diff --git a/src/view/ViewFunc.java b/src/view/ViewFunc.java index 51798b7..4ae53e3 100644 --- a/src/view/ViewFunc.java +++ b/src/view/ViewFunc.java @@ -48,7 +48,7 @@ public void searchItem() { System.out.println("enter the size: "); size = s.nextInt(); Item item = itemController.searchItem(id, size); - if(itemController.isItemExists(id,size)) + if(!itemController.isItemExists(id,size)) System.out.println("the product does not exist"); else if (item.getItemId()<0) System.out.println("the product doesn't in stock!"); @@ -90,7 +90,7 @@ public void addClubMember(){ int gainedPoints = 0; Member m = new Member(name,birthday,id,gainedPoints); memberController.addClubMember(m); - System.out.println("action succeeded!"); + } public void deleteClubMember(){ @@ -152,6 +152,11 @@ public void watchLastPurchase() { System.out.println("enter member id: "); int id = s.nextInt(); Purchase p = purchaseController.lastPurchase(id); + if(p == null) + { + System.out.println("the member is not exist or he didn't bought something in the store!"); + return; + } for (int i = 0; i < p.getItem().size(); i++) { temp = i + 1; System.out.println("item number: " + temp); @@ -293,7 +298,7 @@ public void addWorker(){ Worker w = new Worker(name, birthday, id, hourlySalary,numHourMonth,jobType,pass ); managerController.addWorker(w); - System.out.println("action succeeded!"); + } public void birthDayAuto() From 040817ab93e326e30ad212bbf0820c58b0842ac7 Mon Sep 17 00:00:00 2001 From: Rafi Date: Sat, 13 Jun 2020 15:58:06 +0300 Subject: [PATCH 11/48] =?UTF-8?q?=D7=98=D7=A1=D7=98=D7=99=D7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/GeneralOpModel.java | 8 +-- src/model/MemberModel.java | 2 +- tests/generalOpControllerTests/LoginTest.java | 66 ++++++++++++++++++- 3 files changed, 70 insertions(+), 6 deletions(-) diff --git a/src/model/GeneralOpModel.java b/src/model/GeneralOpModel.java index b26ef2e..2cab096 100644 --- a/src/model/GeneralOpModel.java +++ b/src/model/GeneralOpModel.java @@ -45,8 +45,8 @@ public String Login(int id, String password) { public String isManager(int id, String password) { String i; - String idString =String.valueOf(id); - if(idString == null || idString.trim().equals("") || password == null || password.trim().equals("")) + + if(id < 0 || password == null || password.trim().equals("")) { throw new IllegalArgumentException("id or password must not be null"); } @@ -65,8 +65,8 @@ public String isManager(int id, String password) { } public String isWorker(int id, String password) { - String idString =String.valueOf(id); - if(idString == null || idString.trim().equals("") || password == null || password.trim().equals("")) + + if( id < 0 || password == null || password.trim().equals("")) { throw new IllegalArgumentException("id or password must not be null"); } diff --git a/src/model/MemberModel.java b/src/model/MemberModel.java index 83a7f98..53b94c1 100644 --- a/src/model/MemberModel.java +++ b/src/model/MemberModel.java @@ -126,7 +126,7 @@ public void birthdayPointAuto() { int monthMember = Integer.parseInt(dateClubMember[1]); if (Integer.valueOf(month) == Integer.valueOf(monthMember) && Integer.valueOf(day) == Integer.valueOf(dayMember)) { updateMembersPoints(250, clubMembers.get(i)); - System.out.println("System message: 250 credits added to club member" + clubMembers.get(i).getName() + ", id: " + clubMembers.get(i).getId()); + System.out.println("System message: 250 credits added to club member " + clubMembers.get(i).getName() + ", id: " + clubMembers.get(i).getId()); } } diff --git a/tests/generalOpControllerTests/LoginTest.java b/tests/generalOpControllerTests/LoginTest.java index 0e8b052..da809af 100644 --- a/tests/generalOpControllerTests/LoginTest.java +++ b/tests/generalOpControllerTests/LoginTest.java @@ -1,12 +1,76 @@ package generalOpControllerTests; +import controller.GeneralOpController; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.fail; + public class LoginTest { @Test - public void test() + public void failLoginEmptyIdTestManager() + { + GeneralOpController generalOpController = new GeneralOpController(); + try { + generalOpController.isManager(-1, "1234"); + fail("Login succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("id or password must not be null", e.getMessage()); + + } + } + + @Test + public void failLoginEmptyPasswordTestManager() + { + GeneralOpController generalOpController = new GeneralOpController(); + try { + generalOpController.isManager(12, ""); + fail("Login succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("id or password must not be null", e.getMessage()); + + } + } + + + @Test + public void failLoginEmptyIdTestWorker() + { + GeneralOpController generalOpController = new GeneralOpController(); + try { + generalOpController.isWorker(-1, "1234"); + fail("Login succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("id or password must not be null", e.getMessage()); + + } + } + + + @Test + public void failLoginEmptyPasswordTestWorker() { + GeneralOpController generalOpController = new GeneralOpController(); + try { + generalOpController.isManager(1, ""); + fail("Login succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("id or password must not be null", e.getMessage()); + } } + + } From 83a457c39ff855de794122165e63cfb9363a5e55 Mon Sep 17 00:00:00 2001 From: Rafi Date: Sat, 13 Jun 2020 20:40:00 +0300 Subject: [PATCH 12/48] =?UTF-8?q?=D7=98=D7=A1=D7=98=D7=99=D7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/GeneralOpController.java | 3 +- src/model/GeneralOpModel.java | 8 +- src/model/MemberModel.java | 4 + src/model/PurchaseModel.java | 21 +++ src/model/entities/Member.java | 2 +- .../checkCurrentStockTest.java | 4 - tests/generalOpControllerTests/LoginTest.java | 94 +++++++++++--- .../{addPantsTest.java => AddPantsTest.java} | 2 +- .../{addShirtTest.java => AddShirtTest.java} | 2 +- .../{addShoeTest.java => AddShoeTest.java} | 2 +- .../BestSellingProductTest.java | 4 + ...earchItemTest.java => SearchItemTest.java} | 2 +- .../bestSellingProductTest.java | 4 - .../AddClubMemberTest.java | 122 ++++++++++++++++++ .../addClubMemberTest.java | 4 - .../birthdayPointAutoTest.java | 4 - .../LastPurchaseTest.java | 74 +++++++++++ .../purchaseControllerTests/SellingTest.java | 112 ++++++++++++++++ .../lastPurchaseTest.java | 4 - .../purchaseControllerTests/sellingTest.java | 4 - 20 files changed, 426 insertions(+), 50 deletions(-) delete mode 100644 tests/autoFuncControllerTests/checkCurrentStockTest.java rename tests/itemControllerTests/{addPantsTest.java => AddPantsTest.java} (53%) rename tests/itemControllerTests/{addShirtTest.java => AddShirtTest.java} (53%) rename tests/itemControllerTests/{addShoeTest.java => AddShoeTest.java} (54%) create mode 100644 tests/itemControllerTests/BestSellingProductTest.java rename tests/itemControllerTests/{searchItemTest.java => SearchItemTest.java} (51%) delete mode 100644 tests/itemControllerTests/bestSellingProductTest.java create mode 100644 tests/memberControllerTests/AddClubMemberTest.java delete mode 100644 tests/memberControllerTests/addClubMemberTest.java delete mode 100644 tests/memberControllerTests/birthdayPointAutoTest.java create mode 100644 tests/purchaseControllerTests/LastPurchaseTest.java create mode 100644 tests/purchaseControllerTests/SellingTest.java delete mode 100644 tests/purchaseControllerTests/lastPurchaseTest.java delete mode 100644 tests/purchaseControllerTests/sellingTest.java diff --git a/src/controller/GeneralOpController.java b/src/controller/GeneralOpController.java index 864eaba..fafc9ae 100644 --- a/src/controller/GeneralOpController.java +++ b/src/controller/GeneralOpController.java @@ -21,7 +21,7 @@ public String Login(int id, String password) } public boolean isManager(int id, String password) { - String idString =String.valueOf(id); + String session = model.isManager(id, password); if (session != null) { return true; @@ -30,7 +30,6 @@ public boolean isManager(int id, String password) { } public boolean isWorker(int id, String password){ - String idString =String.valueOf(id); String session = model.isWorker(id, password); if (session != null) { return true; diff --git a/src/model/GeneralOpModel.java b/src/model/GeneralOpModel.java index 2cab096..e72f453 100644 --- a/src/model/GeneralOpModel.java +++ b/src/model/GeneralOpModel.java @@ -46,9 +46,9 @@ public String Login(int id, String password) { public String isManager(int id, String password) { String i; - if(id < 0 || password == null || password.trim().equals("")) + if(id <= 0 || password == null || password.trim().equals("")) { - throw new IllegalArgumentException("id or password must not be null"); + throw new IllegalArgumentException("id or password must not be null or wrong"); } try { @@ -66,9 +66,9 @@ public String isManager(int id, String password) { public String isWorker(int id, String password) { - if( id < 0 || password == null || password.trim().equals("")) + if( id <= 0 || password == null || password.trim().equals("")) { - throw new IllegalArgumentException("id or password must not be null"); + throw new IllegalArgumentException("id or password must not be null or wrong"); } try { diff --git a/src/model/MemberModel.java b/src/model/MemberModel.java index 53b94c1..8f0fd41 100644 --- a/src/model/MemberModel.java +++ b/src/model/MemberModel.java @@ -12,6 +12,10 @@ public class MemberModel { public MemberModel() { } public void addClubMember(Member m) { + if(m.getName().trim().equals("") || (m.getId() <= 0) || m.getPointsGained() < 0 || m.getDateOfBirth().trim().equals("")) + { + throw new IllegalArgumentException("name or id or pointsgaind or dateofbirth must not be null or wrong"); + } if (isExistsClubMember(m.getId()) == false) { Connection connection = null; diff --git a/src/model/PurchaseModel.java b/src/model/PurchaseModel.java index 298d97b..d5e8e53 100644 --- a/src/model/PurchaseModel.java +++ b/src/model/PurchaseModel.java @@ -11,6 +11,14 @@ public class PurchaseModel { public Purchase lastPurchase(int memId) { + if(memId < 0) + { + throw new IllegalArgumentException("id must not be negative"); + } + if(memId == 0) + { + throw new IllegalArgumentException("id must not be zero"); + } int i; ArrayList pur = new ArrayList<>(); try { @@ -27,6 +35,19 @@ public Purchase lastPurchase(int memId) { } public String selling(Purchase pur) { + if(pur.getClubMember().getName().equals("valueless") || pur.getClubMember().getDateOfBirth().equals("-1") || pur.getClubMember().getId() < 0 || pur.getClubMember().getPointsGained() < 0) + { + throw new IllegalArgumentException("name or id or pointsgaind or dateofbirth must not be null or wrong"); + } + if(pur.getItem().isEmpty()) + { + throw new IllegalArgumentException("The Array list Items must not be null or empty"); + } + if(pur.getPrice() < 0 || pur.getShoppingRating() < 0) + { + throw new IllegalArgumentException("the price or shoppingRating must not be negative"); + } + MemberModel memMod = new MemberModel(); ItemModel itemModel = new ItemModel(); diff --git a/src/model/entities/Member.java b/src/model/entities/Member.java index 9fe6913..0c96cdc 100644 --- a/src/model/entities/Member.java +++ b/src/model/entities/Member.java @@ -12,7 +12,7 @@ public void setPointsGained(int pointsGained) { public Member() { super(); - this.pointsGained = -1; + this.pointsGained = 0; } public Member(String name, String dateOfBirth, int id, int pointsGained) { diff --git a/tests/autoFuncControllerTests/checkCurrentStockTest.java b/tests/autoFuncControllerTests/checkCurrentStockTest.java deleted file mode 100644 index 22122d8..0000000 --- a/tests/autoFuncControllerTests/checkCurrentStockTest.java +++ /dev/null @@ -1,4 +0,0 @@ -package autoFuncControllerTests; - -public class checkCurrentStockTest { -} diff --git a/tests/generalOpControllerTests/LoginTest.java b/tests/generalOpControllerTests/LoginTest.java index da809af..32a42a0 100644 --- a/tests/generalOpControllerTests/LoginTest.java +++ b/tests/generalOpControllerTests/LoginTest.java @@ -6,21 +6,47 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.fail; + +import static org.junit.jupiter.api.Assertions.*; public class LoginTest { + GeneralOpController generalOpController; + private final static int MOCK_NEGATIVE = -1; + private final static int MOCK_ZERO = 0; + private final static int MOCK_POSITIVE = 1; + + @BeforeEach + public void setUp() + { + generalOpController = new GeneralOpController(); + } + + + @Test + public void failLoginNegativeIdTestManager() + { + try { + generalOpController.isManager(MOCK_NEGATIVE, "1234"); + fail("Login succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("id or password must not be null or wrong", e.getMessage()); + + } + + } @Test - public void failLoginEmptyIdTestManager() + public void failLoginZeroIdTestManager() { - GeneralOpController generalOpController = new GeneralOpController(); try { - generalOpController.isManager(-1, "1234"); + generalOpController.isManager(MOCK_ZERO, "1234"); fail("Login succeed when should failed"); } catch (IllegalArgumentException e) { - Assertions.assertEquals("id or password must not be null", e.getMessage()); + Assertions.assertEquals("id or password must not be null or wrong", e.getMessage()); } } @@ -28,30 +54,42 @@ public void failLoginEmptyIdTestManager() @Test public void failLoginEmptyPasswordTestManager() { - GeneralOpController generalOpController = new GeneralOpController(); try { - generalOpController.isManager(12, ""); + generalOpController.isManager(MOCK_POSITIVE, ""); fail("Login succeed when should failed"); } catch (IllegalArgumentException e) { - Assertions.assertEquals("id or password must not be null", e.getMessage()); + Assertions.assertEquals("id or password must not be null or wrong", e.getMessage()); } } @Test - public void failLoginEmptyIdTestWorker() + public void loginSucceedTestManager() + { + boolean checkTrue = generalOpController.isManager(12, "1234"); + assertTrue(checkTrue); + boolean checkFalse = generalOpController.isManager(1, "1111"); + assertFalse(checkFalse); + + } + + ///////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////// + + + @Test + public void failLoginNegativeIdTestWorker() { - GeneralOpController generalOpController = new GeneralOpController(); try { - generalOpController.isWorker(-1, "1234"); + generalOpController.isWorker(MOCK_NEGATIVE, "1234"); fail("Login succeed when should failed"); } catch (IllegalArgumentException e) { - Assertions.assertEquals("id or password must not be null", e.getMessage()); + Assertions.assertEquals("id or password must not be null or wrong", e.getMessage()); } } @@ -60,17 +98,43 @@ public void failLoginEmptyIdTestWorker() @Test public void failLoginEmptyPasswordTestWorker() { - GeneralOpController generalOpController = new GeneralOpController(); try { - generalOpController.isManager(1, ""); + generalOpController.isWorker(MOCK_POSITIVE, ""); fail("Login succeed when should failed"); } catch (IllegalArgumentException e) { - Assertions.assertEquals("id or password must not be null", e.getMessage()); + Assertions.assertEquals("id or password must not be null or wrong", e.getMessage()); } } + @Test + public void failLoginZeroIdTestWorker() + { + try { + generalOpController.isWorker(MOCK_ZERO, "1234"); + fail("Login succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("id or password must not be null or wrong", e.getMessage()); + + } + } + + @Test + public void loginSucceedTestWorker() + { + boolean checkTrue = generalOpController.isWorker(10, "0404"); + assertTrue(checkTrue); + boolean checkFalse = generalOpController.isWorker(1, "1111"); + assertFalse(checkFalse); + } + + + + + } diff --git a/tests/itemControllerTests/addPantsTest.java b/tests/itemControllerTests/AddPantsTest.java similarity index 53% rename from tests/itemControllerTests/addPantsTest.java rename to tests/itemControllerTests/AddPantsTest.java index b62c99f..ff473e3 100644 --- a/tests/itemControllerTests/addPantsTest.java +++ b/tests/itemControllerTests/AddPantsTest.java @@ -1,4 +1,4 @@ package itemControllerTests; -public class addPantsTest { +public class AddPantsTest { } diff --git a/tests/itemControllerTests/addShirtTest.java b/tests/itemControllerTests/AddShirtTest.java similarity index 53% rename from tests/itemControllerTests/addShirtTest.java rename to tests/itemControllerTests/AddShirtTest.java index 1fe7e98..f582b23 100644 --- a/tests/itemControllerTests/addShirtTest.java +++ b/tests/itemControllerTests/AddShirtTest.java @@ -1,4 +1,4 @@ package itemControllerTests; -public class addShirtTest { +public class AddShirtTest { } diff --git a/tests/itemControllerTests/addShoeTest.java b/tests/itemControllerTests/AddShoeTest.java similarity index 54% rename from tests/itemControllerTests/addShoeTest.java rename to tests/itemControllerTests/AddShoeTest.java index f7a80e8..a57bb29 100644 --- a/tests/itemControllerTests/addShoeTest.java +++ b/tests/itemControllerTests/AddShoeTest.java @@ -1,4 +1,4 @@ package itemControllerTests; -public class addShoeTest { +public class AddShoeTest { } diff --git a/tests/itemControllerTests/BestSellingProductTest.java b/tests/itemControllerTests/BestSellingProductTest.java new file mode 100644 index 0000000..87e4a3f --- /dev/null +++ b/tests/itemControllerTests/BestSellingProductTest.java @@ -0,0 +1,4 @@ +package itemControllerTests; + +public class BestSellingProductTest { +} diff --git a/tests/itemControllerTests/searchItemTest.java b/tests/itemControllerTests/SearchItemTest.java similarity index 51% rename from tests/itemControllerTests/searchItemTest.java rename to tests/itemControllerTests/SearchItemTest.java index 6830d56..6fe2d22 100644 --- a/tests/itemControllerTests/searchItemTest.java +++ b/tests/itemControllerTests/SearchItemTest.java @@ -1,4 +1,4 @@ package itemControllerTests; -public class searchItemTest { +public class SearchItemTest { } diff --git a/tests/itemControllerTests/bestSellingProductTest.java b/tests/itemControllerTests/bestSellingProductTest.java deleted file mode 100644 index 4e337b2..0000000 --- a/tests/itemControllerTests/bestSellingProductTest.java +++ /dev/null @@ -1,4 +0,0 @@ -package itemControllerTests; - -public class bestSellingProductTest { -} diff --git a/tests/memberControllerTests/AddClubMemberTest.java b/tests/memberControllerTests/AddClubMemberTest.java new file mode 100644 index 0000000..b3fa871 --- /dev/null +++ b/tests/memberControllerTests/AddClubMemberTest.java @@ -0,0 +1,122 @@ +package memberControllerTests; + +import controller.GeneralOpController; +import controller.MemberController; +import model.entities.Member; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.fail; + +public class AddClubMemberTest { + MemberController memberController; + private final static int MOCK_POSITIVE = 1; + private final static int MOCK_NEGATIVE = -1; + private final static int MOCK_ZERO = 0; + private final static String MOCK_NAME = "Daniel"; + private final static String MOCK_DATEOFBIRTH = "31/3/1990"; + private final static int MOCK_POINTSGAINED = 5550; + private final static String MOCK_EMPTYSTRING = ""; + private final static Member MOCK_MEMBER_WITHOUTNAME = new Member(MOCK_EMPTYSTRING , MOCK_DATEOFBIRTH,MOCK_POSITIVE, MOCK_POINTSGAINED); + private final static Member MOCK_MEMBER_WITHOUTDATEOFBIRTH = new Member(MOCK_NAME, MOCK_EMPTYSTRING,MOCK_POSITIVE, MOCK_POINTSGAINED); + private final static Member MOCK_MEMBER_WITHOUTID = new Member(MOCK_NAME, MOCK_DATEOFBIRTH,MOCK_NEGATIVE, MOCK_POINTSGAINED); + private final static Member MOCK_MEMBER_WITHOUTIDOTHER = new Member(MOCK_NAME, MOCK_DATEOFBIRTH,MOCK_ZERO, MOCK_POINTSGAINED); + private final static Member MOCK_MEMBER_WITHOUTPOINTSGAINED = new Member(MOCK_NAME, MOCK_DATEOFBIRTH,MOCK_ZERO, MOCK_NEGATIVE); + + + @BeforeEach + public void setUp() + { + memberController = new MemberController(); + } + + @Test + public void failAddNameTest() + { + try { + memberController.addClubMember(MOCK_MEMBER_WITHOUTNAME); + fail("The addition succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("name or id or pointsgaind or dateofbirth must not be null or wrong", e.getMessage()); + + } + + } + + + @Test + public void failAddDateOfBirthTest() + { + try { + memberController.addClubMember(MOCK_MEMBER_WITHOUTDATEOFBIRTH); + fail("The addition succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("name or id or pointsgaind or dateofbirth must not be null or wrong", e.getMessage()); + + } + + } + + @Test + public void failAddIdTest() + { + try { + memberController.addClubMember(MOCK_MEMBER_WITHOUTID); + fail("The addition succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("name or id or pointsgaind or dateofbirth must not be null or wrong", e.getMessage()); + + } + + } + + @Test + public void failAddIdOtherTest() + { + try { + memberController.addClubMember(MOCK_MEMBER_WITHOUTIDOTHER); + fail("The addition succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("name or id or pointsgaind or dateofbirth must not be null or wrong", e.getMessage()); + + } + + } + + @Test + public void failAddPointsGainedTest() + { + try { + memberController.addClubMember(MOCK_MEMBER_WITHOUTPOINTSGAINED); + fail("The addition succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("name or id or pointsgaind or dateofbirth must not be null or wrong", e.getMessage()); + + } + + } + + + + + + + + + + + + + +} diff --git a/tests/memberControllerTests/addClubMemberTest.java b/tests/memberControllerTests/addClubMemberTest.java deleted file mode 100644 index 6d2d986..0000000 --- a/tests/memberControllerTests/addClubMemberTest.java +++ /dev/null @@ -1,4 +0,0 @@ -package memberControllerTests; - -public class addClubMemberTest { -} diff --git a/tests/memberControllerTests/birthdayPointAutoTest.java b/tests/memberControllerTests/birthdayPointAutoTest.java deleted file mode 100644 index d364fe1..0000000 --- a/tests/memberControllerTests/birthdayPointAutoTest.java +++ /dev/null @@ -1,4 +0,0 @@ -package memberControllerTests; - -public class birthdayPointAutoTest { -} diff --git a/tests/purchaseControllerTests/LastPurchaseTest.java b/tests/purchaseControllerTests/LastPurchaseTest.java new file mode 100644 index 0000000..9cc37ea --- /dev/null +++ b/tests/purchaseControllerTests/LastPurchaseTest.java @@ -0,0 +1,74 @@ +package purchaseControllerTests; + +import controller.PurchaseController; +import model.entities.Purchase; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class LastPurchaseTest { + + PurchaseController purchaseController; + private final static int MOCK_NEGATIVE = -1; + private final static int MOCK_ZERO = 0; + private final static int MOCK_POSITIVE = 1; + private final static int MOCK_ID_NOT_EXIST = 9999; + + @BeforeEach + public void setUp() + { + purchaseController = new PurchaseController(); + } + + + @Test + public void failMemberIdTest() + { + try { + purchaseController.lastPurchase(MOCK_NEGATIVE); + fail("The addition succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("id must not be negative", e.getMessage()); + + } + } + + + @Test + public void failMemberIdOtherTest() + { + try { + purchaseController.lastPurchase(MOCK_ZERO); + fail("The addition succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("id must not be zero", e.getMessage()); + + } + } + + @Test + public void failNullPurchaseTest() { + + Purchase p = purchaseController.lastPurchase(MOCK_POSITIVE); + assertNotNull(p); + } + + @Test + public void failNotNullPurchaseTest() { + + Purchase p = purchaseController.lastPurchase(MOCK_ID_NOT_EXIST); + assertNull(p); + + } + + + + + +} diff --git a/tests/purchaseControllerTests/SellingTest.java b/tests/purchaseControllerTests/SellingTest.java new file mode 100644 index 0000000..6b52a77 --- /dev/null +++ b/tests/purchaseControllerTests/SellingTest.java @@ -0,0 +1,112 @@ +package purchaseControllerTests; + +import controller.GeneralOpController; +import controller.PurchaseController; +import model.entities.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import javax.management.MBeanAttributeInfo; +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.fail; + +public class SellingTest { + + PurchaseController purchaseController; + private final static int MOCK_NEGATIVE = -1; + private final static int MOCK_ZERO = 0; + private final static int MOCK_POSITIVE = 1; + private final static int MOCK_ID_NOT_EXIST = 9999; + private final static String MOCK_NAME = "Yuval"; + private final static String MOCK_DATEOFBIRTH = "31/3/1990"; + private final static int MOCK_POINTSGAINED = 5550; + private final static Member MOCK_EMPTY_MEMBER = new Member(); + private final static Member MOCK_MEMBER = new Member(MOCK_NAME, MOCK_DATEOFBIRTH, MOCK_POSITIVE, MOCK_POINTSGAINED); + +/* + + */ + + @BeforeEach + public void setUp() + { + purchaseController = new PurchaseController(); + } + + @Test + public void failMemberTest() + { + try { + Item MOCK_ITEM = new Shoe("blue", "nabibas", "men", "shoe", 300, 40, 200, 50, 1,"bermuda"); + ArrayList MOCK_LIST = new ArrayList(); + MOCK_LIST.add(MOCK_ITEM); + + Purchase p = new Purchase(MOCK_EMPTY_MEMBER, MOCK_LIST, MOCK_POSITIVE, MOCK_POSITIVE); + purchaseController.selling(p); + fail("The selling succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("name or id or pointsgaind or dateofbirth must not be null or wrong", e.getMessage()); + + } + } + + @Test + public void failArrayListTest() + { + try { + + ArrayList MOCK_LIST = new ArrayList(); + Purchase p = new Purchase(MOCK_MEMBER, MOCK_LIST, MOCK_POSITIVE, MOCK_POSITIVE); + purchaseController.selling(p); + fail("The selling succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("The Array list Items must not be null or empty", e.getMessage()); + + } + } + + @Test + public void failPriceTest() + { + try { + Item MOCK_ITEM = new Shoe("blue", "nabibas", "men", "shoe", 300, 40, 200, 50, 1,"bermuda"); + ArrayList MOCK_LIST = new ArrayList(); + MOCK_LIST.add(MOCK_ITEM); + + Purchase p = new Purchase(MOCK_MEMBER, MOCK_LIST, MOCK_NEGATIVE, MOCK_POSITIVE); + purchaseController.selling(p); + fail("The selling succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("the price or shoppingRating must not be negative", e.getMessage()); + + } + } + + @Test + public void failTest() + { + try { + Item MOCK_ITEM = new Shoe("blue", "nabibas", "men", "shoe", 300, 40, 200, 50, 1,"bermuda"); + ArrayList MOCK_LIST = new ArrayList(); + MOCK_LIST.add(MOCK_ITEM); + + Purchase p = new Purchase(MOCK_MEMBER, MOCK_LIST, MOCK_POSITIVE, MOCK_NEGATIVE); + purchaseController.selling(p); + fail("The selling succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("the price or shoppingRating must not be negative", e.getMessage()); + + } + } + +} diff --git a/tests/purchaseControllerTests/lastPurchaseTest.java b/tests/purchaseControllerTests/lastPurchaseTest.java deleted file mode 100644 index 979c5b7..0000000 --- a/tests/purchaseControllerTests/lastPurchaseTest.java +++ /dev/null @@ -1,4 +0,0 @@ -package purchaseControllerTests; - -public class lastPurchaseTest { -} diff --git a/tests/purchaseControllerTests/sellingTest.java b/tests/purchaseControllerTests/sellingTest.java deleted file mode 100644 index 392442d..0000000 --- a/tests/purchaseControllerTests/sellingTest.java +++ /dev/null @@ -1,4 +0,0 @@ -package purchaseControllerTests; - -public class sellingTest { -} From bcf124201bf0b9ec1a3c881b3f3e934ed2d1acdb Mon Sep 17 00:00:00 2001 From: Rafi Date: Sat, 13 Jun 2020 20:47:23 +0300 Subject: [PATCH 13/48] =?UTF-8?q?=D7=98=D7=A1=D7=98=D7=99=D7=9D=20+=20?= =?UTF-8?q?=D7=94=D7=A4=D7=95=D7=A0'=20=D7=90=D7=95=D7=98=D7=95'=20=D7=AA?= =?UTF-8?q?=D7=95=D7=A4=D7=A2=D7=9C=20=D7=A8=D7=A7=20=D7=A9=D7=9E=D7=AA?= =?UTF-8?q?=D7=97=D7=91=D7=A8=D7=99=D7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/UserInterface.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/view/UserInterface.java b/src/view/UserInterface.java index 1795b16..0b98cf1 100644 --- a/src/view/UserInterface.java +++ b/src/view/UserInterface.java @@ -16,7 +16,6 @@ public void start() { @Override public void run() { viewFunc.birthDayAuto(); - viewFunc.autoFunc(); for(int i=1;i<=3;i++) { String str = viewFunc.login(); if (str.equals( "manager")) { @@ -35,6 +34,7 @@ public void run() { public void workerScreen() { + viewFunc.autoFunc(); Scanner s = new Scanner(System.in); while(true) { System.out.println("Hello Worker!!"); @@ -80,6 +80,7 @@ public void workerScreen() public void managerScreen() { + viewFunc.autoFunc(); Scanner s = new Scanner(System.in); while(true) { System.out.println("Hello Manager!!"); From 8e856be8624c0626b68669e1a4173e127fac3653 Mon Sep 17 00:00:00 2001 From: Rafi Date: Sat, 13 Jun 2020 21:00:36 +0300 Subject: [PATCH 14/48] =?UTF-8?q?=D7=98=D7=A1=D7=98=D7=99=D7=9D=20+=20?= =?UTF-8?q?=D7=94=D7=A4=D7=95=D7=A0'=20=D7=90=D7=95=D7=98=D7=95'=20=D7=AA?= =?UTF-8?q?=D7=95=D7=A4=D7=A2=D7=9C=20=D7=A8=D7=A7=20=D7=A9=D7=9E=D7=AA?= =?UTF-8?q?=D7=97=D7=91=D7=A8=D7=99=D7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/UserInterface.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/view/UserInterface.java b/src/view/UserInterface.java index 0b98cf1..ff5ae4e 100644 --- a/src/view/UserInterface.java +++ b/src/view/UserInterface.java @@ -15,7 +15,6 @@ public void start() { @Override public void run() { - viewFunc.birthDayAuto(); for(int i=1;i<=3;i++) { String str = viewFunc.login(); if (str.equals( "manager")) { @@ -35,6 +34,7 @@ public void run() { public void workerScreen() { viewFunc.autoFunc(); + viewFunc.birthDayAuto(); Scanner s = new Scanner(System.in); while(true) { System.out.println("Hello Worker!!"); @@ -81,6 +81,7 @@ public void workerScreen() public void managerScreen() { viewFunc.autoFunc(); + viewFunc.birthDayAuto(); Scanner s = new Scanner(System.in); while(true) { System.out.println("Hello Manager!!"); From 5c6c4636b4c67bfdd2fe0a846e93becaf390b9fb Mon Sep 17 00:00:00 2001 From: Rafi Date: Sun, 14 Jun 2020 12:19:56 +0300 Subject: [PATCH 15/48] cli --- src/view/UserInterface.java | 23 +++++++++++++---------- src/view/ViewFunc.java | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/view/UserInterface.java b/src/view/UserInterface.java index ff5ae4e..6b4fd14 100644 --- a/src/view/UserInterface.java +++ b/src/view/UserInterface.java @@ -15,20 +15,21 @@ public void start() { @Override public void run() { - for(int i=1;i<=3;i++) { + while (true){ String str = viewFunc.login(); if (str.equals( "manager")) { managerScreen(); - return; + } if (str.equals("worker")) { workerScreen(); - return; + + } + if (str.equals("none")) { + System.out.println("try again"); } - if (str.equals("none")) - System.out.println("try again! **num "+i+" (at the third try the program will close!)"); } - System.out.println("you should remember your password for the next time..."); + } public void workerScreen() @@ -46,7 +47,7 @@ public void workerScreen() System.out.println("5. selling"); System.out.println("6. watch last purchase"); System.out.println("7. watch my monthly salary"); - System.out.println("Any other number to exit"); + System.out.println("Any other number to logout"); int temp=s.nextInt(); switch (temp) { case 1: @@ -71,7 +72,8 @@ public void workerScreen() viewFunc.watchMonthlySalary(); break; default: - System.out.println("***exit***)"); + System.out.println("** logout **"); + System.out.println(""); return; } } @@ -98,7 +100,7 @@ public void managerScreen() System.out.println("10. add new shoe/pants/shirt"); System.out.println("11. Change Hourly Salary"); System.out.println("12. add Worker"); - System.out.println("Any other number to exit"); + System.out.println("Any other number to logout"); int temp=s.nextInt(); switch (temp) { case 1: @@ -138,7 +140,8 @@ public void managerScreen() viewFunc.addWorker(); break; default: - System.out.println("***exit***"); + System.out.println("** logout **"); + System.out.println(""); return; } } diff --git a/src/view/ViewFunc.java b/src/view/ViewFunc.java index 4ae53e3..39a6fab 100644 --- a/src/view/ViewFunc.java +++ b/src/view/ViewFunc.java @@ -28,6 +28,7 @@ public ViewFunc() { } public String login(){ + System.out.println("Login"); Scanner s = new Scanner(System.in); System.out.println("enter your id: "); int id = s.nextInt(); From d896dcfa20db7e9a31bdd63a69702d8e5a33a77f Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Sat, 13 Jun 2020 13:34:03 +0300 Subject: [PATCH 16/48] lellwlw --- .../ProjectClothingStore.kotlin_module | Bin 16 -> 0 bytes src/model/AutoFuncModel.java | 37 ++++++++------- src/model/ItemModel.java | 44 ++++++------------ src/model/MemberModel.java | 14 ++---- src/model/PurchaseModel.java | 6 +-- src/model/WorkerModel.java | 16 ++----- src/view/ViewFunc.java | 15 +----- 7 files changed, 48 insertions(+), 84 deletions(-) delete mode 100644 production/test/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module diff --git a/production/test/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module b/production/test/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module deleted file mode 100644 index a49347afef10a9b5f95305e1058ba36adec7d6dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16 RcmZQzU|?ooU|@t|0RRA102TlM diff --git a/src/model/AutoFuncModel.java b/src/model/AutoFuncModel.java index 6477600..cb477e5 100644 --- a/src/model/AutoFuncModel.java +++ b/src/model/AutoFuncModel.java @@ -3,14 +3,8 @@ import model.entities.Item; import java.util.ArrayList; -import java.util.Date; -import java.util.Timer; -import java.util.TimerTask; - -import static java.lang.Thread.sleep; - -public class AutoFuncModel { +public class AutoFuncModel implements Runnable { public void checkCurrentStock() { int i; @@ -29,17 +23,24 @@ public void checkCurrentStock() { } } - public void runCheckCurrentStock() - { - TimerTask task = new TimerTask() { + @Override + public void run() { + checkCurrentStock(); + } - @Override - public void run() { - checkCurrentStock(); - } - }; + public void checkCurrentStockThread() { + int i; + try { + Runnable runnable = new AutoFuncModel(); + Thread t1 = new Thread(runnable); + for (i = 144; i > 0; i--) { // 10 minutes loop, All day long + t1.run(); + Thread.sleep(6000000); // 10 Minutes + } + + } catch (InterruptedException e) { + System.out.println("Thread interrupted."); + } - Timer timer = new Timer(); - timer.schedule(task, new Date(), 300000); - } + } } diff --git a/src/model/ItemModel.java b/src/model/ItemModel.java index 8f78512..67e27c0 100644 --- a/src/model/ItemModel.java +++ b/src/model/ItemModel.java @@ -78,12 +78,12 @@ public boolean isAllItemsExist(Purchase pur) { } public void addPants(Pants pants) { - if (!isItemExists(pants.getItemId(), pants.getSize())) { + if (!isItemExists(pants.getItemId(), pants.getSize())) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?);"; @@ -115,24 +115,21 @@ public void addPants(Pants pants) { } catch (SQLException e) { e.printStackTrace(); } + } System.out.println("action succeeded!"); - - } - else { + } else { System.out.println("the item is already exists!"); - } - } - + } public void addShoe(Shoe shoe) { if (!isItemExists(shoe.getItemId(), shoe.getSize())) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; @@ -164,24 +161,20 @@ public void addShoe(Shoe shoe) { } catch (SQLException e) { e.printStackTrace(); } + System.out.println("action succeeded!"); } - - System.out.println("action succeeded!"); - } - else { + } else { System.out.println("the item is already exists!"); - } - } - - + } public void addShirt(Shirt shirt) { + if (!isItemExists(shirt.getItemId(), shirt.getSize())) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; @@ -214,19 +207,12 @@ public void addShirt(Shirt shirt) { } catch (SQLException e) { e.printStackTrace(); } + System.out.println("action succeeded!"); } - System.out.println("action succeeded!"); - } - else { + } else { System.out.println("the item is already exists!"); - - } - } - - - - - } +} + diff --git a/src/model/MemberModel.java b/src/model/MemberModel.java index 8f0fd41..f94e1cb 100644 --- a/src/model/MemberModel.java +++ b/src/model/MemberModel.java @@ -21,7 +21,7 @@ public void addClubMember(Member m) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO clubmembers" + " (name, id, dateofbirth, pointgained) VALUES " + " (?, ?, ?, ?);"; @@ -49,8 +49,7 @@ public void addClubMember(Member m) { } System.out.println("action succeeded!"); } - else - { + else { System.out.println("the member is already exists!"); } } @@ -60,11 +59,10 @@ public void deleteClubMember(int id) { String idNumber = String.valueOf(id); String DELETE_USERS_SQL = "delete from clubmembers where id = " + idNumber + ";"; if (isExistsClubMember(id) == true) { - try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement statement = connection.createStatement(); statement.executeUpdate(DELETE_USERS_SQL); System.out.println("Deletion was successfully"); @@ -72,9 +70,7 @@ public void deleteClubMember(int id) { } catch (Exception e) { e.printStackTrace(); } - - System.out.println("action succeed!"); - + System.out.println("action succeeded!"); } else { System.out.println("Unable to delete, no such user in the system"); } @@ -146,7 +142,7 @@ public void updateMembersPoints(int price, Member m) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement stmt = connection.createStatement(); String strUpdate = "update clubmembers set pointgained = pointgained +" + price + " where id =" + m.getId(); diff --git a/src/model/PurchaseModel.java b/src/model/PurchaseModel.java index d5e8e53..64cb48b 100644 --- a/src/model/PurchaseModel.java +++ b/src/model/PurchaseModel.java @@ -31,7 +31,7 @@ public Purchase lastPurchase(int memId) { } catch (Exception e) { e.printStackTrace(); } - return null; + return null; } public String selling(Purchase pur) { @@ -63,7 +63,7 @@ public String selling(Purchase pur) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement stmt = connection.createStatement(); for(i=0;i Date: Sat, 13 Jun 2020 14:22:24 +0300 Subject: [PATCH 17/48] lala2 --- src/model/AutoFuncModel.java | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/model/AutoFuncModel.java b/src/model/AutoFuncModel.java index cb477e5..d66d4bb 100644 --- a/src/model/AutoFuncModel.java +++ b/src/model/AutoFuncModel.java @@ -3,8 +3,14 @@ import model.entities.Item; import java.util.ArrayList; +import java.util.Date; +import java.util.Timer; +import java.util.TimerTask; + +import static java.lang.Thread.sleep; + +public class AutoFuncModel { -public class AutoFuncModel implements Runnable { public void checkCurrentStock() { int i; @@ -23,24 +29,16 @@ public void checkCurrentStock() { } } - @Override - public void run() { - checkCurrentStock(); - } + public void runCheckCurrentStock() { + TimerTask task = new TimerTask() { - public void checkCurrentStockThread() { - int i; - try { - Runnable runnable = new AutoFuncModel(); - Thread t1 = new Thread(runnable); - for (i = 144; i > 0; i--) { // 10 minutes loop, All day long - t1.run(); - Thread.sleep(6000000); // 10 Minutes - } - - } catch (InterruptedException e) { - System.out.println("Thread interrupted."); - } + @Override + public void run() { + checkCurrentStock(); + } + }; - } + Timer timer = new Timer(); + timer.schedule(task, new Date(), 300000); + } } From 9df57edc0d14504f11177e81612b86e50a0ccfec Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Sun, 14 Jun 2020 12:36:57 +0300 Subject: [PATCH 18/48] new class --- src/driver/MVCDriver.java | 1 - src/model/ManagerModel.java | 2 +- src/model/StoreModel.java | 8 ++++---- src/view/UserInterface.java | 10 +++++++++- src/view/ViewFunc.java | 10 ++++++++++ 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/driver/MVCDriver.java b/src/driver/MVCDriver.java index 61356e5..b95f8ca 100644 --- a/src/driver/MVCDriver.java +++ b/src/driver/MVCDriver.java @@ -7,6 +7,5 @@ public static void main(String[] args) { UserInterface view = new UserInterface(); view.start(); } - } diff --git a/src/model/ManagerModel.java b/src/model/ManagerModel.java index 359f9ba..f7952ef 100644 --- a/src/model/ManagerModel.java +++ b/src/model/ManagerModel.java @@ -13,7 +13,7 @@ public String changeHourlySalary(int workerId, int newSalary) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement stmt = connection.createStatement(); String strUpdate = "update workers set hourlysalary = " + newSalary + " where id =" + workerId; diff --git a/src/model/StoreModel.java b/src/model/StoreModel.java index 6e89ae1..37d2be2 100644 --- a/src/model/StoreModel.java +++ b/src/model/StoreModel.java @@ -34,7 +34,7 @@ public static ArrayList getAllPurchase() { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -148,7 +148,7 @@ public static ArrayList getClubMembers() { ClubMembers = new ArrayList(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -190,7 +190,7 @@ public static ArrayList getItems() { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -250,7 +250,7 @@ public static ArrayList getWorkers() { Workers = new ArrayList<>(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); diff --git a/src/view/UserInterface.java b/src/view/UserInterface.java index 6b4fd14..29294f1 100644 --- a/src/view/UserInterface.java +++ b/src/view/UserInterface.java @@ -15,6 +15,7 @@ public void start() { @Override public void run() { + int i=1; while (true){ String str = viewFunc.login(); if (str.equals( "manager")) { @@ -26,7 +27,14 @@ public void run() { } if (str.equals("none")) { - System.out.println("try again"); + if (i==3) { + System.out.println("mistake number "+i+"/3"); + System.out.println("the program closes"); + return; + } + System.out.println("username or password are - try again!"); + System.out.println("mistake number "+i+"/3"); + i++; } } diff --git a/src/view/ViewFunc.java b/src/view/ViewFunc.java index efaca8b..6dac25f 100644 --- a/src/view/ViewFunc.java +++ b/src/view/ViewFunc.java @@ -16,6 +16,16 @@ public class ViewFunc{ private WorkerController workerController; private GeneralOpController generalOpController; + public void birthDayAuto() + { + memberController.birthdayPointAuto(); + } + + public void autoFunc() + { + autoFuncController.checkCurrentStock(); + } + public ViewFunc() { autoFuncController = new AutoFuncController(); itemController = new ItemController(); From 40a7d6af67f16b444acd02be932bcd4145a95642 Mon Sep 17 00:00:00 2001 From: Rafi Date: Sun, 14 Jun 2020 14:46:47 +0300 Subject: [PATCH 19/48] cli --- src/controller/GeneralOpController.java | 2 +- src/controller/ItemController.java | 2 +- src/controller/ManagerController.java | 2 +- src/controller/MemberController.java | 6 ++--- src/controller/PurchaseController.java | 2 +- src/controller/StoreController.java | 2 +- src/controller/WorkerController.java | 2 +- src/model/ItemModel.java | 4 ++-- src/model/ManagerModel.java | 2 +- src/model/MemberModel.java | 20 ++++++++-------- src/model/PurchaseModel.java | 4 ++-- src/model/StoreModel.java | 8 +++---- src/model/WorkerModel.java | 2 +- src/view/ViewFunc.java | 7 +++++- tests/itemControllerTests/AddPantsTest.java | 18 ++++++++++++++ .../AddClubMemberTest.java | 24 +++++++++++++++---- 16 files changed, 72 insertions(+), 35 deletions(-) diff --git a/src/controller/GeneralOpController.java b/src/controller/GeneralOpController.java index fafc9ae..a508157 100644 --- a/src/controller/GeneralOpController.java +++ b/src/controller/GeneralOpController.java @@ -4,7 +4,7 @@ import model.entities.*; public class GeneralOpController { - protected model.GeneralOpModel model; + protected GeneralOpModel model; public GeneralOpController() { this.model = new model.GeneralOpModel(); diff --git a/src/controller/ItemController.java b/src/controller/ItemController.java index e53ab9d..b35abd4 100644 --- a/src/controller/ItemController.java +++ b/src/controller/ItemController.java @@ -6,7 +6,7 @@ public class ItemController { - protected model.ItemModel model; + protected ItemModel model; public ItemController() { this.model = new ItemModel(); diff --git a/src/controller/ManagerController.java b/src/controller/ManagerController.java index c25383b..bca71a5 100644 --- a/src/controller/ManagerController.java +++ b/src/controller/ManagerController.java @@ -6,7 +6,7 @@ public class ManagerController { - protected model.ManagerModel model; + protected ManagerModel model; public ManagerController() { diff --git a/src/controller/MemberController.java b/src/controller/MemberController.java index 2d9d883..f1c0393 100644 --- a/src/controller/MemberController.java +++ b/src/controller/MemberController.java @@ -6,16 +6,16 @@ public class MemberController { - protected model.MemberModel model; + protected MemberModel model; public MemberController() { this.model = new MemberModel(); } - public void addClubMember(Member m) + public boolean addClubMember(Member m) { - model.addClubMember(m); + return model.addClubMember(m); } public void deleteClubMember(int id) diff --git a/src/controller/PurchaseController.java b/src/controller/PurchaseController.java index a93acf9..b946f3b 100644 --- a/src/controller/PurchaseController.java +++ b/src/controller/PurchaseController.java @@ -7,7 +7,7 @@ public class PurchaseController { - protected model.PurchaseModel model; + protected PurchaseModel model; public PurchaseController() { this.model = new PurchaseModel(); diff --git a/src/controller/StoreController.java b/src/controller/StoreController.java index b3047f5..9509a35 100644 --- a/src/controller/StoreController.java +++ b/src/controller/StoreController.java @@ -8,7 +8,7 @@ public class StoreController { - protected model.StoreModel model; + protected StoreModel model; public StoreController() { } diff --git a/src/controller/WorkerController.java b/src/controller/WorkerController.java index 766a6b5..0ef353d 100644 --- a/src/controller/WorkerController.java +++ b/src/controller/WorkerController.java @@ -5,7 +5,7 @@ public class WorkerController { - model.WorkerModel model; + WorkerModel model; public WorkerController() { this.model = new WorkerModel(); diff --git a/src/model/ItemModel.java b/src/model/ItemModel.java index 67e27c0..e74b122 100644 --- a/src/model/ItemModel.java +++ b/src/model/ItemModel.java @@ -129,7 +129,7 @@ public void addShoe(Shoe shoe) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; @@ -174,7 +174,7 @@ public void addShirt(Shirt shirt) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; diff --git a/src/model/ManagerModel.java b/src/model/ManagerModel.java index f7952ef..359f9ba 100644 --- a/src/model/ManagerModel.java +++ b/src/model/ManagerModel.java @@ -13,7 +13,7 @@ public String changeHourlySalary(int workerId, int newSalary) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); Statement stmt = connection.createStatement(); String strUpdate = "update workers set hourlysalary = " + newSalary + " where id =" + workerId; diff --git a/src/model/MemberModel.java b/src/model/MemberModel.java index f94e1cb..08f14da 100644 --- a/src/model/MemberModel.java +++ b/src/model/MemberModel.java @@ -11,17 +11,20 @@ public class MemberModel { public MemberModel() { } - public void addClubMember(Member m) { + public boolean addClubMember(Member m) { if(m.getName().trim().equals("") || (m.getId() <= 0) || m.getPointsGained() < 0 || m.getDateOfBirth().trim().equals("")) { throw new IllegalArgumentException("name or id or pointsgaind or dateofbirth must not be null or wrong"); } - if (isExistsClubMember(m.getId()) == false) { + if (isExistsClubMember(m.getId()) == true) { + throw new IllegalArgumentException("the member is exist"); + } + Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); String INSERT_USERS_SQL = "INSERT INTO clubmembers" + " (name, id, dateofbirth, pointgained) VALUES " + " (?, ?, ?, ?);"; @@ -47,11 +50,8 @@ public void addClubMember(Member m) { } } - System.out.println("action succeeded!"); - } - else { - System.out.println("the member is already exists!"); - } + return true; + } public void deleteClubMember(int id) { @@ -62,7 +62,7 @@ public void deleteClubMember(int id) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); Statement statement = connection.createStatement(); statement.executeUpdate(DELETE_USERS_SQL); System.out.println("Deletion was successfully"); @@ -142,7 +142,7 @@ public void updateMembersPoints(int price, Member m) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); Statement stmt = connection.createStatement(); String strUpdate = "update clubmembers set pointgained = pointgained +" + price + " where id =" + m.getId(); diff --git a/src/model/PurchaseModel.java b/src/model/PurchaseModel.java index 64cb48b..d347c8b 100644 --- a/src/model/PurchaseModel.java +++ b/src/model/PurchaseModel.java @@ -63,7 +63,7 @@ public String selling(Purchase pur) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); Statement stmt = connection.createStatement(); for(i=0;i getAllPurchase() { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -148,7 +148,7 @@ public static ArrayList getClubMembers() { ClubMembers = new ArrayList(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -190,7 +190,7 @@ public static ArrayList getItems() { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -250,7 +250,7 @@ public static ArrayList getWorkers() { Workers = new ArrayList<>(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); diff --git a/src/model/WorkerModel.java b/src/model/WorkerModel.java index ef10f64..032c68f 100644 --- a/src/model/WorkerModel.java +++ b/src/model/WorkerModel.java @@ -15,7 +15,7 @@ public void addWorker(Worker w) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); String INSERT_USERS_SQL = "INSERT INTO workers" + " (name, id, dateofbirth, hourlysalary, numHourMonth, jobType, password) VALUES " + " (?, ?, ?, ?, ?, ?, ?);"; diff --git a/src/view/ViewFunc.java b/src/view/ViewFunc.java index 6dac25f..8a29d9d 100644 --- a/src/view/ViewFunc.java +++ b/src/view/ViewFunc.java @@ -92,6 +92,7 @@ else if (item.getItemId()<0) public void addClubMember(){ Scanner s = new Scanner(System.in); + boolean a; System.out.println("enter member's name: "); String name = s.next(); System.out.println("enter birthday: "); @@ -100,7 +101,11 @@ public void addClubMember(){ int id = s.nextInt(); int gainedPoints = 0; Member m = new Member(name,birthday,id,gainedPoints); - memberController.addClubMember(m); + a = memberController.addClubMember(m); + if(a == true) + { + System.out.println("action succeed"); + } } public void deleteClubMember(){ diff --git a/tests/itemControllerTests/AddPantsTest.java b/tests/itemControllerTests/AddPantsTest.java index ff473e3..41b9f1a 100644 --- a/tests/itemControllerTests/AddPantsTest.java +++ b/tests/itemControllerTests/AddPantsTest.java @@ -1,4 +1,22 @@ package itemControllerTests; +import controller.GeneralOpController; +import controller.ItemController; +import org.junit.jupiter.api.BeforeEach; + public class AddPantsTest { + ItemController itemController; + private final static int MOCK_NEGATIVE = -1; + private final static int MOCK_ZERO = 0; + private final static int MOCK_POSITIVE = 1; + + @BeforeEach + public void setUp() + { + itemController = new ItemController(); + } + + + + } diff --git a/tests/memberControllerTests/AddClubMemberTest.java b/tests/memberControllerTests/AddClubMemberTest.java index b3fa871..5c5f63a 100644 --- a/tests/memberControllerTests/AddClubMemberTest.java +++ b/tests/memberControllerTests/AddClubMemberTest.java @@ -23,6 +23,7 @@ public class AddClubMemberTest { private final static Member MOCK_MEMBER_WITHOUTID = new Member(MOCK_NAME, MOCK_DATEOFBIRTH,MOCK_NEGATIVE, MOCK_POINTSGAINED); private final static Member MOCK_MEMBER_WITHOUTIDOTHER = new Member(MOCK_NAME, MOCK_DATEOFBIRTH,MOCK_ZERO, MOCK_POINTSGAINED); private final static Member MOCK_MEMBER_WITHOUTPOINTSGAINED = new Member(MOCK_NAME, MOCK_DATEOFBIRTH,MOCK_ZERO, MOCK_NEGATIVE); + private final static Member MOCK_MEMBER_EXIST = new Member("Yuval", "30/2/1999",1, 4534); @BeforeEach @@ -93,17 +94,30 @@ public void failAddIdOtherTest() } @Test - public void failAddPointsGainedTest() - { + public void failAddPointsGainedTest() { try { memberController.addClubMember(MOCK_MEMBER_WITHOUTPOINTSGAINED); fail("The addition succeed when should failed"); - } - catch (IllegalArgumentException e) - { + } catch (IllegalArgumentException e) { Assertions.assertEquals("name or id or pointsgaind or dateofbirth must not be null or wrong", e.getMessage()); } + } + + + @Test + public void failAddClubMemberTest() + { + try { + memberController.addClubMember(MOCK_MEMBER_EXIST); + fail("The addition succeed when should failed"); + } + catch (IllegalArgumentException e) + { + Assertions.assertEquals("the member is exist", e.getMessage()); + + } + } From 1e107f1da4911d03e2c4d42ba5031c3abb6970f8 Mon Sep 17 00:00:00 2001 From: Rafi Date: Sun, 14 Jun 2020 15:57:18 +0300 Subject: [PATCH 20/48] cli --- src/model/ItemModel.java | 29 ++++++++- tests/itemControllerTests/AddPantsTest.java | 45 ++++++++++++++ tests/itemControllerTests/AddShirtTest.java | 66 ++++++++++++++++++++ tests/itemControllerTests/AddShoeTest.java | 68 +++++++++++++++++++++ 4 files changed, 205 insertions(+), 3 deletions(-) diff --git a/src/model/ItemModel.java b/src/model/ItemModel.java index e74b122..9556f89 100644 --- a/src/model/ItemModel.java +++ b/src/model/ItemModel.java @@ -78,12 +78,19 @@ public boolean isAllItemsExist(Purchase pur) { } public void addPants(Pants pants) { - + if (pants.getItemId() < 0 || pants.getSize() < 0) + { + throw new IllegalArgumentException("id or size must not be negative"); + } + if (isItemExists(pants.getItemId(), pants.getSize())) + { + throw new IllegalArgumentException("id and size exist"); + } if (!isItemExists(pants.getItemId(), pants.getSize())) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?);"; @@ -125,6 +132,15 @@ public void addPants(Pants pants) { } public void addShoe(Shoe shoe) { + if (shoe.getItemId() < 0 || shoe.getSize() < 0) + { + throw new IllegalArgumentException("id or size must not be negative"); + } + if (isItemExists(shoe.getItemId(), shoe.getSize())) + { + throw new IllegalArgumentException("id and size exist"); + } + if (!isItemExists(shoe.getItemId(), shoe.getSize())) { Connection connection = null; try { @@ -169,7 +185,14 @@ public void addShoe(Shoe shoe) { } public void addShirt(Shirt shirt) { - + if (shirt.getItemId() < 0 || shirt.getSize() < 0) + { + throw new IllegalArgumentException("id or size must not be negative"); + } + if (isItemExists(shirt.getItemId(), shirt.getSize())) + { + throw new IllegalArgumentException("id and size exist"); + } if (!isItemExists(shirt.getItemId(), shirt.getSize())) { Connection connection = null; try { diff --git a/tests/itemControllerTests/AddPantsTest.java b/tests/itemControllerTests/AddPantsTest.java index 41b9f1a..43d2524 100644 --- a/tests/itemControllerTests/AddPantsTest.java +++ b/tests/itemControllerTests/AddPantsTest.java @@ -2,13 +2,22 @@ import controller.GeneralOpController; import controller.ItemController; +import model.entities.Item; +import model.entities.Pants; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.fail; public class AddPantsTest { ItemController itemController; private final static int MOCK_NEGATIVE = -1; private final static int MOCK_ZERO = 0; private final static int MOCK_POSITIVE = 1; + private final static int MOCK_ID_EXIST = 3; + private final static int MOCK_SIZE_EXIST = 30; + @BeforeEach public void setUp() @@ -16,7 +25,43 @@ public void setUp() itemController = new ItemController(); } + @Test + public void failIdTest() { + try { + Pants i = new Pants("blue", "niki", "men", "pants", 200, MOCK_POSITIVE, 200, 500, MOCK_NEGATIVE, "bermuda"); + itemController.addPants(i); + fail("The addition succeed when should failed"); + } catch (IllegalArgumentException e) { + Assertions.assertEquals("id or size must not be negative", e.getMessage()); + + } + } + + @Test + public void failSizeTest() { + try { + Pants i = new Pants("blue", "niki", "men", "pants", 200, MOCK_NEGATIVE, 200, 500, MOCK_POSITIVE, "bermuda"); + itemController.addPants(i); + fail("The addition succeed when should failed"); + } catch (IllegalArgumentException e) { + Assertions.assertEquals("id or size must not be negative", e.getMessage()); + } + } + + + @Test + public void failAddPantsTest() { + try { + Pants i = new Pants("blue", "niki", "men", "pants", 200, MOCK_SIZE_EXIST, 200, 500, MOCK_ID_EXIST, "bermuda"); + itemController.addPants(i); + fail("The addition succeed when should failed"); + } catch (IllegalArgumentException e) { + Assertions.assertEquals("id and size exist", e.getMessage()); + + } + + } } diff --git a/tests/itemControllerTests/AddShirtTest.java b/tests/itemControllerTests/AddShirtTest.java index f582b23..2be353d 100644 --- a/tests/itemControllerTests/AddShirtTest.java +++ b/tests/itemControllerTests/AddShirtTest.java @@ -1,4 +1,70 @@ package itemControllerTests; +import controller.ItemController; +import model.entities.Pants; +import model.entities.Shirt; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.fail; + public class AddShirtTest { + + ItemController itemController; + private final static int MOCK_NEGATIVE = -1; + private final static int MOCK_ZERO = 0; + private final static int MOCK_POSITIVE = 1; + private final static int MOCK_ID_EXIST = 5; + private final static int MOCK_SIZE_EXIST = 20; + + + @BeforeEach + public void setUp() + { + itemController = new ItemController(); + } + + @Test + public void failIdTest() { + try { + Shirt i = new Shirt("blue", "niki", "men", "pants", 200, MOCK_POSITIVE, 200, 500, MOCK_NEGATIVE, "lycra"); + itemController.addShirt(i); + fail("The addition succeed when should failed"); + } catch (IllegalArgumentException e) { + Assertions.assertEquals("id or size must not be negative", e.getMessage()); + + } + + } + + @Test + public void failSizeTest() { + try { + Shirt i = new Shirt("blue", "niki", "men", "pants", 200, MOCK_NEGATIVE, 200, 500,MOCK_POSITIVE, "lycra"); + itemController.addShirt(i); + fail("The addition succeed when should failed"); + } catch (IllegalArgumentException e) { + Assertions.assertEquals("id or size must not be negative", e.getMessage()); + + } + + } + + + @Test + public void failAddPantsTest() { + try { + Pants i = new Pants("blue", "niki", "men", "pants", 200, MOCK_SIZE_EXIST, 200, 500, MOCK_ID_EXIST, "bermuda"); + itemController.addPants(i); + fail("The addition succeed when should failed"); + } catch (IllegalArgumentException e) { + Assertions.assertEquals("id and size exist", e.getMessage()); + + } + + } } + + + diff --git a/tests/itemControllerTests/AddShoeTest.java b/tests/itemControllerTests/AddShoeTest.java index a57bb29..d86e416 100644 --- a/tests/itemControllerTests/AddShoeTest.java +++ b/tests/itemControllerTests/AddShoeTest.java @@ -1,4 +1,72 @@ package itemControllerTests; +import controller.ItemController; +import model.entities.Pants; +import model.entities.Shirt; +import model.entities.Shoe; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.fail; + public class AddShoeTest { + ItemController itemController; + private final static int MOCK_NEGATIVE = -1; + private final static int MOCK_ZERO = 0; + private final static int MOCK_POSITIVE = 1; + private final static int MOCK_ID_EXIST = 2; + private final static int MOCK_SIZE_EXIST = 40; + + + @BeforeEach + public void setUp() + { + itemController = new ItemController(); + } + @Test + public void failIdTest() { + try { + Shoe i = new Shoe("blue", "niki", "men", "pants", 200, MOCK_POSITIVE, 200, 500, MOCK_NEGATIVE, "lycra"); + itemController.addShoe(i); + fail("The addition succeed when should failed"); + } catch (IllegalArgumentException e) { + Assertions.assertEquals("id or size must not be negative", e.getMessage()); + + } + + } + + @Test + public void failSizeTest() { + try { + Shoe i = new Shoe("blue", "niki", "men", "pants", 200, MOCK_NEGATIVE, 200, 500, MOCK_POSITIVE, "lycra"); + itemController.addShoe(i); + fail("The addition succeed when should failed"); + } catch (IllegalArgumentException e) { + Assertions.assertEquals("id or size must not be negative", e.getMessage()); + + } + + } + + + + + @Test + public void failAddPantsTest() { + try { + Pants i = new Pants("blue", "niki", "men", "pants", 200, MOCK_SIZE_EXIST, 200, 500, MOCK_ID_EXIST, "bermuda"); + itemController.addPants(i); + fail("The addition succeed when should failed"); + } catch (IllegalArgumentException e) { + Assertions.assertEquals("id and size exist", e.getMessage()); + + } + + } } + + + + From 3de40a638a3558045951260db95724b02a8c57a0 Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Mon, 15 Jun 2020 12:45:41 +0300 Subject: [PATCH 21/48] new class --- src/controller/AutoFuncController.java | 5 ++- src/controller/ItemController.java | 15 +++---- src/controller/ManagerController.java | 21 +--------- src/controller/MemberController.java | 10 +++-- src/controller/PurchaseController.java | 2 +- src/controller/WorkerController.java | 6 +-- src/model/AutoFuncModel.java | 6 ++- src/model/GeneralOpModel.java | 1 - src/model/ItemModel.java | 37 +++++------------ src/model/ManagerModel.java | 10 ++--- src/model/MemberModel.java | 38 +++++++++-------- src/model/PurchaseModel.java | 11 ++--- src/model/StoreModel.java | 8 ++-- src/model/WorkerModel.java | 18 ++++----- src/view/ViewFunc.java | 56 +++++++++++++++++++++----- 15 files changed, 121 insertions(+), 123 deletions(-) diff --git a/src/controller/AutoFuncController.java b/src/controller/AutoFuncController.java index e947cfd..0611647 100644 --- a/src/controller/AutoFuncController.java +++ b/src/controller/AutoFuncController.java @@ -1,7 +1,10 @@ package controller; +import model.entities.Item; import view.*; import model.*; +import java.util.ArrayList; + public class AutoFuncController { @@ -13,7 +16,7 @@ public AutoFuncController() { public void checkCurrentStock() { - model.runCheckCurrentStock(); + model.runCheckCurrentStock(); } } diff --git a/src/controller/ItemController.java b/src/controller/ItemController.java index b35abd4..a4ac404 100644 --- a/src/controller/ItemController.java +++ b/src/controller/ItemController.java @@ -19,22 +19,19 @@ public Item searchItem(int id, int size) public Item bestSellingProduct() { return model.bestSellingProduct(); } - public boolean isAllItemsExist(Purchase pur) { - return model.isAllItemsExist(pur); - } public boolean isItemExists(int id, int size){return model.isItemExists(id,size);} - public void addPants(Pants pants) { - model.addPants(pants); + public boolean addPants(Pants pants) { + return model.addPants(pants); } - public void addShoe(Shoe shoe) { - model.addShoe(shoe); + public boolean addShoe(Shoe shoe) { + return model.addShoe(shoe); } - public void addShirt(Shirt shirt) { - model.addShirt(shirt); + public boolean addShirt(Shirt shirt) { + return model.addShirt(shirt); } } diff --git a/src/controller/ManagerController.java b/src/controller/ManagerController.java index bca71a5..20aca37 100644 --- a/src/controller/ManagerController.java +++ b/src/controller/ManagerController.java @@ -4,7 +4,7 @@ import model.entities.Worker; -public class ManagerController { +public class ManagerController extends WorkerController{ protected ManagerModel model; @@ -13,24 +13,7 @@ public ManagerController() { this.model = new ManagerModel(); } - public String changeHourlySalary(int workerId, int newSalary) { + public boolean changeHourlySalary(int workerId, int newSalary) { return model.changeHourlySalary(workerId, newSalary); } - - public void addWorker(Worker w) { - model.addWorker(w); - } - - public String watchMonthlySalary(int workerId) - { - return model.watchMonthlySalary(workerId); - } - - public boolean isExistsWorker(int workerId) - { - return model.isExistsWorker(workerId); - } - - - } diff --git a/src/controller/MemberController.java b/src/controller/MemberController.java index f1c0393..7ef2dea 100644 --- a/src/controller/MemberController.java +++ b/src/controller/MemberController.java @@ -3,6 +3,8 @@ import model.*; import model.entities.Member; +import java.util.ArrayList; + public class MemberController { @@ -18,9 +20,9 @@ public boolean addClubMember(Member m) return model.addClubMember(m); } - public void deleteClubMember(int id) + public boolean deleteClubMember(int id) { - model.deleteClubMember(id); + return model.deleteClubMember(id); } public boolean isExistsClubMember(int id) @@ -30,9 +32,9 @@ public boolean isExistsClubMember(int id) public Member searchMember(int id){return model.searchMember(id);} - public void birthdayPointAuto() + public ArrayList birthdayPointAuto() { - model.birthdayPointAuto(); + return model.birthdayPointAuto(); } public void updateMembersPoints(int price, Member m) diff --git a/src/controller/PurchaseController.java b/src/controller/PurchaseController.java index b946f3b..0c35764 100644 --- a/src/controller/PurchaseController.java +++ b/src/controller/PurchaseController.java @@ -17,7 +17,7 @@ public Purchase lastPurchase(int memId) { return model.lastPurchase(memId); } - public String selling(Purchase pur) + public int selling(Purchase pur) { return model.selling(pur); } diff --git a/src/controller/WorkerController.java b/src/controller/WorkerController.java index 0ef353d..12a2803 100644 --- a/src/controller/WorkerController.java +++ b/src/controller/WorkerController.java @@ -11,11 +11,11 @@ public WorkerController() { this.model = new WorkerModel(); } - public void addWorker(Worker w) { - model.addWorker(w); + public boolean addWorker(Worker w) { + return model.addWorker(w); } - public String watchMonthlySalary(int workerId) + public int watchMonthlySalary(int workerId) { return model.watchMonthlySalary(workerId); } diff --git a/src/model/AutoFuncModel.java b/src/model/AutoFuncModel.java index d66d4bb..7dc8901 100644 --- a/src/model/AutoFuncModel.java +++ b/src/model/AutoFuncModel.java @@ -14,24 +14,25 @@ public class AutoFuncModel { public void checkCurrentStock() { int i; - double presentOfCurrentStock = 0.2; + // ArrayList itemsLow = new ArrayList(); ArrayList items = new ArrayList(); try { items = StoreModel.getInstance().getItems(); for (i = 0; i < items.size(); i++) { if (((double) items.get(i).getCurrentStock() / items.get(i).getBaseStock()) < presentOfCurrentStock) { + // items.add(items.get(i)); System.out.println("System Message: stock is low. " + "item id:" + items.get(i).getItemId()); } } } catch (Exception e) { e.printStackTrace(); } + //return itemsLow; } public void runCheckCurrentStock() { TimerTask task = new TimerTask() { - @Override public void run() { checkCurrentStock(); @@ -40,5 +41,6 @@ public void run() { Timer timer = new Timer(); timer.schedule(task, new Date(), 300000); + } } diff --git a/src/model/GeneralOpModel.java b/src/model/GeneralOpModel.java index e72f453..59d0a4f 100644 --- a/src/model/GeneralOpModel.java +++ b/src/model/GeneralOpModel.java @@ -21,7 +21,6 @@ public double averageSellingRate() { e.printStackTrace(); } return sum; - } public String Login(int id, String password) { diff --git a/src/model/ItemModel.java b/src/model/ItemModel.java index 9556f89..d3d0a12 100644 --- a/src/model/ItemModel.java +++ b/src/model/ItemModel.java @@ -62,22 +62,7 @@ public Item bestSellingProduct() { return temp; } - public boolean isAllItemsExist(Purchase pur) { - int i; - try { - for (i = 0; i < pur.getItem().size(); i++) { - if(!isItemExists(pur.getItem().get(i).getItemId(),pur.getItem().get(i).getSize())) { - System.out.println("item:" +pur.getItem().get(i).getItemId()+" is not exist!"); - return false; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return true; - } - - public void addPants(Pants pants) { + public boolean addPants(Pants pants) { if (pants.getItemId() < 0 || pants.getSize() < 0) { throw new IllegalArgumentException("id or size must not be negative"); @@ -124,14 +109,12 @@ public void addPants(Pants pants) { } } - System.out.println("action succeeded!"); - } else { - System.out.println("the item is already exists!"); + return true; } - + return false; } - public void addShoe(Shoe shoe) { + public boolean addShoe(Shoe shoe) { if (shoe.getItemId() < 0 || shoe.getSize() < 0) { throw new IllegalArgumentException("id or size must not be negative"); @@ -177,14 +160,13 @@ public void addShoe(Shoe shoe) { } catch (SQLException e) { e.printStackTrace(); } - System.out.println("action succeeded!"); + return true; } - } else { - System.out.println("the item is already exists!"); } + return false; } - public void addShirt(Shirt shirt) { + public boolean addShirt(Shirt shirt) { if (shirt.getItemId() < 0 || shirt.getSize() < 0) { throw new IllegalArgumentException("id or size must not be negative"); @@ -230,11 +212,10 @@ public void addShirt(Shirt shirt) { } catch (SQLException e) { e.printStackTrace(); } - System.out.println("action succeeded!"); + return true; } - } else { - System.out.println("the item is already exists!"); } + return false; } } diff --git a/src/model/ManagerModel.java b/src/model/ManagerModel.java index 359f9ba..8dc410a 100644 --- a/src/model/ManagerModel.java +++ b/src/model/ManagerModel.java @@ -2,11 +2,11 @@ import java.sql.*; -public class ManagerModel extends WorkerModel { +public class ManagerModel extends WorkerModel { - public String changeHourlySalary(int workerId, int newSalary) { + public boolean changeHourlySalary(int workerId, int newSalary) { if (!isExistsWorker(workerId)) { - return "worker are not registered!\n"; + return false; } Connection connection = null; @@ -18,7 +18,7 @@ public String changeHourlySalary(int workerId, int newSalary) { Statement stmt = connection.createStatement(); String strUpdate = "update workers set hourlysalary = " + newSalary + " where id =" + workerId; int countUpdated = stmt.executeUpdate(strUpdate); - return "update successfully passed!"; + return true; } catch (IllegalAccessException | InstantiationException | SQLException | ClassNotFoundException e) { e.printStackTrace(); } finally { @@ -28,7 +28,7 @@ public String changeHourlySalary(int workerId, int newSalary) { e.printStackTrace(); } } - return "update failed!"; + return false; } diff --git a/src/model/MemberModel.java b/src/model/MemberModel.java index 08f14da..fb950bd 100644 --- a/src/model/MemberModel.java +++ b/src/model/MemberModel.java @@ -18,13 +18,13 @@ public boolean addClubMember(Member m) { } if (isExistsClubMember(m.getId()) == true) { - throw new IllegalArgumentException("the member is exist"); + throw new IllegalArgumentException("the member is already exist"); } Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO clubmembers" + " (name, id, dateofbirth, pointgained) VALUES " + " (?, ?, ?, ?);"; @@ -54,7 +54,7 @@ public boolean addClubMember(Member m) { } - public void deleteClubMember(int id) { + public boolean deleteClubMember(int id) { Connection connection = null; String idNumber = String.valueOf(id); String DELETE_USERS_SQL = "delete from clubmembers where id = " + idNumber + ";"; @@ -62,18 +62,15 @@ public void deleteClubMember(int id) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement statement = connection.createStatement(); statement.executeUpdate(DELETE_USERS_SQL); - System.out.println("Deletion was successfully"); - + return true; } catch (Exception e) { e.printStackTrace(); } - System.out.println("action succeeded!"); - } else { - System.out.println("Unable to delete, no such user in the system"); } + return false; } public boolean isExistsClubMember(int id) { @@ -109,10 +106,12 @@ public Member searchMember(int id) { return null; } - public void birthdayPointAuto() { + public ArrayList birthdayPointAuto() { int i; ArrayList clubMembers; + ArrayList birthdayMembers; try { + birthdayMembers = new ArrayList(); clubMembers = new ArrayList(); clubMembers = StoreModel.getInstance().getClubMembers(); Date date = new Date(); @@ -122,19 +121,18 @@ public void birthdayPointAuto() { for (i = 0; i < clubMembers.size(); i++) { String[] dateClubMember; dateClubMember = clubMembers.get(i).getDateOfBirth().split("/"); - int dayMember = Integer.parseInt(dateClubMember[0]); - int monthMember = Integer.parseInt(dateClubMember[1]); - if (Integer.valueOf(month) == Integer.valueOf(monthMember) && Integer.valueOf(day) == Integer.valueOf(dayMember)) { - updateMembersPoints(250, clubMembers.get(i)); - System.out.println("System message: 250 credits added to club member " + clubMembers.get(i).getName() + ", id: " + clubMembers.get(i).getId()); - } - + int dayMember = Integer.parseInt(dateClubMember[0]); + int monthMember = Integer.parseInt(dateClubMember[1]); + if (Integer.valueOf(month) == Integer.valueOf(monthMember) && Integer.valueOf(day) == Integer.valueOf(dayMember)) { + updateMembersPoints(250, clubMembers.get(i)); + birthdayMembers.add( clubMembers.get(i)); } - + } + return birthdayMembers; } catch (Exception e) { e.printStackTrace(); } - + return null; } public void updateMembersPoints(int price, Member m) { @@ -142,7 +140,7 @@ public void updateMembersPoints(int price, Member m) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement stmt = connection.createStatement(); String strUpdate = "update clubmembers set pointgained = pointgained +" + price + " where id =" + m.getId(); diff --git a/src/model/PurchaseModel.java b/src/model/PurchaseModel.java index d347c8b..6945222 100644 --- a/src/model/PurchaseModel.java +++ b/src/model/PurchaseModel.java @@ -34,7 +34,7 @@ public Purchase lastPurchase(int memId) { return null; } - public String selling(Purchase pur) { + public int selling(Purchase pur) { if(pur.getClubMember().getName().equals("valueless") || pur.getClubMember().getDateOfBirth().equals("-1") || pur.getClubMember().getId() < 0 || pur.getClubMember().getPointsGained() < 0) { throw new IllegalArgumentException("name or id or pointsgaind or dateofbirth must not be null or wrong"); @@ -52,10 +52,9 @@ public String selling(Purchase pur) { ItemModel itemModel = new ItemModel(); if(!updateStockMinus(pur)) - return "Purchase faild!"; + return -1; int price = newPrice(pur.getPrice(), pur.getClubMember()); - System.out.println("The price is: " + price); memMod.updateMembersPoints((int) (0.1*price), pur.getClubMember()); int i; String strDate = new SimpleDateFormat("dd/MM/yyyy").format(new Date()); @@ -80,8 +79,7 @@ public String selling(Purchase pur) { e.printStackTrace(); } } - return "Purchase succeeded!"; - + return price; } public int newPrice(int price, Member m) { @@ -106,7 +104,7 @@ public boolean updateStockMinus(Purchase pur) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement stmt = connection.createStatement(); for(i=0;i=0;j--) { String strUpdate2 = "update items set currentStock = currentStock +1 where itemid =" + pur.getItem().get(j).getItemId(); diff --git a/src/model/StoreModel.java b/src/model/StoreModel.java index 6e89ae1..37d2be2 100644 --- a/src/model/StoreModel.java +++ b/src/model/StoreModel.java @@ -34,7 +34,7 @@ public static ArrayList getAllPurchase() { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -148,7 +148,7 @@ public static ArrayList getClubMembers() { ClubMembers = new ArrayList(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -190,7 +190,7 @@ public static ArrayList getItems() { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -250,7 +250,7 @@ public static ArrayList getWorkers() { Workers = new ArrayList<>(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); diff --git a/src/model/WorkerModel.java b/src/model/WorkerModel.java index 032c68f..62fafaa 100644 --- a/src/model/WorkerModel.java +++ b/src/model/WorkerModel.java @@ -10,12 +10,12 @@ public class WorkerModel { - public void addWorker(Worker w) { + public boolean addWorker(Worker w) { if (isExistsWorker(w.getId()) == false) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO workers" + " (name, id, dateofbirth, hourlysalary, numHourMonth, jobType, password) VALUES " + " (?, ?, ?, ?, ?, ?, ?);"; @@ -40,18 +40,16 @@ public void addWorker(Worker w) { } catch (SQLException e) { e.printStackTrace(); } - System.out.println("action succeeded!"); + return true; } - } else { - System.out.println("the worker is already exists!"); } - + return false; } - public String watchMonthlySalary(int workerId) { + public int watchMonthlySalary(int workerId) { if (!isExistsWorker(workerId)) { - return "You are not registered!\n"; + return -1; } int i; @@ -60,13 +58,13 @@ public String watchMonthlySalary(int workerId) { workers = StoreModel.getInstance().getWorkers(); for (i = 0; i < workers.size(); i++) { if (workerId == (workers.get(i).getId())) { - return "Your monthly salary is: " + workers.get(i).getHourlySalary() * workers.get(i).getNumHourMonth() + "\n"; + return workers.get(i).getHourlySalary() * workers.get(i).getNumHourMonth(); } } } catch (Exception e) { e.printStackTrace(); } - return "You are not registered!\n"; + return -1; } public boolean isExistsWorker(int workerId) { diff --git a/src/view/ViewFunc.java b/src/view/ViewFunc.java index 8a29d9d..38c7d67 100644 --- a/src/view/ViewFunc.java +++ b/src/view/ViewFunc.java @@ -18,7 +18,11 @@ public class ViewFunc{ public void birthDayAuto() { - memberController.birthdayPointAuto(); + ArrayList temp = memberController.birthdayPointAuto(); + for(int i=0;i Date: Mon, 15 Jun 2020 12:46:22 +0300 Subject: [PATCH 22/48] new --- .../META-INF/ProjectClothingStore.kotlin_module | Bin 0 -> 16 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 production/test/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module diff --git a/production/test/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module b/production/test/ProjectClothingStore/META-INF/ProjectClothingStore.kotlin_module new file mode 100644 index 0000000000000000000000000000000000000000..a49347afef10a9b5f95305e1058ba36adec7d6dd GIT binary patch literal 16 RcmZQzU|?ooU|@t|0RRA102TlM literal 0 HcmV?d00001 From b75b754414b095e9197687d7598d66c381217fb6 Mon Sep 17 00:00:00 2001 From: Rafi Date: Mon, 15 Jun 2020 14:00:46 +0300 Subject: [PATCH 23/48] cli --- src/controller/AutoFuncController.java | 2 +- src/model/MemberModel.java | 6 +++--- src/model/PurchaseModel.java | 2 +- src/model/StoreModel.java | 8 ++++---- src/model/WorkerModel.java | 2 +- tests/itemControllerTests/AddPantsTest.java | 13 ++++++++++++- tests/itemControllerTests/AddShirtTest.java | 15 ++++++++++++++- tests/itemControllerTests/AddShoeTest.java | 13 +++++++++++++ .../AddClubMemberTest.java | 15 +++++++++++---- tests/purchaseControllerTests/SellingTest.java | 17 ++++++++++++++++- 10 files changed, 76 insertions(+), 17 deletions(-) diff --git a/src/controller/AutoFuncController.java b/src/controller/AutoFuncController.java index 0611647..79a146c 100644 --- a/src/controller/AutoFuncController.java +++ b/src/controller/AutoFuncController.java @@ -16,7 +16,7 @@ public AutoFuncController() { public void checkCurrentStock() { - model.runCheckCurrentStock(); + model.runCheckCurrentStock(); } } diff --git a/src/model/MemberModel.java b/src/model/MemberModel.java index fb950bd..5e792af 100644 --- a/src/model/MemberModel.java +++ b/src/model/MemberModel.java @@ -24,7 +24,7 @@ public boolean addClubMember(Member m) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); String INSERT_USERS_SQL = "INSERT INTO clubmembers" + " (name, id, dateofbirth, pointgained) VALUES " + " (?, ?, ?, ?);"; @@ -62,7 +62,7 @@ public boolean deleteClubMember(int id) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); Statement statement = connection.createStatement(); statement.executeUpdate(DELETE_USERS_SQL); return true; @@ -140,7 +140,7 @@ public void updateMembersPoints(int price, Member m) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); Statement stmt = connection.createStatement(); String strUpdate = "update clubmembers set pointgained = pointgained +" + price + " where id =" + m.getId(); diff --git a/src/model/PurchaseModel.java b/src/model/PurchaseModel.java index 6945222..b1243ff 100644 --- a/src/model/PurchaseModel.java +++ b/src/model/PurchaseModel.java @@ -104,7 +104,7 @@ public boolean updateStockMinus(Purchase pur) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); Statement stmt = connection.createStatement(); for(i=0;i getAllPurchase() { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -148,7 +148,7 @@ public static ArrayList getClubMembers() { ClubMembers = new ArrayList(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -190,7 +190,7 @@ public static ArrayList getItems() { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -250,7 +250,7 @@ public static ArrayList getWorkers() { Workers = new ArrayList<>(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); diff --git a/src/model/WorkerModel.java b/src/model/WorkerModel.java index 62fafaa..9794c51 100644 --- a/src/model/WorkerModel.java +++ b/src/model/WorkerModel.java @@ -15,7 +15,7 @@ public boolean addWorker(Worker w) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); String INSERT_USERS_SQL = "INSERT INTO workers" + " (name, id, dateofbirth, hourlysalary, numHourMonth, jobType, password) VALUES " + " (?, ?, ?, ?, ?, ?, ?);"; diff --git a/tests/itemControllerTests/AddPantsTest.java b/tests/itemControllerTests/AddPantsTest.java index 43d2524..2de8fd5 100644 --- a/tests/itemControllerTests/AddPantsTest.java +++ b/tests/itemControllerTests/AddPantsTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; public class AddPantsTest { @@ -17,7 +18,8 @@ public class AddPantsTest { private final static int MOCK_POSITIVE = 1; private final static int MOCK_ID_EXIST = 3; private final static int MOCK_SIZE_EXIST = 30; - + private final static int MOCK_ID_NOT_EXIST = 152; + private final static int MOCK_SIZE_NOT_EXIST = 56; @BeforeEach public void setUp() @@ -64,4 +66,13 @@ public void failAddPantsTest() { } } + + + @Test + public void failAddPantsSucceedTest() + { + Pants i = new Pants("blue", "niki", "men", "pants", 200, MOCK_SIZE_NOT_EXIST, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); + boolean a = itemController.addPants(i); + assertTrue(a); + } } diff --git a/tests/itemControllerTests/AddShirtTest.java b/tests/itemControllerTests/AddShirtTest.java index 2be353d..a575b14 100644 --- a/tests/itemControllerTests/AddShirtTest.java +++ b/tests/itemControllerTests/AddShirtTest.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; public class AddShirtTest { @@ -17,7 +18,7 @@ public class AddShirtTest { private final static int MOCK_POSITIVE = 1; private final static int MOCK_ID_EXIST = 5; private final static int MOCK_SIZE_EXIST = 20; - + private final static int MOCK_ID_NOT_EXIST = 5; @BeforeEach public void setUp() @@ -64,6 +65,18 @@ public void failAddPantsTest() { } } + + + + + @Test + public void failAddShirtSucceedTest() + { + Shirt i = new Shirt("blue", "niki", "men", "pants", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); + boolean a = itemController.addShirt(i); + assertTrue(a); + } + } diff --git a/tests/itemControllerTests/AddShoeTest.java b/tests/itemControllerTests/AddShoeTest.java index d86e416..eba900f 100644 --- a/tests/itemControllerTests/AddShoeTest.java +++ b/tests/itemControllerTests/AddShoeTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; public class AddShoeTest { @@ -17,6 +18,7 @@ public class AddShoeTest { private final static int MOCK_POSITIVE = 1; private final static int MOCK_ID_EXIST = 2; private final static int MOCK_SIZE_EXIST = 40; + private final static int MOCK_ID_NOT_EXIST = 80; @BeforeEach @@ -65,6 +67,17 @@ public void failAddPantsTest() { } } + + + + + @Test + public void failAddShirtSucceedTest() + { + Shoe i = new Shoe("blue", "niki", "men", "pants", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); + boolean a = itemController.addShoe(i); + assertTrue(a); + } } diff --git a/tests/memberControllerTests/AddClubMemberTest.java b/tests/memberControllerTests/AddClubMemberTest.java index 5c5f63a..003bf28 100644 --- a/tests/memberControllerTests/AddClubMemberTest.java +++ b/tests/memberControllerTests/AddClubMemberTest.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; public class AddClubMemberTest { MemberController memberController; @@ -24,7 +24,7 @@ public class AddClubMemberTest { private final static Member MOCK_MEMBER_WITHOUTIDOTHER = new Member(MOCK_NAME, MOCK_DATEOFBIRTH,MOCK_ZERO, MOCK_POINTSGAINED); private final static Member MOCK_MEMBER_WITHOUTPOINTSGAINED = new Member(MOCK_NAME, MOCK_DATEOFBIRTH,MOCK_ZERO, MOCK_NEGATIVE); private final static Member MOCK_MEMBER_EXIST = new Member("Yuval", "30/2/1999",1, 4534); - + private final static Member MOCK_MEMBER_NOT_EXIST = new Member("Dani", "30/2/1999",49, 4534); @BeforeEach public void setUp() @@ -112,16 +112,23 @@ public void failAddClubMemberTest() memberController.addClubMember(MOCK_MEMBER_EXIST); fail("The addition succeed when should failed"); } - catch (IllegalArgumentException e) - { + catch (IllegalArgumentException e) { Assertions.assertEquals("the member is exist", e.getMessage()); } + } + @Test + public void failAddClubMemberSucceedTest() +{ + boolean checkTrue = memberController.addClubMember(MOCK_MEMBER_NOT_EXIST); + assertTrue(checkTrue); + +} diff --git a/tests/purchaseControllerTests/SellingTest.java b/tests/purchaseControllerTests/SellingTest.java index 6b52a77..138d9c7 100644 --- a/tests/purchaseControllerTests/SellingTest.java +++ b/tests/purchaseControllerTests/SellingTest.java @@ -10,6 +10,8 @@ import javax.management.MBeanAttributeInfo; import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; public class SellingTest { @@ -91,7 +93,7 @@ public void failPriceTest() } @Test - public void failTest() + public void failSellingTest() { try { Item MOCK_ITEM = new Shoe("blue", "nabibas", "men", "shoe", 300, 40, 200, 50, 1,"bermuda"); @@ -109,4 +111,17 @@ public void failTest() } } + + @Test + public void failSellingReturnTest() + { + Item MOCK_ITEM = new Shoe("blue", "nabibas", "men", "shoe", 300, 40, 200, 50, 1,"bermuda"); + ArrayList MOCK_LIST = new ArrayList(); + MOCK_LIST.add(MOCK_ITEM); + + Purchase p = new Purchase(MOCK_MEMBER, MOCK_LIST, MOCK_POSITIVE, MOCK_POSITIVE); + int i = purchaseController.selling(p); + assertTrue(i > -2); + } + } From 485c1270109b53fbe09b82c640bca846156668a0 Mon Sep 17 00:00:00 2001 From: orshmar18 Date: Mon, 15 Jun 2020 22:48:24 +0300 Subject: [PATCH 24/48] add test to searh item and fix code design --- src/model/ItemModel.java | 12 ++-- src/view/ViewFunc.java | 69 ++++++++++--------- .../BestSellingProductTest.java | 14 ++++ tests/itemControllerTests/SearchItemTest.java | 58 ++++++++++++++++ 4 files changed, 116 insertions(+), 37 deletions(-) diff --git a/src/model/ItemModel.java b/src/model/ItemModel.java index 9556f89..6bd2274 100644 --- a/src/model/ItemModel.java +++ b/src/model/ItemModel.java @@ -10,7 +10,12 @@ public class ItemModel { - public Item searchItem(int id, int size) { //if exist and in stock + public Item searchItem(int id, int size) { + if(id <= 0 || size <= 0) + { + throw new IllegalArgumentException("id or size must be a positive number"); + } + int i; ArrayList items = new ArrayList<>(); try { @@ -23,8 +28,7 @@ public Item searchItem(int id, int size) { //if exist and in stock } catch (Exception e) { e.printStackTrace(); } - Item NONE = new Shirt(); - return NONE; + return null; } public boolean isItemExists(int id, int size) { @@ -45,7 +49,7 @@ public boolean isItemExists(int id, int size) { public Item bestSellingProduct() { int i, max = 0; - Item temp = new Shirt(); + Item temp = null; ArrayList items = new ArrayList<>(); try { items = StoreModel.getInstance().getItems(); diff --git a/src/view/ViewFunc.java b/src/view/ViewFunc.java index 8a29d9d..45ec1cf 100644 --- a/src/view/ViewFunc.java +++ b/src/view/ViewFunc.java @@ -1,10 +1,10 @@ package view; +import controller.*; import model.entities.*; -import java.util.*; -import controller.*; -import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; public class ViewFunc{ private AutoFuncController autoFuncController; @@ -59,7 +59,7 @@ public void searchItem() { System.out.println("enter the size: "); size = s.nextInt(); Item item = itemController.searchItem(id, size); - if(!itemController.isItemExists(id,size)) + if(item == null) System.out.println("the product does not exist"); else if (item.getItemId()<0) System.out.println("the product doesn't in stock!"); @@ -136,15 +136,15 @@ public void selling(){ int id = s.nextInt(); System.out.println("enter it's size"); int size = s.nextInt(); - if(!itemController.isItemExists(id,size)) - { + Item item = itemController.searchItem(id, size); + if(item != null) { + items.add(item); + items.get(i).setItemId(id); + price += item.getPrice(); + } else { System.out.println("item:" +id+" is not exist!"); return; } - Item item = itemController.searchItem(id, size); - items.add(item); - items.get(i).setItemId(id); - price += item.getPrice(); } System.out.println("enter member id:"); int memId = s.nextInt(); @@ -213,30 +213,33 @@ public void averageSellingRate() { public void bestSellingProduct() { System.out.println("the best selling product is:"); Item item = itemController.bestSellingProduct(); - System.out.println("the id:"+item.getItemId()); - System.out.println("the color:"+item.getColor()); - System.out.println("the brand:"+item.getBrand()); - System.out.println("the gender:"+item.getGender()); - System.out.println("the type:"+item.getType()); - System.out.println("the price:"+item.getPrice()); - System.out.println("the size:"+item.getSize()); - System.out.println("current Stock:"+item.getCurrentStock()); - System.out.println("base Stock:"+item.getBaseStock()); - switch (item.getType()) { - case "shirt": - Shirt shirt = (Shirt) item; - System.out.println("shirt Type:" + shirt.getShirtType()); - break; - case "pants": - Pants pants = (Pants) item; - System.out.println("pants Type:" + pants.getPantsType()); - break; - case "shoe": - Shoe shoe = (Shoe) item; - System.out.println("drawstring Color:" + shoe.getDrawstringColor()); - break; + if(item != null) { + System.out.println("the id:" + item.getItemId()); + System.out.println("the color:" + item.getColor()); + System.out.println("the brand:" + item.getBrand()); + System.out.println("the gender:" + item.getGender()); + System.out.println("the type:" + item.getType()); + System.out.println("the price:" + item.getPrice()); + System.out.println("the size:" + item.getSize()); + System.out.println("current Stock:" + item.getCurrentStock()); + System.out.println("base Stock:" + item.getBaseStock()); + switch (item.getType()) { + case "shirt": + Shirt shirt = (Shirt) item; + System.out.println("shirt Type:" + shirt.getShirtType()); + break; + case "pants": + Pants pants = (Pants) item; + System.out.println("pants Type:" + pants.getPantsType()); + break; + case "shoe": + Shoe shoe = (Shoe) item; + System.out.println("drawstring Color:" + shoe.getDrawstringColor()); + break; + } + } else { + System.out.println("there is no best selling item"); } - } public void addItem(){ diff --git a/tests/itemControllerTests/BestSellingProductTest.java b/tests/itemControllerTests/BestSellingProductTest.java index 87e4a3f..bfc1250 100644 --- a/tests/itemControllerTests/BestSellingProductTest.java +++ b/tests/itemControllerTests/BestSellingProductTest.java @@ -1,4 +1,18 @@ package itemControllerTests; +import controller.ItemController; +import org.junit.jupiter.api.BeforeEach; + + + + + public class BestSellingProductTest { + ItemController itemController; + + + @BeforeEach + public void setUp() {itemController = new ItemController();} + + } diff --git a/tests/itemControllerTests/SearchItemTest.java b/tests/itemControllerTests/SearchItemTest.java index 6fe2d22..63cde26 100644 --- a/tests/itemControllerTests/SearchItemTest.java +++ b/tests/itemControllerTests/SearchItemTest.java @@ -1,4 +1,62 @@ package itemControllerTests; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SearchItemTest { + ItemController itemController; + private final static int MOCK_NEGATIVE = -1; + private final static int MOCK_ZERO = 0; + private final static int MOCK_POSITIVE = 1; + private final static int MOCK_ID_EXIST = 2; + private final static int MOCK_ID_NOT_EXIST = 200000; + + + private final static int MOCK_SIZE_EXIST = 40; + + @BeforeEach + public void setUp() + { + itemController = new ItemController(); + } + + @Test + public void failIdTest() { + try { + itemController.searchItem(MOCK_NEGATIVE,MOCK_SIZE_EXIST); + fail("The search succeed when should failed"); + } catch (IllegalArgumentException e) { + Assertions.assertEquals("id must be positive", e.getMessage()); + + } + + } + + @Test + public void failSizeTest() { + try { + itemController.searchItem(MOCK_ID_EXIST,MOCK_NEGATIVE); + fail("The search succeed when should failed"); + } catch (IllegalArgumentException e) { + Assertions.assertEquals("size must be positive", e.getMessage()); + + } + + } + + @Test + public void SearchItemFoundedTest() + { + Item item = itemController.searchItem(MOCK_ID_EXIST,MOCK_SIZE_EXIST); + assertTrue(item.getItemId() == MOCK_ID_EXIST); + assertTrue(item.getSize() == MOCK_SIZE_EXIST); + + } + + @Test + public void SearchItemNotFoundSucceedTest() + { + Item item = itemController.searchItem(MOCK_ID_NOT_EXIST_EXIST,MOCK_SIZE_EXIST); + assertTrue(item == null); + } } From 4bd9214851626af769f1ed88ddaad456b5d37a9e Mon Sep 17 00:00:00 2001 From: orshmar18 Date: Mon, 15 Jun 2020 23:20:48 +0300 Subject: [PATCH 25/48] fix tests --- tests/itemControllerTests/SearchItemTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/itemControllerTests/SearchItemTest.java b/tests/itemControllerTests/SearchItemTest.java index 63cde26..addaab8 100644 --- a/tests/itemControllerTests/SearchItemTest.java +++ b/tests/itemControllerTests/SearchItemTest.java @@ -26,7 +26,7 @@ public void failIdTest() { itemController.searchItem(MOCK_NEGATIVE,MOCK_SIZE_EXIST); fail("The search succeed when should failed"); } catch (IllegalArgumentException e) { - Assertions.assertEquals("id must be positive", e.getMessage()); + Assertions.assertEquals("id or size must be a positive number", e.getMessage()); } @@ -38,7 +38,7 @@ public void failSizeTest() { itemController.searchItem(MOCK_ID_EXIST,MOCK_NEGATIVE); fail("The search succeed when should failed"); } catch (IllegalArgumentException e) { - Assertions.assertEquals("size must be positive", e.getMessage()); + Assertions.assertEquals("id or size must be a positive number", e.getMessage()); } @@ -48,8 +48,9 @@ public void failSizeTest() { public void SearchItemFoundedTest() { Item item = itemController.searchItem(MOCK_ID_EXIST,MOCK_SIZE_EXIST); - assertTrue(item.getItemId() == MOCK_ID_EXIST); - assertTrue(item.getSize() == MOCK_SIZE_EXIST); + Assertions.assertNotNull(item); + Assertions.assertEquals(item.getItemId(), MOCK_ID_EXIST); + Assertions.assertEquals(item.getSize(), MOCK_SIZE_EXIST); } @@ -57,6 +58,6 @@ public void SearchItemFoundedTest() public void SearchItemNotFoundSucceedTest() { Item item = itemController.searchItem(MOCK_ID_NOT_EXIST_EXIST,MOCK_SIZE_EXIST); - assertTrue(item == null); + Assertions.assertNull(item == null); } } From 5f44d65af4ddbd61ff03428ab530f8019e2efc5c Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Tue, 16 Jun 2020 12:24:44 +0300 Subject: [PATCH 26/48] new --- src/model/ItemModel.java | 6 +++--- src/model/ManagerModel.java | 2 +- src/model/MemberModel.java | 6 +++--- src/model/PurchaseModel.java | 4 ++-- src/model/StoreModel.java | 8 ++++---- src/model/WorkerModel.java | 2 +- tests/itemControllerTests/SearchItemTest.java | 8 +++++--- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/model/ItemModel.java b/src/model/ItemModel.java index 95fd2cb..2478500 100644 --- a/src/model/ItemModel.java +++ b/src/model/ItemModel.java @@ -79,7 +79,7 @@ public boolean addPants(Pants pants) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?);"; @@ -132,7 +132,7 @@ public boolean addShoe(Shoe shoe) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; @@ -183,7 +183,7 @@ public boolean addShirt(Shirt shirt) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO items" + " (itemid, color, price, type, size, brand, gender, drawstringcolor, pantstype, shirtstype, basestock, currentStock) VALUES " + " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; diff --git a/src/model/ManagerModel.java b/src/model/ManagerModel.java index 8dc410a..98f8972 100644 --- a/src/model/ManagerModel.java +++ b/src/model/ManagerModel.java @@ -13,7 +13,7 @@ public boolean changeHourlySalary(int workerId, int newSalary) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement stmt = connection.createStatement(); String strUpdate = "update workers set hourlysalary = " + newSalary + " where id =" + workerId; diff --git a/src/model/MemberModel.java b/src/model/MemberModel.java index 5e792af..fb950bd 100644 --- a/src/model/MemberModel.java +++ b/src/model/MemberModel.java @@ -24,7 +24,7 @@ public boolean addClubMember(Member m) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO clubmembers" + " (name, id, dateofbirth, pointgained) VALUES " + " (?, ?, ?, ?);"; @@ -62,7 +62,7 @@ public boolean deleteClubMember(int id) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement statement = connection.createStatement(); statement.executeUpdate(DELETE_USERS_SQL); return true; @@ -140,7 +140,7 @@ public void updateMembersPoints(int price, Member m) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement stmt = connection.createStatement(); String strUpdate = "update clubmembers set pointgained = pointgained +" + price + " where id =" + m.getId(); diff --git a/src/model/PurchaseModel.java b/src/model/PurchaseModel.java index b1243ff..4c78ec5 100644 --- a/src/model/PurchaseModel.java +++ b/src/model/PurchaseModel.java @@ -62,7 +62,7 @@ public int selling(Purchase pur) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); Statement stmt = connection.createStatement(); for(i=0;i getAllPurchase() { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -148,7 +148,7 @@ public static ArrayList getClubMembers() { ClubMembers = new ArrayList(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -190,7 +190,7 @@ public static ArrayList getItems() { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); @@ -250,7 +250,7 @@ public static ArrayList getWorkers() { Workers = new ArrayList<>(); Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); // Step 2:Create a statement using connection object Statement stmt = connection.createStatement(); diff --git a/src/model/WorkerModel.java b/src/model/WorkerModel.java index 9794c51..62fafaa 100644 --- a/src/model/WorkerModel.java +++ b/src/model/WorkerModel.java @@ -15,7 +15,7 @@ public boolean addWorker(Worker w) { Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "ProjectClothingStore"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); String INSERT_USERS_SQL = "INSERT INTO workers" + " (name, id, dateofbirth, hourlysalary, numHourMonth, jobType, password) VALUES " + " (?, ?, ?, ?, ?, ?, ?);"; diff --git a/tests/itemControllerTests/SearchItemTest.java b/tests/itemControllerTests/SearchItemTest.java index addaab8..bfa621f 100644 --- a/tests/itemControllerTests/SearchItemTest.java +++ b/tests/itemControllerTests/SearchItemTest.java @@ -2,6 +2,10 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import controller.ItemController; +import model.entities.*; + +import static org.junit.jupiter.api.Assertions.fail; public class SearchItemTest { ItemController itemController; @@ -39,9 +43,7 @@ public void failSizeTest() { fail("The search succeed when should failed"); } catch (IllegalArgumentException e) { Assertions.assertEquals("id or size must be a positive number", e.getMessage()); - } - } @Test @@ -57,7 +59,7 @@ public void SearchItemFoundedTest() @Test public void SearchItemNotFoundSucceedTest() { - Item item = itemController.searchItem(MOCK_ID_NOT_EXIST_EXIST,MOCK_SIZE_EXIST); + Item item = itemController.searchItem(MOCK_ID_NOT_EXIST,MOCK_SIZE_EXIST); Assertions.assertNull(item == null); } } From 657316d3202eb59b6acb359512406f752ee0a738 Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Tue, 16 Jun 2020 12:55:56 +0300 Subject: [PATCH 27/48] Update ViewFunc.java --- src/view/ViewFunc.java | 85 ++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/src/view/ViewFunc.java b/src/view/ViewFunc.java index e2e827c..d3233a0 100644 --- a/src/view/ViewFunc.java +++ b/src/view/ViewFunc.java @@ -1,10 +1,10 @@ package view; -import controller.*; import model.entities.*; -import java.util.ArrayList; -import java.util.Scanner; +import java.util.*; +import controller.*; +import java.io.IOException; public class ViewFunc{ private AutoFuncController autoFuncController; @@ -63,7 +63,7 @@ public void searchItem() { System.out.println("enter the size: "); size = s.nextInt(); Item item = itemController.searchItem(id, size); - if(item == null) + if(!itemController.isItemExists(id,size)) System.out.println("the product does not exist"); else if (item.getItemId()<0) System.out.println("the product doesn't in stock!"); @@ -144,15 +144,15 @@ public void selling(){ int id = s.nextInt(); System.out.println("enter it's size"); int size = s.nextInt(); - Item item = itemController.searchItem(id, size); - if(item != null) { - items.add(item); - items.get(i).setItemId(id); - price += item.getPrice(); - } else { + if(!itemController.isItemExists(id,size)) + { System.out.println("item:" +id+" is not exist!"); return; } + Item item = itemController.searchItem(id, size); + items.add(item); + items.get(i).setItemId(id); + price += item.getPrice(); } System.out.println("enter member id:"); int memId = s.nextInt(); @@ -236,33 +236,30 @@ public void averageSellingRate() { public void bestSellingProduct() { System.out.println("the best selling product is:"); Item item = itemController.bestSellingProduct(); - if(item != null) { - System.out.println("the id:" + item.getItemId()); - System.out.println("the color:" + item.getColor()); - System.out.println("the brand:" + item.getBrand()); - System.out.println("the gender:" + item.getGender()); - System.out.println("the type:" + item.getType()); - System.out.println("the price:" + item.getPrice()); - System.out.println("the size:" + item.getSize()); - System.out.println("current Stock:" + item.getCurrentStock()); - System.out.println("base Stock:" + item.getBaseStock()); - switch (item.getType()) { - case "shirt": - Shirt shirt = (Shirt) item; - System.out.println("shirt Type:" + shirt.getShirtType()); - break; - case "pants": - Pants pants = (Pants) item; - System.out.println("pants Type:" + pants.getPantsType()); - break; - case "shoe": - Shoe shoe = (Shoe) item; - System.out.println("drawstring Color:" + shoe.getDrawstringColor()); - break; - } - } else { - System.out.println("there is no best selling item"); + System.out.println("the id:"+item.getItemId()); + System.out.println("the color:"+item.getColor()); + System.out.println("the brand:"+item.getBrand()); + System.out.println("the gender:"+item.getGender()); + System.out.println("the type:"+item.getType()); + System.out.println("the price:"+item.getPrice()); + System.out.println("the size:"+item.getSize()); + System.out.println("current Stock:"+item.getCurrentStock()); + System.out.println("base Stock:"+item.getBaseStock()); + switch (item.getType()) { + case "shirt": + Shirt shirt = (Shirt) item; + System.out.println("shirt Type:" + shirt.getShirtType()); + break; + case "pants": + Pants pants = (Pants) item; + System.out.println("pants Type:" + pants.getPantsType()); + break; + case "shoe": + Shoe shoe = (Shoe) item; + System.out.println("drawstring Color:" + shoe.getDrawstringColor()); + break; } + } public void addItem(){ @@ -353,4 +350,20 @@ public void addWorker(){ } } + public void runCheckCurrentStock() { + TimerTask task = new TimerTask() { + @Override + public void run() { + ArrayList itemsLow = new ArrayList(); + itemsLow = autoFuncController.checkCurrentStock(); + System.out.println(itemsLow.toString()); + + } + }; + + Timer timer = new Timer(); + timer.schedule(task, new Date(), 300000); + + } + } From 225ba91fb2c6e3107443e814124dcc68eeae4111 Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Tue, 16 Jun 2020 12:56:38 +0300 Subject: [PATCH 28/48] Update UserInterface.java --- src/view/UserInterface.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/view/UserInterface.java b/src/view/UserInterface.java index 29294f1..769699d 100644 --- a/src/view/UserInterface.java +++ b/src/view/UserInterface.java @@ -42,7 +42,7 @@ public void run() { public void workerScreen() { - viewFunc.autoFunc(); + viewFunc.runCheckCurrentStock(); viewFunc.birthDayAuto(); Scanner s = new Scanner(System.in); while(true) { @@ -90,7 +90,7 @@ public void workerScreen() public void managerScreen() { - viewFunc.autoFunc(); + viewFunc.runCheckCurrentStock(); viewFunc.birthDayAuto(); Scanner s = new Scanner(System.in); while(true) { @@ -155,4 +155,4 @@ public void managerScreen() } } -} \ No newline at end of file +} From 3174597f1a0ff76c028d6adedb7350941ed06d01 Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Tue, 16 Jun 2020 12:57:04 +0300 Subject: [PATCH 29/48] Update AutoFuncModel.java --- src/model/AutoFuncModel.java | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/model/AutoFuncModel.java b/src/model/AutoFuncModel.java index 7dc8901..ab987e7 100644 --- a/src/model/AutoFuncModel.java +++ b/src/model/AutoFuncModel.java @@ -12,35 +12,23 @@ public class AutoFuncModel { - public void checkCurrentStock() { + public ArrayList checkCurrentStock() { int i; double presentOfCurrentStock = 0.2; - // ArrayList itemsLow = new ArrayList(); + ArrayList itemsLow = new ArrayList(); ArrayList items = new ArrayList(); try { items = StoreModel.getInstance().getItems(); for (i = 0; i < items.size(); i++) { if (((double) items.get(i).getCurrentStock() / items.get(i).getBaseStock()) < presentOfCurrentStock) { - // items.add(items.get(i)); - System.out.println("System Message: stock is low. " + "item id:" + items.get(i).getItemId()); + String s=String.valueOf(items.get(i).getItemId()); + itemsLow.add("System Message: stock is low. " + "item id:" + s); } } } catch (Exception e) { e.printStackTrace(); } - //return itemsLow; + return itemsLow; } - public void runCheckCurrentStock() { - TimerTask task = new TimerTask() { - @Override - public void run() { - checkCurrentStock(); - } - }; - - Timer timer = new Timer(); - timer.schedule(task, new Date(), 300000); - - } } From ce850bd66681dc054fa412e06f55601efcf3c49f Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Tue, 16 Jun 2020 12:57:27 +0300 Subject: [PATCH 30/48] Update AutoFuncController.java --- src/controller/AutoFuncController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controller/AutoFuncController.java b/src/controller/AutoFuncController.java index 79a146c..f17897e 100644 --- a/src/controller/AutoFuncController.java +++ b/src/controller/AutoFuncController.java @@ -14,9 +14,9 @@ public AutoFuncController() { this.model = new AutoFuncModel(); } - public void checkCurrentStock() + public ArrayList checkCurrentStock() { - model.runCheckCurrentStock(); + return model.checkCurrentStock(); } } From b19f9e29da1a8f7664924ed1ca22c101fd5d9b7d Mon Sep 17 00:00:00 2001 From: orshmar18 Date: Tue, 16 Jun 2020 15:09:41 +0300 Subject: [PATCH 31/48] fix BestSellingProductTest(try) --- .../BestSellingProductTest.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/itemControllerTests/BestSellingProductTest.java b/tests/itemControllerTests/BestSellingProductTest.java index bfc1250..9fe7e2c 100644 --- a/tests/itemControllerTests/BestSellingProductTest.java +++ b/tests/itemControllerTests/BestSellingProductTest.java @@ -1,18 +1,28 @@ package itemControllerTests; - import controller.ItemController; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; - - - +import org.junit.jupiter.api.Test; public class BestSellingProductTest { ItemController itemController; - @BeforeEach public void setUp() {itemController = new ItemController();} + @Test + public void BestSellingProductFoundedTest() + { + Item item = itemController.bestSellingProduct(); + Assertions.assertNotNull(item); + } + + @Test + public void BestSellingProductNotFoundSucceedTest() + { + Item item = itemController.bestSellingProduct(); + Assertions.assertNull(item == null); + } } From 989eff4880ef1d3debc3dcc394259b3c3e7b5177 Mon Sep 17 00:00:00 2001 From: orshmar18 Date: Tue, 16 Jun 2020 15:42:31 +0300 Subject: [PATCH 32/48] fix BestSellingProductTest(try)2 --- tests/itemControllerTests/BestSellingProductTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/itemControllerTests/BestSellingProductTest.java b/tests/itemControllerTests/BestSellingProductTest.java index 9fe7e2c..46d8ddb 100644 --- a/tests/itemControllerTests/BestSellingProductTest.java +++ b/tests/itemControllerTests/BestSellingProductTest.java @@ -10,7 +10,7 @@ public class BestSellingProductTest { @BeforeEach public void setUp() {itemController = new ItemController();} - +//cxvds,vsfvkmsdkc @Test public void BestSellingProductFoundedTest() { From 5cc58bd1b204bc2f79374eaef4291e688f0dc6b4 Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Wed, 1 Jul 2020 22:13:37 +0300 Subject: [PATCH 33/48] Update BestSellingProductTest.java --- tests/itemControllerTests/BestSellingProductTest.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/itemControllerTests/BestSellingProductTest.java b/tests/itemControllerTests/BestSellingProductTest.java index 46d8ddb..d5e9a43 100644 --- a/tests/itemControllerTests/BestSellingProductTest.java +++ b/tests/itemControllerTests/BestSellingProductTest.java @@ -1,5 +1,6 @@ package itemControllerTests; import controller.ItemController; +import model.entities.Item; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,7 +11,7 @@ public class BestSellingProductTest { @BeforeEach public void setUp() {itemController = new ItemController();} -//cxvds,vsfvkmsdkc + @Test public void BestSellingProductFoundedTest() { @@ -18,11 +19,7 @@ public void BestSellingProductFoundedTest() Assertions.assertNotNull(item); } - @Test - public void BestSellingProductNotFoundSucceedTest() - { - Item item = itemController.bestSellingProduct(); - Assertions.assertNull(item == null); - } + + } From 8752165c1c464291aaca65fa318874024919119a Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Wed, 1 Jul 2020 22:14:07 +0300 Subject: [PATCH 34/48] Update SearchItemTest.java --- tests/itemControllerTests/SearchItemTest.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/itemControllerTests/SearchItemTest.java b/tests/itemControllerTests/SearchItemTest.java index bfa621f..290c046 100644 --- a/tests/itemControllerTests/SearchItemTest.java +++ b/tests/itemControllerTests/SearchItemTest.java @@ -14,8 +14,6 @@ public class SearchItemTest { private final static int MOCK_POSITIVE = 1; private final static int MOCK_ID_EXIST = 2; private final static int MOCK_ID_NOT_EXIST = 200000; - - private final static int MOCK_SIZE_EXIST = 40; @BeforeEach @@ -30,7 +28,7 @@ public void failIdTest() { itemController.searchItem(MOCK_NEGATIVE,MOCK_SIZE_EXIST); fail("The search succeed when should failed"); } catch (IllegalArgumentException e) { - Assertions.assertEquals("id or size must be a positive number", e.getMessage()); + Assertions.assertEquals("id or size must not be negative", e.getMessage()); } @@ -42,7 +40,7 @@ public void failSizeTest() { itemController.searchItem(MOCK_ID_EXIST,MOCK_NEGATIVE); fail("The search succeed when should failed"); } catch (IllegalArgumentException e) { - Assertions.assertEquals("id or size must be a positive number", e.getMessage()); + Assertions.assertEquals("id or size must not be negative", e.getMessage()); } } @@ -51,15 +49,14 @@ public void SearchItemFoundedTest() { Item item = itemController.searchItem(MOCK_ID_EXIST,MOCK_SIZE_EXIST); Assertions.assertNotNull(item); - Assertions.assertEquals(item.getItemId(), MOCK_ID_EXIST); - Assertions.assertEquals(item.getSize(), MOCK_SIZE_EXIST); - } + + @Test public void SearchItemNotFoundSucceedTest() { - Item item = itemController.searchItem(MOCK_ID_NOT_EXIST,MOCK_SIZE_EXIST); - Assertions.assertNull(item == null); + Item item = itemController.searchItem(MOCK_ID_NOT_EXIST,MOCK_ID_NOT_EXIST); + Assertions.assertNull(item); } } From 512e0d8f6bd886a71f93cfaf805eed5db5cfe0b6 Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Wed, 1 Jul 2020 22:15:26 +0300 Subject: [PATCH 35/48] Update ItemModel.java --- src/model/ItemModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/model/ItemModel.java b/src/model/ItemModel.java index 2478500..c0a9285 100644 --- a/src/model/ItemModel.java +++ b/src/model/ItemModel.java @@ -11,9 +11,9 @@ public class ItemModel { public Item searchItem(int id, int size) { - if(id <= 0 || size <= 0) + if (id < 0 || size < 0) { - throw new IllegalArgumentException("id or size must be a positive number"); + throw new IllegalArgumentException("id or size must not be negative"); } int i; From f8f79a8a56a96997eda9924122c34934c50454c5 Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Thu, 2 Jul 2020 16:32:17 +0300 Subject: [PATCH 36/48] new class --- src/view/UserInterface.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/view/UserInterface.java b/src/view/UserInterface.java index 769699d..93da96f 100644 --- a/src/view/UserInterface.java +++ b/src/view/UserInterface.java @@ -32,7 +32,7 @@ public void run() { System.out.println("the program closes"); return; } - System.out.println("username or password are - try again!"); + System.out.println("username or password are not correct - try again!"); System.out.println("mistake number "+i+"/3"); i++; } From fafb0ec5c622922517b7f489daf460fd9ecfd7bb Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Mon, 6 Jul 2020 22:41:15 +0300 Subject: [PATCH 37/48] changed the tests --- src/controller/ItemController.java | 5 ++++ src/model/ItemModel.java | 25 ++++++++++++++++--- src/model/MemberModel.java | 24 +++++++++--------- tests/itemControllerTests/AddPantsTest.java | 2 +- tests/itemControllerTests/AddShirtTest.java | 3 +-- tests/itemControllerTests/AddShoeTest.java | 3 +-- .../AddClubMemberTest.java | 6 ++--- .../purchaseControllerTests/SellingTest.java | 6 +---- 8 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/controller/ItemController.java b/src/controller/ItemController.java index a4ac404..62863d2 100644 --- a/src/controller/ItemController.java +++ b/src/controller/ItemController.java @@ -34,4 +34,9 @@ public boolean addShirt(Shirt shirt) { return model.addShirt(shirt); } + public boolean deleteItem(int id, int size) + { + return model.deleteItem(id,size); + } + } diff --git a/src/model/ItemModel.java b/src/model/ItemModel.java index c0a9285..5166373 100644 --- a/src/model/ItemModel.java +++ b/src/model/ItemModel.java @@ -2,10 +2,7 @@ import model.entities.*; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.SQLException; +import java.sql.*; import java.util.ArrayList; public class ItemModel { @@ -222,5 +219,25 @@ public boolean addShirt(Shirt shirt) { return false; } + public boolean deleteItem(int id, int size) { + Connection connection = null; + String idNumber = String.valueOf(id); + String sizeNumber = String.valueOf(size); + String DELETE_USERS_SQL = "delete from items where itemid = " + idNumber + " and size = "+ sizeNumber+ ";"; + if (isItemExists(id,size) == true) { + try { + + Class.forName("com.mysql.jdbc.Driver").newInstance(); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + Statement statement = connection.createStatement(); + statement.executeUpdate(DELETE_USERS_SQL); + return true; + } catch (Exception e) { + e.printStackTrace(); + } + } + return false; + } + } diff --git a/src/model/MemberModel.java b/src/model/MemberModel.java index fb950bd..99b5a03 100644 --- a/src/model/MemberModel.java +++ b/src/model/MemberModel.java @@ -56,22 +56,22 @@ public boolean addClubMember(Member m) { public boolean deleteClubMember(int id) { Connection connection = null; - String idNumber = String.valueOf(id); - String DELETE_USERS_SQL = "delete from clubmembers where id = " + idNumber + ";"; + String idNumber = String.valueOf(id); + String DELETE_USERS_SQL = "delete from clubmembers where id = " + idNumber + ";"; if (isExistsClubMember(id) == true) { - try { + try { - Class.forName("com.mysql.jdbc.Driver").newInstance(); - connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); - Statement statement = connection.createStatement(); - statement.executeUpdate(DELETE_USERS_SQL); - return true; - } catch (Exception e) { - e.printStackTrace(); - } + Class.forName("com.mysql.jdbc.Driver").newInstance(); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "root", "6560634i"); + Statement statement = connection.createStatement(); + statement.executeUpdate(DELETE_USERS_SQL); + return true; + } catch (Exception e) { + e.printStackTrace(); } - return false; } + return false; +} public boolean isExistsClubMember(int id) { int i; diff --git a/tests/itemControllerTests/AddPantsTest.java b/tests/itemControllerTests/AddPantsTest.java index 2de8fd5..0626b58 100644 --- a/tests/itemControllerTests/AddPantsTest.java +++ b/tests/itemControllerTests/AddPantsTest.java @@ -37,7 +37,6 @@ public void failIdTest() { Assertions.assertEquals("id or size must not be negative", e.getMessage()); } - } @Test @@ -74,5 +73,6 @@ public void failAddPantsSucceedTest() Pants i = new Pants("blue", "niki", "men", "pants", 200, MOCK_SIZE_NOT_EXIST, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); boolean a = itemController.addPants(i); assertTrue(a); + itemController.deleteItem(MOCK_ID_NOT_EXIST,MOCK_SIZE_NOT_EXIST); } } diff --git a/tests/itemControllerTests/AddShirtTest.java b/tests/itemControllerTests/AddShirtTest.java index a575b14..2957a95 100644 --- a/tests/itemControllerTests/AddShirtTest.java +++ b/tests/itemControllerTests/AddShirtTest.java @@ -67,14 +67,13 @@ public void failAddPantsTest() { } - - @Test public void failAddShirtSucceedTest() { Shirt i = new Shirt("blue", "niki", "men", "pants", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); boolean a = itemController.addShirt(i); assertTrue(a); + itemController.deleteItem(MOCK_ID_NOT_EXIST,MOCK_POSITIVE); } } diff --git a/tests/itemControllerTests/AddShoeTest.java b/tests/itemControllerTests/AddShoeTest.java index eba900f..0ffed0f 100644 --- a/tests/itemControllerTests/AddShoeTest.java +++ b/tests/itemControllerTests/AddShoeTest.java @@ -69,14 +69,13 @@ public void failAddPantsTest() { } - - @Test public void failAddShirtSucceedTest() { Shoe i = new Shoe("blue", "niki", "men", "pants", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); boolean a = itemController.addShoe(i); assertTrue(a); + itemController.deleteItem(MOCK_ID_NOT_EXIST,MOCK_POSITIVE); } } diff --git a/tests/memberControllerTests/AddClubMemberTest.java b/tests/memberControllerTests/AddClubMemberTest.java index 003bf28..35f7058 100644 --- a/tests/memberControllerTests/AddClubMemberTest.java +++ b/tests/memberControllerTests/AddClubMemberTest.java @@ -113,12 +113,9 @@ public void failAddClubMemberTest() fail("The addition succeed when should failed"); } catch (IllegalArgumentException e) { - Assertions.assertEquals("the member is exist", e.getMessage()); + Assertions.assertEquals("the member is already exist", e.getMessage()); } - - - } @@ -127,6 +124,7 @@ public void failAddClubMemberSucceedTest() { boolean checkTrue = memberController.addClubMember(MOCK_MEMBER_NOT_EXIST); assertTrue(checkTrue); + memberController.deleteClubMember(MOCK_MEMBER_NOT_EXIST.getId()); } diff --git a/tests/purchaseControllerTests/SellingTest.java b/tests/purchaseControllerTests/SellingTest.java index 138d9c7..c9fd810 100644 --- a/tests/purchaseControllerTests/SellingTest.java +++ b/tests/purchaseControllerTests/SellingTest.java @@ -21,16 +21,12 @@ public class SellingTest { private final static int MOCK_ZERO = 0; private final static int MOCK_POSITIVE = 1; private final static int MOCK_ID_NOT_EXIST = 9999; - private final static String MOCK_NAME = "Yuval"; + private final static String MOCK_NAME = "yuval"; private final static String MOCK_DATEOFBIRTH = "31/3/1990"; private final static int MOCK_POINTSGAINED = 5550; private final static Member MOCK_EMPTY_MEMBER = new Member(); private final static Member MOCK_MEMBER = new Member(MOCK_NAME, MOCK_DATEOFBIRTH, MOCK_POSITIVE, MOCK_POINTSGAINED); -/* - - */ - @BeforeEach public void setUp() { From 06b00fbdaf4ef55dc322e2254dce9d43e7ae2d3f Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Mon, 6 Jul 2020 22:59:22 +0300 Subject: [PATCH 38/48] Update AddShirtTest.java --- tests/itemControllerTests/AddShirtTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/itemControllerTests/AddShirtTest.java b/tests/itemControllerTests/AddShirtTest.java index 2957a95..d541599 100644 --- a/tests/itemControllerTests/AddShirtTest.java +++ b/tests/itemControllerTests/AddShirtTest.java @@ -54,7 +54,7 @@ public void failSizeTest() { @Test - public void failAddPantsTest() { + public void failAddShirtTest() { try { Pants i = new Pants("blue", "niki", "men", "pants", 200, MOCK_SIZE_EXIST, 200, 500, MOCK_ID_EXIST, "bermuda"); itemController.addPants(i); @@ -67,13 +67,14 @@ public void failAddPantsTest() { } + + @Test public void failAddShirtSucceedTest() { Shirt i = new Shirt("blue", "niki", "men", "pants", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); boolean a = itemController.addShirt(i); assertTrue(a); - itemController.deleteItem(MOCK_ID_NOT_EXIST,MOCK_POSITIVE); } } From 5320272a66f79b7f9ef92d9fa843a2d3ea5a715a Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Mon, 6 Jul 2020 23:00:04 +0300 Subject: [PATCH 39/48] Update AddShoeTest.java --- tests/itemControllerTests/AddShoeTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/itemControllerTests/AddShoeTest.java b/tests/itemControllerTests/AddShoeTest.java index 0ffed0f..34dd031 100644 --- a/tests/itemControllerTests/AddShoeTest.java +++ b/tests/itemControllerTests/AddShoeTest.java @@ -56,7 +56,7 @@ public void failSizeTest() { @Test - public void failAddPantsTest() { + public void failAddShoeTest() { try { Pants i = new Pants("blue", "niki", "men", "pants", 200, MOCK_SIZE_EXIST, 200, 500, MOCK_ID_EXIST, "bermuda"); itemController.addPants(i); @@ -69,13 +69,14 @@ public void failAddPantsTest() { } + + @Test - public void failAddShirtSucceedTest() + public void failAddShoeSucceedTest() { Shoe i = new Shoe("blue", "niki", "men", "pants", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); boolean a = itemController.addShoe(i); assertTrue(a); - itemController.deleteItem(MOCK_ID_NOT_EXIST,MOCK_POSITIVE); } } From 176118cbed33dda38299ca4ef137644f41219a71 Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Mon, 6 Jul 2020 23:08:54 +0300 Subject: [PATCH 40/48] Update AddShirtTest.java --- tests/itemControllerTests/AddShirtTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/itemControllerTests/AddShirtTest.java b/tests/itemControllerTests/AddShirtTest.java index d541599..b40843c 100644 --- a/tests/itemControllerTests/AddShirtTest.java +++ b/tests/itemControllerTests/AddShirtTest.java @@ -1,7 +1,6 @@ package itemControllerTests; import controller.ItemController; -import model.entities.Pants; import model.entities.Shirt; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -29,7 +28,7 @@ public void setUp() @Test public void failIdTest() { try { - Shirt i = new Shirt("blue", "niki", "men", "pants", 200, MOCK_POSITIVE, 200, 500, MOCK_NEGATIVE, "lycra"); + Shirt i = new Shirt("blue", "niki", "men", "shirt", 200, MOCK_POSITIVE, 200, 500, MOCK_NEGATIVE, "lycra"); itemController.addShirt(i); fail("The addition succeed when should failed"); } catch (IllegalArgumentException e) { @@ -42,7 +41,7 @@ public void failIdTest() { @Test public void failSizeTest() { try { - Shirt i = new Shirt("blue", "niki", "men", "pants", 200, MOCK_NEGATIVE, 200, 500,MOCK_POSITIVE, "lycra"); + Shirt i = new Shirt("blue", "niki", "men", "shirt", 200, MOCK_NEGATIVE, 200, 500,MOCK_POSITIVE, "lycra"); itemController.addShirt(i); fail("The addition succeed when should failed"); } catch (IllegalArgumentException e) { @@ -56,8 +55,8 @@ public void failSizeTest() { @Test public void failAddShirtTest() { try { - Pants i = new Pants("blue", "niki", "men", "pants", 200, MOCK_SIZE_EXIST, 200, 500, MOCK_ID_EXIST, "bermuda"); - itemController.addPants(i); + Shirt i = new Shirt("blue", "niki", "men", "shirt", 200, MOCK_SIZE_EXIST, 200, 500, MOCK_ID_EXIST, "bermuda"); + itemController.addShirt(i); fail("The addition succeed when should failed"); } catch (IllegalArgumentException e) { Assertions.assertEquals("id and size exist", e.getMessage()); @@ -72,7 +71,7 @@ public void failAddShirtTest() { @Test public void failAddShirtSucceedTest() { - Shirt i = new Shirt("blue", "niki", "men", "pants", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); + Shirt i = new Shirt("blue", "niki", "men", "shirt", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); boolean a = itemController.addShirt(i); assertTrue(a); } From 423555a08c4a25a4eecb32ad1d0da9e2883d7af1 Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Mon, 6 Jul 2020 23:09:19 +0300 Subject: [PATCH 41/48] Update AddShoeTest.java --- tests/itemControllerTests/AddShoeTest.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/itemControllerTests/AddShoeTest.java b/tests/itemControllerTests/AddShoeTest.java index 34dd031..eeee1e3 100644 --- a/tests/itemControllerTests/AddShoeTest.java +++ b/tests/itemControllerTests/AddShoeTest.java @@ -1,8 +1,6 @@ package itemControllerTests; import controller.ItemController; -import model.entities.Pants; -import model.entities.Shirt; import model.entities.Shoe; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -29,7 +27,7 @@ public void setUp() @Test public void failIdTest() { try { - Shoe i = new Shoe("blue", "niki", "men", "pants", 200, MOCK_POSITIVE, 200, 500, MOCK_NEGATIVE, "lycra"); + Shoe i = new Shoe("blue", "niki", "men", "shoe", 200, MOCK_POSITIVE, 200, 500, MOCK_NEGATIVE, "lycra"); itemController.addShoe(i); fail("The addition succeed when should failed"); } catch (IllegalArgumentException e) { @@ -42,7 +40,7 @@ public void failIdTest() { @Test public void failSizeTest() { try { - Shoe i = new Shoe("blue", "niki", "men", "pants", 200, MOCK_NEGATIVE, 200, 500, MOCK_POSITIVE, "lycra"); + Shoe i = new Shoe("blue", "niki", "men", "shoe", 200, MOCK_NEGATIVE, 200, 500, MOCK_POSITIVE, "lycra"); itemController.addShoe(i); fail("The addition succeed when should failed"); } catch (IllegalArgumentException e) { @@ -58,8 +56,8 @@ public void failSizeTest() { @Test public void failAddShoeTest() { try { - Pants i = new Pants("blue", "niki", "men", "pants", 200, MOCK_SIZE_EXIST, 200, 500, MOCK_ID_EXIST, "bermuda"); - itemController.addPants(i); + Shoe i = new Shoe("blue", "niki", "men", "shoe", 200, MOCK_SIZE_EXIST, 200, 500, MOCK_ID_EXIST, "bermuda"); + itemController.addShoe(i); fail("The addition succeed when should failed"); } catch (IllegalArgumentException e) { Assertions.assertEquals("id and size exist", e.getMessage()); @@ -74,7 +72,7 @@ public void failAddShoeTest() { @Test public void failAddShoeSucceedTest() { - Shoe i = new Shoe("blue", "niki", "men", "pants", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); + Shoe i = new Shoe("blue", "niki", "men", "shoe", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); boolean a = itemController.addShoe(i); assertTrue(a); } From b72fd12a614c390538a39342bb76881c3f84c2dc Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Mon, 6 Jul 2020 23:12:03 +0300 Subject: [PATCH 42/48] Update AddShirtTest.java --- tests/itemControllerTests/AddShirtTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/itemControllerTests/AddShirtTest.java b/tests/itemControllerTests/AddShirtTest.java index b40843c..0a293b3 100644 --- a/tests/itemControllerTests/AddShirtTest.java +++ b/tests/itemControllerTests/AddShirtTest.java @@ -74,6 +74,7 @@ public void failAddShirtSucceedTest() Shirt i = new Shirt("blue", "niki", "men", "shirt", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); boolean a = itemController.addShirt(i); assertTrue(a); + itemController.deleteItem(MOCK_ID_NOT_EXIST,MOCK_SIZE_NOT_EXIST); } } From b75909f8a269a10a1298922f47a1ca167bebacc2 Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Mon, 6 Jul 2020 23:12:25 +0300 Subject: [PATCH 43/48] Update AddShoeTest.java --- tests/itemControllerTests/AddShoeTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/itemControllerTests/AddShoeTest.java b/tests/itemControllerTests/AddShoeTest.java index eeee1e3..e6365c4 100644 --- a/tests/itemControllerTests/AddShoeTest.java +++ b/tests/itemControllerTests/AddShoeTest.java @@ -75,6 +75,7 @@ public void failAddShoeSucceedTest() Shoe i = new Shoe("blue", "niki", "men", "shoe", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); boolean a = itemController.addShoe(i); assertTrue(a); + itemController.deleteItem(MOCK_ID_NOT_EXIST,MOCK_SIZE_NOT_EXIST); } } From 1e89345796e03b1f8c0098a8b7661e4b81eea6a9 Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Mon, 6 Jul 2020 23:15:45 +0300 Subject: [PATCH 44/48] Update AddShirtTest.java --- tests/itemControllerTests/AddShirtTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/itemControllerTests/AddShirtTest.java b/tests/itemControllerTests/AddShirtTest.java index 0a293b3..4598d81 100644 --- a/tests/itemControllerTests/AddShirtTest.java +++ b/tests/itemControllerTests/AddShirtTest.java @@ -74,7 +74,7 @@ public void failAddShirtSucceedTest() Shirt i = new Shirt("blue", "niki", "men", "shirt", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); boolean a = itemController.addShirt(i); assertTrue(a); - itemController.deleteItem(MOCK_ID_NOT_EXIST,MOCK_SIZE_NOT_EXIST); + itemController.deleteItem(MOCK_POSITIVE,MOCK_ID_NOT_EXIST); } } From 69317c78c4e7f2d7e9765c2b0e5bc9bdb2371e6c Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Mon, 6 Jul 2020 23:16:11 +0300 Subject: [PATCH 45/48] Update AddShoeTest.java --- tests/itemControllerTests/AddShoeTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/itemControllerTests/AddShoeTest.java b/tests/itemControllerTests/AddShoeTest.java index e6365c4..4442faf 100644 --- a/tests/itemControllerTests/AddShoeTest.java +++ b/tests/itemControllerTests/AddShoeTest.java @@ -75,7 +75,7 @@ public void failAddShoeSucceedTest() Shoe i = new Shoe("blue", "niki", "men", "shoe", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); boolean a = itemController.addShoe(i); assertTrue(a); - itemController.deleteItem(MOCK_ID_NOT_EXIST,MOCK_SIZE_NOT_EXIST); + itemController.deleteItem(MOCK_POSITIVE,MOCK_SIZE_NOT_EXIST); } } From 6459481bcb849d78e309decc6b3cb75aecce601f Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Mon, 6 Jul 2020 23:17:54 +0300 Subject: [PATCH 46/48] changed the tests --- tests/itemControllerTests/AddShoeTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/itemControllerTests/AddShoeTest.java b/tests/itemControllerTests/AddShoeTest.java index 4442faf..8d2c559 100644 --- a/tests/itemControllerTests/AddShoeTest.java +++ b/tests/itemControllerTests/AddShoeTest.java @@ -75,7 +75,7 @@ public void failAddShoeSucceedTest() Shoe i = new Shoe("blue", "niki", "men", "shoe", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); boolean a = itemController.addShoe(i); assertTrue(a); - itemController.deleteItem(MOCK_POSITIVE,MOCK_SIZE_NOT_EXIST); + itemController.deleteItem(MOCK_ID_NOT_EXIST,MOCK_POSITIVE); } } From b2b9d0164179e02245b44bb0f86d898ea4b71dc5 Mon Sep 17 00:00:00 2001 From: inbalmishal Date: Mon, 6 Jul 2020 23:31:10 +0300 Subject: [PATCH 47/48] changed the tests --- tests/itemControllerTests/AddShirtTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/itemControllerTests/AddShirtTest.java b/tests/itemControllerTests/AddShirtTest.java index 4598d81..b416d31 100644 --- a/tests/itemControllerTests/AddShirtTest.java +++ b/tests/itemControllerTests/AddShirtTest.java @@ -74,7 +74,7 @@ public void failAddShirtSucceedTest() Shirt i = new Shirt("blue", "niki", "men", "shirt", 200, MOCK_POSITIVE, 200, 500, MOCK_ID_NOT_EXIST, "bermuda"); boolean a = itemController.addShirt(i); assertTrue(a); - itemController.deleteItem(MOCK_POSITIVE,MOCK_ID_NOT_EXIST); + itemController.deleteItem(MOCK_ID_NOT_EXIST,MOCK_POSITIVE); } } From acd7f9a6364d0edabf8e7366272b4a71af1740b7 Mon Sep 17 00:00:00 2001 From: RafiAriel <65024803+RafiAriel@users.noreply.github.com> Date: Tue, 7 Jul 2020 18:44:22 +0300 Subject: [PATCH 48/48] Update AddClubMemberTest.java --- tests/memberControllerTests/AddClubMemberTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/memberControllerTests/AddClubMemberTest.java b/tests/memberControllerTests/AddClubMemberTest.java index 35f7058..9bef816 100644 --- a/tests/memberControllerTests/AddClubMemberTest.java +++ b/tests/memberControllerTests/AddClubMemberTest.java @@ -23,7 +23,7 @@ public class AddClubMemberTest { private final static Member MOCK_MEMBER_WITHOUTID = new Member(MOCK_NAME, MOCK_DATEOFBIRTH,MOCK_NEGATIVE, MOCK_POINTSGAINED); private final static Member MOCK_MEMBER_WITHOUTIDOTHER = new Member(MOCK_NAME, MOCK_DATEOFBIRTH,MOCK_ZERO, MOCK_POINTSGAINED); private final static Member MOCK_MEMBER_WITHOUTPOINTSGAINED = new Member(MOCK_NAME, MOCK_DATEOFBIRTH,MOCK_ZERO, MOCK_NEGATIVE); - private final static Member MOCK_MEMBER_EXIST = new Member("Yuval", "30/2/1999",1, 4534); + private final static Member MOCK_MEMBER_EXIST = new Member("test", "4/3/1990",9999, 1111); private final static Member MOCK_MEMBER_NOT_EXIST = new Member("Dani", "30/2/1999",49, 4534); @BeforeEach @@ -116,6 +116,9 @@ public void failAddClubMemberTest() Assertions.assertEquals("the member is already exist", e.getMessage()); } + + + } @@ -125,7 +128,6 @@ public void failAddClubMemberSucceedTest() boolean checkTrue = memberController.addClubMember(MOCK_MEMBER_NOT_EXIST); assertTrue(checkTrue); memberController.deleteClubMember(MOCK_MEMBER_NOT_EXIST.getId()); - }