diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..577b0f7e --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,9 @@ +# Default ignored files +/shelf/ +/workspace.xml +/vcs.xml +/uiDesigner.xml +/modules.xml +/modules.xml +/misc.xml +/KDTBE5_Java_ToyProject.iml \ No newline at end of file diff --git a/.idea/KDTBE5_Java_ToyProject.iml b/.idea/KDTBE5_Java_ToyProject.iml new file mode 100644 index 00000000..5890ca80 --- /dev/null +++ b/.idea/KDTBE5_Java_ToyProject.iml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..4458232f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..576cf688 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/me.smartstore/Main.java b/me.smartstore/Main.java new file mode 100644 index 00000000..1e809849 --- /dev/null +++ b/me.smartstore/Main.java @@ -0,0 +1,6 @@ + +public class Main { + public static void main(String[] args) { + SmartStoreApp.getInstance().test().run(); + } +} diff --git a/me.smartstore/SmartStoreApp.java b/me.smartstore/SmartStoreApp.java new file mode 100644 index 00000000..e1909877 --- /dev/null +++ b/me.smartstore/SmartStoreApp.java @@ -0,0 +1,63 @@ + +import customer.Customer; +import customer.Customers; +import group.Group; +import group.GroupType; +import group.Groups; +import group.Parameter; +import menu.*; + +public class SmartStoreApp { + private final Groups allGroups = Groups.getInstance(); + private final Customers allCustomers = Customers.getInstance(); + private final MainMenu mainMenu = MainMenu.getInstance(); + + // singleton + private static SmartStoreApp smartStoreApp; + + public static SmartStoreApp getInstance() { + if (smartStoreApp == null) { + smartStoreApp = new SmartStoreApp(); + } + return smartStoreApp; + } + + private SmartStoreApp() {} + + public void details() { + System.out.println("\n\n==========================================="); + System.out.println(" Title : SmartStore Customer Classification"); + System.out.println(" Release Date : 23.05.10"); + System.out.println(" Copyright 2023 Gyeongmin All rights reserved."); + System.out.println("===========================================\n"); + } + + public SmartStoreApp test() { + allGroups.add(new Group(new Parameter(10, 100000), GroupType.GENERAL)); + allGroups.add(new Group(new Parameter(20, 200000), GroupType.VIP)); + allGroups.add(new Group(new Parameter(30, 300000), GroupType.VVIP)); + + //고객 정보 + for (int i = 0; i < 26; i++) { + allCustomers.add(new Customer( + Character.toString( + (char) ('a' + i)), + (char) ('a' + i) + "123", + ((int) (Math.random() * 5) + 1) * 10, + ((int) (Math.random() * 5) + 1) * 100000)); + } + + System.out.println("allCustomers = " + allCustomers); + System.out.println("allGroups = " + allGroups); + + allCustomers.refresh(allGroups); + + return this; + } + + public void run() { + details(); + mainMenu.manage(); + + } +} \ No newline at end of file diff --git a/me.smartstore/arrays/Collections.java b/me.smartstore/arrays/Collections.java new file mode 100644 index 00000000..0b2c65bf --- /dev/null +++ b/me.smartstore/arrays/Collections.java @@ -0,0 +1,13 @@ +package arrays; + +public interface Collections { + int size(); + T get(int index); + void set(int index, T object); + int indexOf(T object); + void add(T object); + void add(int index, T object); + T pop(); + T pop(int index); + T pop(T object); +} \ No newline at end of file diff --git a/me.smartstore/arrays/DArray.java b/me.smartstore/arrays/DArray.java new file mode 100644 index 00000000..392fa8c0 --- /dev/null +++ b/me.smartstore/arrays/DArray.java @@ -0,0 +1,140 @@ +package arrays; + +import customer.Customer; +import exception.ElementNotFoundException; +import exception.EmptyArrayException; +import exception.NullArgumentException; + +public class DArray implements Collections { // Dynamic Array + + protected static final int DEFAULT = 10; + + protected T[] arrays; + protected int size; + protected int capacity; + + @SuppressWarnings("unchecked") + public DArray() { + arrays = (T[]) new Object[DEFAULT]; + capacity = DEFAULT; + } + + @SuppressWarnings("unchecked") + public DArray(int initial) { + arrays = (T[]) new Object[initial]; + capacity = initial; + } + + public DArray(T[] arrays) { + this.arrays = arrays; + capacity = arrays.length; + size = arrays.length; + } + + @Override + public int size() { + return size; + } + + protected int capacity() { + return capacity; + } + + @Override + public T get(int index) throws IndexOutOfBoundsException { + if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); + return arrays[index]; + } + + @Override + public void set(int index, T object) throws IndexOutOfBoundsException, NullArgumentException { + if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); + if (object == null) throw new NullArgumentException(); + + arrays[index] = object; + } + + @Override + public int indexOf(T object) throws NullArgumentException, ElementNotFoundException { + if (object == null) throw new NullArgumentException(); // not found (instead of throwing exception) + + for (int i = 0; i < size; i++) { + if (arrays[i] == null) continue; + if (arrays[i].equals(object)) return i; + } + throw new ElementNotFoundException(); // not found + } + + @Override + public void add(T object) throws NullArgumentException { + if (object == null) throw new NullArgumentException(); // if argument is null, do not add null value in array + + if (size < capacity) { + arrays[size] = object; + size++; + } else { + grow(); + add(object); + } + } + + @Override + public void add(int index, T object) throws IndexOutOfBoundsException, NullArgumentException { + if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); + if (object == null) throw new NullArgumentException(); + + if (size < capacity) { + for (int i = size-1; i >= index ; i--) { + arrays[i+1] = arrays[i]; + } + arrays[index] = object; + size++; + } else { + grow(); + add(index, object); + } + } + + @Override + public T pop() { + return pop(size-1); + } + + @Override + public T pop(int index) throws IndexOutOfBoundsException { + if (size == 0) throw new EmptyArrayException(); + if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); + + T popElement = arrays[index]; + arrays[index] = null; + + for (int i = index+1; i < size; i++) { + arrays[i-1] = arrays[i]; + } + arrays[size-1] = null; + size--; + return popElement; + } + + @Override + public T pop(T object) { + return pop(indexOf(object)); + } + + protected void grow() { + capacity *= 2; + arrays = java.util.Arrays.copyOf(arrays, capacity); + } + + @Override + public String toString() { + String toStr = ""; + for (int i = 0; i < size; i++) { + toStr += (arrays[i] + "\n"); + } + return toStr; + } + + public void remove(Customer customerToDelete) { + } +} \ No newline at end of file diff --git a/me.smartstore/customer/Customer.java b/me.smartstore/customer/Customer.java new file mode 100644 index 00000000..506da180 --- /dev/null +++ b/me.smartstore/customer/Customer.java @@ -0,0 +1,112 @@ +package customer; + +import group.Group; + +import java.util.Objects; + +public class Customer { + private String cusName; + private String cusId; + private int cusTotalTime; + private int cusTotalPay; + private Group group; + + public Customer() { + } + + public Customer(String cusId) { + this.cusId = cusId; + } + + public Customer(String cusName, String cusId) { + this.cusName = cusName; + this.cusId = cusId; + } + + public Customer(String cusName, String cusId, int cusTotalTime, int cusTotalPay) { + this.cusName = cusName; + this.cusId = cusId; + this.cusTotalTime = cusTotalTime; + this.cusTotalPay = cusTotalPay; + } + + public Customer(String cusName, String cusId, int cusTotalTime, int cusTotalPay, Group group) { + this.cusName = cusName; + this.cusId = cusId; + this.cusTotalTime = cusTotalTime; + this.cusTotalPay = cusTotalPay; + this.group = group; + } + + public String getCusName() { + return cusName; + } + + public void setCusName(String cusName) { + this.cusName = cusName; + } + + public String getCusId() { + return cusId; + } + + public void setCusId(String cusId) { + this.cusId = cusId; + } + + public int getCusTotalTime() { + return cusTotalTime; + } + + public void setCusTotalTime(int cusTotalTime) { + this.cusTotalTime = cusTotalTime; + } + + public int getCusTotalPay() { + return cusTotalPay; + } + + public void setCusTotalPay(int cusTotalPay) { + this.cusTotalPay = cusTotalPay; + } + + public Group getGroup() { + return group; + } + + public void setGroup(Group group) { + this.group = group; + } + + public void addPurchase(int pay) { + cusTotalPay += pay; + } + + public void addTime(int time) { + cusTotalTime += time; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Customer customer = (Customer) o; + return Objects.equals(cusId, customer.cusId); + } + + @Override + public int hashCode() { + return Objects.hash(cusId); + } + + @Override + public String toString() { + return "Customer{" + + "cusName='" + cusName + '\'' + + ", cusId='" + cusId + '\'' + + ", cusTotalTime=" + cusTotalTime + + ", cusTotalPay=" + cusTotalPay + + ", group=" + group + + '}'; + } +} diff --git a/me.smartstore/customer/Customers.java b/me.smartstore/customer/Customers.java new file mode 100644 index 00000000..0d8cb5c9 --- /dev/null +++ b/me.smartstore/customer/Customers.java @@ -0,0 +1,108 @@ +package customer; + +import group.Groups; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Customers { + private static Customers instance; + private final List customers; + private int minTotalTime; + private int minTotalPay; + private final Map customerGroup; // 추가된 필드 + + private Customers() { + customers = new ArrayList<>(); + customerGroup = new HashMap<>(); // 초기화 + } + + public static Customers getInstance() { + if (instance == null) { + instance = new Customers(); + } + return instance; + } + + public void add(Customer customer) { + customers.add(customer); + } + + public boolean remove(Customer customer) { + return customers.remove(customer); + } + + public List getList() { + return customers; + } + + public void setMinTotalTime(int minTotalTime) { + this.minTotalTime = minTotalTime; + } + + public void setMinTotalPay(int minTotalPay) { + this.minTotalPay = minTotalPay; + } + + public void groupCustomers() { + customerGroup.clear(); // 기존 분류 정보 초기화 + for (Customer customer : customers) { + if (customer.getCusTotalTime() >= minTotalTime && customer.getCusTotalPay() >= minTotalPay) { + customerGroup.put(customer, "VVIP"); + } else if (customer.getCusTotalTime() >= minTotalTime) { + customerGroup.put(customer, "VIP"); + } else { + customerGroup.put(customer, "General"); + } + } + } + + public void printGroupedCustomers() { + groupCustomers(); + for (String group : new String[]{"General", "VIP", "VVIP"}) { + System.out.println(group + " Customers:"); + for (Customer customer : customerGroup.keySet()) { + if (customerGroup.get(customer).equals(group)) { + System.out.println(customer); + } + } + System.out.println(); + } + } + + public void addPurchase(String name, int pay) { + for (Customer customer : customers) { + if (customer.getCusName().equals(name)) { + customer.addPurchase(pay); + return; + } + } + System.out.println("No such customer exists."); + } + + public void addTime(String name, int time) { + for (Customer customer : customers) { + if (customer.getCusName().equals(name)) { + customer.addTime(time); + return; + } + } + System.out.println("No such customer exists."); + } + + public void printAll() { + } + + public Customer find(String toLowerCase) { + return null; + } + + public void refresh(Groups allGroups) { + } + + public boolean isEmpty() { + return false; + } +} diff --git a/me.smartstore/exception/ArrayEmptyException.java b/me.smartstore/exception/ArrayEmptyException.java new file mode 100644 index 00000000..a649f689 --- /dev/null +++ b/me.smartstore/exception/ArrayEmptyException.java @@ -0,0 +1,14 @@ +package exception; + +import util.Message; + +public class ArrayEmptyException extends RuntimeException { + + public ArrayEmptyException() { + super(Message.ERR_MSG_INVALID_ARR_EMPTY); + } + + public ArrayEmptyException(String message) { + super(message); + } +} diff --git a/me.smartstore/exception/ElementNotFoundException.java b/me.smartstore/exception/ElementNotFoundException.java new file mode 100644 index 00000000..f163a3e8 --- /dev/null +++ b/me.smartstore/exception/ElementNotFoundException.java @@ -0,0 +1,22 @@ +package exception; + +public class ElementNotFoundException extends RuntimeException { + public ElementNotFoundException() { + } + + public ElementNotFoundException(String message) { + super(message); + } + + public ElementNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public ElementNotFoundException(Throwable cause) { + super(cause); + } + + public ElementNotFoundException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/me.smartstore/exception/EmptyArrayException.java b/me.smartstore/exception/EmptyArrayException.java new file mode 100644 index 00000000..4ece8b3b --- /dev/null +++ b/me.smartstore/exception/EmptyArrayException.java @@ -0,0 +1,22 @@ +package exception; + +public class EmptyArrayException extends RuntimeException { + public EmptyArrayException() { + } + + public EmptyArrayException(String message) { + super(message); + } + + public EmptyArrayException(String message, Throwable cause) { + super(message, cause); + } + + public EmptyArrayException(Throwable cause) { + super(cause); + } + + public EmptyArrayException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/me.smartstore/exception/InputEmptyException.java b/me.smartstore/exception/InputEmptyException.java new file mode 100644 index 00000000..2327adb2 --- /dev/null +++ b/me.smartstore/exception/InputEmptyException.java @@ -0,0 +1,15 @@ +package exception; + + +import util.Message; + +public class InputEmptyException extends RuntimeException { + + public InputEmptyException() { + super(Message.ERR_MSG_INVALID_INPUT_EMPTY); + } + + public InputEmptyException(String message) { + super(message); + } +} diff --git a/me.smartstore/exception/InputEndException.java b/me.smartstore/exception/InputEndException.java new file mode 100644 index 00000000..defe48fe --- /dev/null +++ b/me.smartstore/exception/InputEndException.java @@ -0,0 +1,13 @@ +package exception; + +import util.Message; + +public class InputEndException extends RuntimeException { + public InputEndException() { + super(Message.ERR_MSG_INPUT_END); + } + + public InputEndException(String message) { + super(message); + } +} diff --git a/me.smartstore/exception/InputFormatException.java b/me.smartstore/exception/InputFormatException.java new file mode 100644 index 00000000..c21e71f5 --- /dev/null +++ b/me.smartstore/exception/InputFormatException.java @@ -0,0 +1,13 @@ +package exception; + +import util.Message; + +public class InputFormatException extends RuntimeException { + public InputFormatException() { + super(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } + + public InputFormatException(String message) { + super(message); + } +} diff --git a/me.smartstore/exception/InputRangeException.java b/me.smartstore/exception/InputRangeException.java new file mode 100644 index 00000000..35b0f4ad --- /dev/null +++ b/me.smartstore/exception/InputRangeException.java @@ -0,0 +1,14 @@ +package exception; + + +import util.Message; + +public class InputRangeException extends RuntimeException { + public InputRangeException() { + super(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + + public InputRangeException(String message) { + super(message); + } +} diff --git a/me.smartstore/exception/InputTypeException.java b/me.smartstore/exception/InputTypeException.java new file mode 100644 index 00000000..58b6a149 --- /dev/null +++ b/me.smartstore/exception/InputTypeException.java @@ -0,0 +1,14 @@ +package exception; + + +import util.Message; + +public class InputTypeException extends RuntimeException { + public InputTypeException() { + super(Message.ERR_MSG_INVALID_INPUT_TYPE); + } + + public InputTypeException(String message) { + super(message); + } +} diff --git a/me.smartstore/exception/NullArgumentException.java b/me.smartstore/exception/NullArgumentException.java new file mode 100644 index 00000000..14349091 --- /dev/null +++ b/me.smartstore/exception/NullArgumentException.java @@ -0,0 +1,22 @@ +package exception; + +public class NullArgumentException extends RuntimeException { + public NullArgumentException() { + } + + public NullArgumentException(String message) { + super(message); + } + + public NullArgumentException(String message, Throwable cause) { + super(message, cause); + } + + public NullArgumentException(Throwable cause) { + super(cause); + } + + public NullArgumentException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/me.smartstore/group/Group.java b/me.smartstore/group/Group.java new file mode 100644 index 00000000..35881bb9 --- /dev/null +++ b/me.smartstore/group/Group.java @@ -0,0 +1,52 @@ +package group; +import java.util.Objects; + +public class Group { + private Parameter parameter; + private GroupType groupType; + + public Group() { + } + + public Group(Parameter parameter, GroupType groupType) { + this.parameter = parameter; + this.groupType = groupType; + } + + public Parameter getParameter() { + return parameter; + } + + public void setParameter(Parameter parameter) { + this.parameter = parameter; + } + + public GroupType getGroupType() { + return groupType; + } + + public void setGroupType(GroupType groupType) { + this.groupType = groupType; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Group group = (Group) o; + return Objects.equals(parameter, group.parameter) && groupType == group.groupType; + } + + @Override + public int hashCode() { + return Objects.hash(parameter, groupType); + } + + @Override + public String toString() { + return "Group{" + + "parameter=" + parameter + + ", groupType=" + groupType + + '}'; + } +} diff --git a/me.smartstore/group/GroupType.java b/me.smartstore/group/GroupType.java new file mode 100644 index 00000000..1637f363 --- /dev/null +++ b/me.smartstore/group/GroupType.java @@ -0,0 +1,21 @@ +package group; + +public enum GroupType { + N("해당없음"), G("일반고객"), V("우수고객"), VV("최우수고객"), + NONE("해당없음"), GENERAL("일반고객"), VIP("우수고객"), VVIP("최우수고객"); + + String groupType = ""; + + GroupType(String groupType) { + this.groupType = groupType; + } + + public GroupType replaceFullName() { + if (this == N) return NONE; + else if (this == G) return GENERAL; + else if (this == V) return VIP; + else if (this == VV) return VVIP; + return this; + } + +} diff --git a/me.smartstore/group/Groups.java b/me.smartstore/group/Groups.java new file mode 100644 index 00000000..84d4606c --- /dev/null +++ b/me.smartstore/group/Groups.java @@ -0,0 +1,63 @@ +package group; + +import arrays.DArray; +import customer.Customer; +import customer.Customers; + +public class Groups extends DArray { + // singleton + public static Groups allGroups; + + public static Groups getInstance() { + if (allGroups == null) { + allGroups = new Groups(); + } + return allGroups; + } + + public Groups() { + } + + public Group find(GroupType groupType) { + for (int i = 0; i < allGroups.size; i++) { + if (allGroups.get(i).getGroupType() == groupType) { + return allGroups.get(i); + } + } + return null; + } + + public void grouping(Customers customers) { + } + + public void setParameter(GroupType groupType, Parameter parameter) { + Group group = find(groupType); + if (group != null) { + group.setParameter(parameter); + } + } + + public Parameter viewParameter(GroupType groupType) { + Group group = find(groupType); + if (group != null) { + return group.getParameter(); + } + return null; + } + + public void updateParameter(GroupType groupType, Integer minTime, Integer minPay) { + Group group = find(groupType); + if (group != null) { + Parameter parameter = new Parameter(minTime, minPay); + group.setParameter(parameter); + } + } + + public Group getGroup(Customer customer) { + return null; + } + + public Group assign(Customer customer) { + return null; + } +} diff --git a/me.smartstore/group/Parameter.java b/me.smartstore/group/Parameter.java new file mode 100644 index 00000000..9cec4994 --- /dev/null +++ b/me.smartstore/group/Parameter.java @@ -0,0 +1,59 @@ +package group; + +import java.util.Objects; + +public class Parameter { + private Integer minTime; + private Integer minPay; + + + public Parameter() { + } + + public Parameter(Integer minTime, Integer minPay) { + this.minTime = minTime; + this.minPay = minPay; + } + + public Integer getMinTime() { + return minTime; + } + + public void setMinTime(Integer minTime) { + this.minTime = minTime; + } + + public Integer getMinPay() { + return minPay; + } + + public void setMinPay(Integer minPay) { + this.minPay = minPay; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Parameter parameter = (Parameter) o; + return Objects.equals(minTime, parameter.minTime) && Objects.equals(minPay, parameter.minPay); + } + + @Override + public int hashCode() { + return Objects.hash(minTime, minPay); + } + + @Override + public String toString() { + return "Parameter{" + + "minTime=" + minTime + + ", minPay=" + minPay + + '}'; + } + public void viewParameter() { + System.out.println("Minimum Time: " + minTime); + System.out.println("Minimum Pay: " + minPay); + } + +} diff --git a/me.smartstore/menu/CustomerMenu.java b/me.smartstore/menu/CustomerMenu.java new file mode 100644 index 00000000..2893db76 --- /dev/null +++ b/me.smartstore/menu/CustomerMenu.java @@ -0,0 +1,129 @@ +package menu; + +import customer.Customer; +import customer.Customers; +import exception.InputEndException; +import util.Message; + +public class CustomerMenu implements Menu { + private static CustomerMenu customerMenu; + private final Customers allCustomers = Customers.getInstance(); + + public static CustomerMenu getInstance() { + if (customerMenu == null) { + customerMenu = new CustomerMenu(); + } + return customerMenu; + } + + private CustomerMenu() {} + + @Override + public void manage() { + while (true) { + int choice = chooseMenu(new String[]{ + "Add Customer", + "View Customer", + "Update Customer", + "Delete Customer", + "Back"}); + + if (choice == 1) { + addCustomer(); + } else if (choice == 2) { + viewCustomer(); + } else if (choice == 3) { + updateCustomer(); + } else if (choice == 4) { + deleteCustomer(); + } else { + break; + } + } + } + + private void addCustomer() { + System.out.print("Enter customer name: "); + String name; + try { + name = nextLine(); + } catch (InputEndException e) { + return; + } + System.out.print("Enter customer Id: "); + String Id; + try { + Id = nextLine(); + } catch (InputEndException e) { + return; + } + System.out.print("Enter cusTotalTime: "); + int cusTotalTime; + try { + cusTotalTime = Integer.parseInt(nextLine()); + } catch (InputEndException e) { + return; + } + + System.out.print("Enter cusTotalPay: "); + int cusTotalPay; + try { + cusTotalPay = Integer.parseInt(nextLine()); + } catch (InputEndException e) { + return; + } + + + System.out.println(name + " has been added."); + } + + private void viewCustomer() { + if (allCustomers.isEmpty()) { + System.out.println("There are no customers."); + } else { + System.out.println("Customers:"); + for (Customer c : allCustomers.getList()) { + System.out.println("- " + c.getCusName() + " (ID: " + c.getCusId() + ")"+ " (TotalPay: " + c.getCusTotalPay() + ")"+ " (TotalTime: " + c.getCusTotalTime() + ")"); + } + } + } + + + private void updateCustomer() { + System.out.print("Enter customer name to update: "); + String name = nextLine(Message.END_MSG); + if (name == null) return; // input end + + Customer customer = null; + for (Customer c : allCustomers.getList()) { + if (c.getCusName().equalsIgnoreCase(name)) { + customer = c; + break; + } + } + if (customer == null) { + System.out.println("There is no customer named '" + name + "'"); + return; + } + + // update logic + System.out.println(customer.getCusName() + " has been updated."); + } + + private void deleteCustomer() { + System.out.print("Enter customer name to delete: "); + String name = nextLine(Message.END_MSG); + if (name == null) return; // input end + + Customer customer = allCustomers.find(name.toLowerCase()); // 소문자로 변환하여 검색 + if (customer == null) { + System.out.println("There is no customer named '" + name + "'"); + return; + } + + if (customer != null) { + allCustomers.remove(customer); + System.out.println(customer.getCusName() + " has been deleted."); + } + } +} diff --git a/me.smartstore/menu/GroupMenu.java b/me.smartstore/menu/GroupMenu.java new file mode 100644 index 00000000..3d877aab --- /dev/null +++ b/me.smartstore/menu/GroupMenu.java @@ -0,0 +1,185 @@ +package menu; + +import group.Groups; +import customer.Customers; +import exception.InputEndException; +import exception.InputRangeException; +import group.Group; +import group.GroupType; +import group.Parameter; +import util.Message; +public class GroupMenu implements Menu { + private final Groups allGroups = Groups.getInstance(); + private final Customers allCustomers = Customers.getInstance(); + private static GroupMenu groupMenu; + + public static GroupMenu getInstance() { + if (groupMenu == null) { + groupMenu = new GroupMenu(); + } + return groupMenu; + } + + private GroupMenu() { + } + + @Override + public void manage() { + while (true) { + int choice = chooseMenu(new String[]{"Set Parameter", "View Parameter", "Update Parameter", "Back"}); + + if (choice == 1) { + setParameter(); + } else if (choice == 2) { + viewParameter(); + } else if (choice == 3) { + updateParameter(); + } else { + break; + } + } + } + + public GroupType chooseGroup() { + while (true) { + try { + System.out.print("Which group (GENERAL (G), VIP (V), VVIP (VV))? "); + String choice = nextLine(Message.END_MSG); + + GroupType groupType = GroupType.valueOf(choice).replaceFullName(); + return groupType; + } catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + return null; + } catch (IllegalArgumentException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } + } + + public void setParameter() { + while (true) { + GroupType groupType = chooseGroup(); + if (groupType == null) { + break; + } + Group group = allGroups.find(groupType); + if (group != null && group.getParameter() != null) { + System.out.println("\n" + group.getGroupType() + " group already exists."); + System.out.println("\n" + group); + } else { + Parameter parameter = new Parameter(); + System.out.println("Enter minimum usage time"); + int minUsageTime; + while (true) { + try { + minUsageTime = Integer.parseInt(nextLine()); + if (minUsageTime < 0) { + throw new InputRangeException(); + } + break; + } catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } catch (InputRangeException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } + parameter.setMinTime(minUsageTime); + + System.out.println("Enter minimum payment amount"); + int minPaymentAmount; + while (true) { + try { + minPaymentAmount = Integer.parseInt(nextLine()); + if (minPaymentAmount < 0) { + throw new InputRangeException(); + } + break; + } catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } catch (InputRangeException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } + parameter.setMinPay(minPaymentAmount); + + group.setParameter(parameter); + allCustomers.refresh(allGroups); + } + } + } + + public void viewParameter() { + while (true) { + GroupType groupType = chooseGroup(); + if (groupType == null) { + break; + } + Group group = allGroups.find(groupType); + if (group == null || group.getParameter() == null) { + System.out.println("\n" + groupType + " group does not exist."); + } else { + System.out.println("\n" + group.getParameter()); + } + } + } + + public void updateParameter() { + while (true) { + GroupType groupType = chooseGroup(); + if (groupType == null) { + break; + } + Group group = allGroups.find(groupType); + if (group == null || group.getParameter() == null) { + System.out.println("\n" + groupType + " group does not exist."); + } else { + Parameter parameter = group.getParameter(); + System.out.println("\nCurrent parameter:"); + System.out.println(parameter); + + System.out.println("Enter new minimum usage time (current: " + parameter.getMinTime() + ")"); + int minUsageTime; + while (true) { + try { + minUsageTime = Integer.parseInt(nextLine()); + if (minUsageTime < 0) { + throw new InputRangeException(); + } + break; + } catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } catch (InputRangeException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } + parameter.setMinTime(minUsageTime); + + System.out.println("Enter new minimum payment amount (current: " + parameter.getMinPay() + ")"); + int minPaymentAmount; + while (true) { + try { + minPaymentAmount = Integer.parseInt(nextLine()); + if (minPaymentAmount < 0) { + throw new InputRangeException(); + } + break; + } catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } catch (InputRangeException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } + parameter.setMinPay(minPaymentAmount); + + System.out.println("\nNew parameter:"); + System.out.println(parameter); + + allCustomers.refresh(allGroups); + } + } + } + public interface Menu { + void manage(); + } +} \ No newline at end of file diff --git a/me.smartstore/menu/MainMenu.java b/me.smartstore/menu/MainMenu.java new file mode 100644 index 00000000..228aca4a --- /dev/null +++ b/me.smartstore/menu/MainMenu.java @@ -0,0 +1,69 @@ +package menu; + +public class MainMenu implements Menu { + + private final CustomerMenu customerMenu = CustomerMenu.getInstance(); + private final GroupMenu groupMenu = GroupMenu.getInstance(); + private final SummaryMenu summaryMenu = SummaryMenu.getInstance(); + private static MainMenu mainMenu; + + public static MainMenu getInstance() { + if (mainMenu == null) { + mainMenu = new MainMenu(); + } + return mainMenu; + } + + private MainMenu() {} + + @Override + public void manage() { + while ( true ) { + int choice = mainMenu.chooseMenu(new String[] { + "Parameter", + "Customer", + "Classification Summary", + "Quit"}); + + if (choice == 1) { + editParameter(); + } + else if (choice == 2) { + customerMenu.manage(); + } + else if (choice == 3) { + summaryMenu.manage(); + } + else { + System.out.println("Program Finished"); + saveData(); + break; + } + } + } + + public void editParameter() { + while ( true ) { + int choice = mainMenu.chooseMenu(new String[]{ + "Set Parameter", + "View Parameter", + "Update Parameter", + "Back"}); + + if (choice == 1) { + groupMenu.setParameter(); + } + else if (choice == 2) { + } + else if (choice == 3) { + } + else { + break; + } + } + } + + public void saveData() { + System.out.println("Data Saved"); + } +} diff --git a/me.smartstore/menu/Menu.java b/me.smartstore/menu/Menu.java new file mode 100644 index 00000000..e518901f --- /dev/null +++ b/me.smartstore/menu/Menu.java @@ -0,0 +1,48 @@ +package menu; + +import exception.InputRangeException; +import exception.InputEndException; +import util.Message; + +import java.util.InputMismatchException; +import java.util.Scanner; + +public interface Menu { + Scanner scanner = new Scanner(System.in); + + default String nextLine() { + return scanner.nextLine().toUpperCase(); + } + + default String nextLine(String end) { + System.out.println("** Press 'end', if you want to exit! **"); + String str = scanner.nextLine().toUpperCase(); + if (str.equals(end)) throw new InputEndException(); + return str; + } + + default int chooseMenu(String[] menus) { + while ( true ) { + try { + System.out.println("==============================="); + for (int i = 0; i < menus.length; i++) { + System.out.printf(" %d. %s\n", i + 1, menus[i]); + } + System.out.println("==============================="); + System.out.print("Choose One: "); + int choice = Integer.parseInt(nextLine()); + if (choice >= 1 && choice <= menus.length) return choice; + throw new InputRangeException(); + + } catch (InputMismatchException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + + } catch (InputRangeException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + + } + } + } + + void manage(); +} diff --git a/me.smartstore/menu/SummaryMenu.java b/me.smartstore/menu/SummaryMenu.java new file mode 100644 index 00000000..2ea3f69c --- /dev/null +++ b/me.smartstore/menu/SummaryMenu.java @@ -0,0 +1,82 @@ +package menu; + +import customer.Customer; +import customer.Customers; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class SummaryMenu implements Menu { + private static SummaryMenu summaryMenu; + + public static SummaryMenu getInstance() { + if (summaryMenu == null) { + summaryMenu = new SummaryMenu(); + } + return summaryMenu; + } + + private SummaryMenu() {} + + @Override + public void manage() { + Customers allCustomers = Customers.getInstance(); + + while (true) { + int choice = chooseMenu(new String[]{ + "Summary", + "Summary (Sorted By Name)", + "Summary (Sorted By Time)", + "Summary (Sorted By Pay)", + "Back"}); + switch (choice) { + case 1: + System.out.println("========== Summary =========="); + printCustomers(allCustomers.getList()); + break; + case 2: + System.out.println("========== Summary (Sorted By Name) =========="); + List customersSortedByName = allCustomers.getList(); + Collections.sort(customersSortedByName, new Comparator() { + @Override + public int compare(Customer o1, Customer o2) { + return o1.getCusName().compareTo(o2.getCusName()); + } + }); + printCustomers(customersSortedByName); + break; + case 3: + System.out.println("========== Summary (Sorted By Time) =========="); + List customersSortedByTime = allCustomers.getList(); + Collections.sort(customersSortedByTime, new Comparator() { + @Override + public int compare(Customer o1, Customer o2) { + return Integer.compare(o2.getCusTotalTime(), o1.getCusTotalTime()); + } + }); + printCustomers(customersSortedByTime); + break; + case 4: + System.out.println("========== Summary (Sorted By Pay) =========="); + List customersSortedByPay = allCustomers.getList(); + Collections.sort(customersSortedByPay, new Comparator() { + @Override + public int compare(Customer o1, Customer o2) { + return Double.compare(o2.getCusTotalPay(), o1.getCusTotalPay()); + } + }); + printCustomers(customersSortedByPay); + break; + case 5: + return; + } + } + } + + private void printCustomers(List customers) { + for (Customer customer : customers) { + System.out.println(customer); + } + } +} diff --git a/me.smartstore/util/Message.java b/me.smartstore/util/Message.java new file mode 100644 index 00000000..7d33cb17 --- /dev/null +++ b/me.smartstore/util/Message.java @@ -0,0 +1,13 @@ +package util; + +public interface Message { + String ERR_MSG_INVALID_ARR_EMPTY = "No Customers. Please input one first."; + String ERR_MSG_NULL_ARR_ELEMENT = "Elements in Array has null. Array can't be sorted."; + String ERR_MSG_INVALID_INPUT_NULL = "Null Input. Please input something."; + String ERR_MSG_INVALID_INPUT_EMPTY = "Empty Input. Please input something."; + String ERR_MSG_INVALID_INPUT_RANGE = "Invalid Input. Please try again."; + String ERR_MSG_INVALID_INPUT_TYPE = "Invalid Type for Input. Please try again."; + String ERR_MSG_INVALID_INPUT_FORMAT = "Invalid Format for Input. Please try again."; + String ERR_MSG_INPUT_END = "END is pressed. Exit this menu."; + String END_MSG = "END"; +}