diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/jyjang/smartstore/Main.java b/jyjang/smartstore/Main.java new file mode 100644 index 00000000..b41e1ddd --- /dev/null +++ b/jyjang/smartstore/Main.java @@ -0,0 +1,9 @@ +package jyjang.smartstore; + +public class Main { + + public static void main(String[] args) { +// SmartStoreApplication.getInstance().test().run(); + SmartStoreApplication.getInstance().run(); + } +} diff --git a/jyjang/smartstore/SmartStoreApplication.java b/jyjang/smartstore/SmartStoreApplication.java new file mode 100644 index 00000000..bd5316cb --- /dev/null +++ b/jyjang/smartstore/SmartStoreApplication.java @@ -0,0 +1,45 @@ +package jyjang.smartstore; + +import jyjang.smartstore.customer.Customers; +import jyjang.smartstore.group.Groups; +import jyjang.smartstore.menu.*; + +public class SmartStoreApplication { + + private static SmartStoreApplication smartStoreApplication; + + public static SmartStoreApplication getInstance() { + if (smartStoreApplication == null) + smartStoreApplication = new SmartStoreApplication(); + return smartStoreApplication; + } + + + + private final Groups allGroups = Groups.getInstance(); + private final Customers allCustomers = Customers.getInstance(); + + private final MainMenu mainMenu = MainMenu.getInstance(); + + public SmartStoreApplication test() { +// this.allGroups.add(new Group(GroupType.GENERAL, new Parameter(Integer.valueOf(10), Integer.valueOf(100000)))); +// this.allGroups.add(new Group(GroupType.VIP, new Parameter(Integer.valueOf(20), Integer.valueOf(200000)))); +// this.allGroups.add(new Group(GroupType.VVIP, new Parameter(Integer.valueOf(30), Integer.valueOf(300000)))); +// for (int i = 0; i < 20; i++) +// this.allCustomers.add(new Customer( +// Character.toString((char)(97 + i)), "" + (char)(97 + i) + "123", ( +// +// (int)(Math.random() * 5.0D) + 1) * 10, ( +// (int)(Math.random() * 5.0D) + 1) * 100000)); +// this.allCustomers.refresh(this.allGroups); + return this; + } + + private SmartStoreApplication() { + + } + + public void run() { + mainMenu.manage(); + } +} diff --git a/jyjang/smartstore/arrays/Collections.java b/jyjang/smartstore/arrays/Collections.java new file mode 100644 index 00000000..ea219522 --- /dev/null +++ b/jyjang/smartstore/arrays/Collections.java @@ -0,0 +1,14 @@ +package jyjang.smartstore.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); +} diff --git a/jyjang/smartstore/arrays/DArray.java b/jyjang/smartstore/arrays/DArray.java new file mode 100644 index 00000000..0e813915 --- /dev/null +++ b/jyjang/smartstore/arrays/DArray.java @@ -0,0 +1,163 @@ +package jyjang.smartstore.arrays; + +import jyjang.smartstore.exception.ElementNotFoundException; +import jyjang.smartstore.exception.EmptyArrayException; +import jyjang.smartstore.exception.NullArgumentException; + +// Dynamic Array +public class DArray implements Collections { + + 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 => 배열에 얼마나 capacity 남아있는지 외부에 알려줄 필요가 없기 때문 + protected int capacity() { + return capacity; + } + + @Override + public T get(int index) throws IndexOutOfBoundsException { + if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); + return arrays[index]; + } + + /** + * @param: ... + * @return: ... + * @throws: IndexOutOfBoundsException + * @throws: NullArgumentException + * */ + @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 { + // not found (instead of throwing exception) + if (object == null) { + throw new NullArgumentException(); + } + + for (int i = 0; i < size; i++) { + if (arrays[i] == null) continue; + if (arrays[i].equals(object)) return i; + } + throw new ElementNotFoundException(); // not found + } + + // 배열의 cap이 부족한 경우 + @Override + public void add(T object) throws NullArgumentException { + // if argument is null, do not add null value in array + if (object == null) { + throw new NullArgumentException(); + } + + 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; // doubling + 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; + } +} \ No newline at end of file diff --git a/jyjang/smartstore/customer/Customer.java b/jyjang/smartstore/customer/Customer.java new file mode 100644 index 00000000..3cc9b31a --- /dev/null +++ b/jyjang/smartstore/customer/Customer.java @@ -0,0 +1,94 @@ +package jyjang.smartstore.customer; + +import jyjang.smartstore.group.Group; + +import java.util.Objects; + +public class Customer { + + private String cName; + private String cId; + private Integer totalTime; + private Integer totalPay; + + private Group group; + + public Customer() { + + } + + public Customer(String cName, String cId) { + this.cName = cName; + this.cId = cId; + } + + public Customer(String cName, String cId, Integer totalTime, Integer totalPay) { + this.cName = cName; + this.cId = cId; + this.totalTime = totalTime; + this.totalPay = totalPay; + } + + public String getcName() { + return cName; + } + + public void setcName(String cName) { + this.cName = cName; + } + + public String getcId() { + return cId; + } + + public void setcId(String cId) { + this.cId = cId; + } + + public Integer getTotalTime() { + return totalTime; + } + + public void setTotalTime(Integer totalTime) { + this.totalTime = totalTime; + } + + public Integer getTotalPay() { + return totalPay; + } + + public void setTotalPay(Integer totalPay) { + this.totalPay = totalPay; + } + + public Group getGroup() { + return group; + } + + public void setGroup(Group group) { + this.group = group; + } + + @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(cId, customer.cId); + } + + @Override + public int hashCode() { + return Objects.hash(cId); + } + + @Override + public String toString() { + return "Customer{" + + "cName='" + cName + '\'' + + ", cId='" + cId + '\'' + + ", totalTime=" + totalTime + + ", totalPay=" + totalPay + + '}'; + } +} diff --git a/jyjang/smartstore/customer/Customers.java b/jyjang/smartstore/customer/Customers.java new file mode 100644 index 00000000..56165814 --- /dev/null +++ b/jyjang/smartstore/customer/Customers.java @@ -0,0 +1,52 @@ +package jyjang.smartstore.customer; + +import jyjang.smartstore.arrays.DArray; +import jyjang.smartstore.group.Group; +import jyjang.smartstore.group.GroupType; +import jyjang.smartstore.group.Groups; + +public class Customers extends DArray { + + // singleton + private static Customers allCustomers; + private final Groups allGroups; + + public static Customers getInstance() { + if (allCustomers == null) { + allCustomers = new Customers(); + } + return allCustomers; + } + + private Customers() { + this.allGroups = Groups.getInstance(); + } + + // refresh 함수가 호출되는 경우 + // 1. 분류기준 바뀔 때 + // 2. 새로운 고객이 들어올 때 + public void refresh() { + for (int i = 0; i < allCustomers.size(); i++) { + Customer customer = allCustomers.get(i); + customer.setGroup(findGroupByCustomer(customer)); + } + + } + + public Group findGroupByCustomer(Customer customer) { + + int totalPay = customer.getTotalPay(); + int totalTime = customer.getTotalTime(); + + for (int i = allGroups.size() - 1; i >= 0; i--) { + Group group = allGroups.get(i); + + if (totalPay >= group.getParameter().getMinimumTotalPay() && totalTime >= group.getParameter().getMinimumSpentTime()) { + return group; + } + } + + return null; + } + +} diff --git a/jyjang/smartstore/exception/ElementNotFoundException.java b/jyjang/smartstore/exception/ElementNotFoundException.java new file mode 100644 index 00000000..bae68f47 --- /dev/null +++ b/jyjang/smartstore/exception/ElementNotFoundException.java @@ -0,0 +1,22 @@ +package jyjang.smartstore.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); + } +} \ No newline at end of file diff --git a/jyjang/smartstore/exception/EmptyArrayException.java b/jyjang/smartstore/exception/EmptyArrayException.java new file mode 100644 index 00000000..9a4f2a7c --- /dev/null +++ b/jyjang/smartstore/exception/EmptyArrayException.java @@ -0,0 +1,22 @@ +package jyjang.smartstore.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); + } +} \ No newline at end of file diff --git a/jyjang/smartstore/exception/InputEndException.java b/jyjang/smartstore/exception/InputEndException.java new file mode 100644 index 00000000..f4e130cf --- /dev/null +++ b/jyjang/smartstore/exception/InputEndException.java @@ -0,0 +1,23 @@ +package jyjang.smartstore.exception; + +public class InputEndException extends RuntimeException { + + public InputEndException() { + } + + public InputEndException(String message) { + super(message); + } + + public InputEndException(String message, Throwable cause) { + super(message, cause); + } + + public InputEndException(Throwable cause) { + super(cause); + } + + public InputEndException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/jyjang/smartstore/exception/InputRangeException.java b/jyjang/smartstore/exception/InputRangeException.java new file mode 100644 index 00000000..98342b6b --- /dev/null +++ b/jyjang/smartstore/exception/InputRangeException.java @@ -0,0 +1,24 @@ +package jyjang.smartstore.exception; + +public class InputRangeException extends RuntimeException { + + public InputRangeException() { + } + + public InputRangeException(String message) { + super(message); + } + + public InputRangeException(String message, Throwable cause) { + super(message, cause); + } + + public InputRangeException(Throwable cause) { + super(cause); + } + + public InputRangeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + +} diff --git a/jyjang/smartstore/exception/NullArgumentException.java b/jyjang/smartstore/exception/NullArgumentException.java new file mode 100644 index 00000000..24530a2e --- /dev/null +++ b/jyjang/smartstore/exception/NullArgumentException.java @@ -0,0 +1,22 @@ +package jyjang.smartstore.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/jyjang/smartstore/group/Group.java b/jyjang/smartstore/group/Group.java new file mode 100644 index 00000000..96196579 --- /dev/null +++ b/jyjang/smartstore/group/Group.java @@ -0,0 +1,54 @@ +package jyjang.smartstore.group; + +import java.util.Objects; + +public class Group { + + private Parameter parameter; // 분류기준 + private GroupType groupType; // 그룹 타입 + + public Group() { + } + + public Group(GroupType groupType, Parameter parameter) { + this.groupType = groupType; + this.parameter = parameter; + } + + public GroupType getGroupType() { + return groupType; + } + + public void setGroupType(GroupType groupType) { + this.groupType = groupType; + } + + public Parameter getParameter() { + return parameter; + } + + public void setParameter(Parameter parameter) { + this.parameter = parameter; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Group group = (Group) o; + return groupType == group.groupType && Objects.equals(parameter, group.parameter); + } + + @Override + public int hashCode() { + return Objects.hash(groupType, parameter); + } + + @Override + public String toString() { + return "Group{" + + "groupType=" + groupType + + ", parameter=" + parameter + + '}'; + } +} diff --git a/jyjang/smartstore/group/GroupType.java b/jyjang/smartstore/group/GroupType.java new file mode 100644 index 00000000..f0cee830 --- /dev/null +++ b/jyjang/smartstore/group/GroupType.java @@ -0,0 +1,41 @@ +package jyjang.smartstore.group; + +import java.util.Arrays; + +public enum GroupType { + NONE("N", "해당없음") + , GENERAL("G", "일반고객") + , VIP("V", "우수고객") + , VVIP("VV", "최우수고객"); + + + String label; + final String groupType; + + GroupType(String initial, String groupType) { + this.label = initial; + this.groupType = groupType; + } + + public String getLabel() { + return label; + } + + public String getGroupType() { + return groupType; + } + + public static GroupType getGroupTypeByInitial(String label) { + GroupType groupType = Arrays.stream(values()) + .filter(type -> type.label.equals(label.toUpperCase())) + .findAny() + .orElse(null); + + if(null == groupType) { + throw new IllegalArgumentException(); + } + + return groupType; + } + +} \ No newline at end of file diff --git a/jyjang/smartstore/group/Groups.java b/jyjang/smartstore/group/Groups.java new file mode 100644 index 00000000..c257f243 --- /dev/null +++ b/jyjang/smartstore/group/Groups.java @@ -0,0 +1,35 @@ +package jyjang.smartstore.group; + +import jyjang.smartstore.arrays.DArray; +import jyjang.smartstore.customer.Customer; +import jyjang.smartstore.customer.Customers; + +import java.util.Collections; + +public class Groups extends DArray { + + private static Groups allGroups; + + public static Groups getInstance() { + if (allGroups == null) + allGroups = new Groups(); + return allGroups; + } + + private Groups() { + + } + + private Group[] 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; + + } + +} diff --git a/jyjang/smartstore/group/Parameter.java b/jyjang/smartstore/group/Parameter.java new file mode 100644 index 00000000..1d86fda2 --- /dev/null +++ b/jyjang/smartstore/group/Parameter.java @@ -0,0 +1,47 @@ +package jyjang.smartstore.group; + +import java.util.Objects; + +public class Parameter { + + private Integer minimumSpentTime; + private Integer minimumTotalPay; + + public Parameter() { + + } + + public Parameter(Integer minimumSpentTime, Integer minimumTotalPay) { + this.minimumSpentTime = minimumSpentTime; + this.minimumTotalPay = minimumTotalPay; + } + + public Integer getMinimumSpentTime() { + return minimumSpentTime; + } + + public void setMinimumSpentTime(Integer minimumSpentTime) { + this.minimumSpentTime = minimumSpentTime; + } + + public Integer getMinimumTotalPay() { + return minimumTotalPay; + } + + public void setMinimumTotalPay(Integer minimumTotalPay) { + this.minimumTotalPay = minimumTotalPay; + } + + @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(minimumSpentTime, parameter.minimumSpentTime) && Objects.equals(minimumTotalPay, parameter.minimumTotalPay); + } + + @Override + public int hashCode() { + return Objects.hash(minimumSpentTime, minimumTotalPay); + } +} diff --git a/jyjang/smartstore/menu/CustomerMenu.java b/jyjang/smartstore/menu/CustomerMenu.java new file mode 100644 index 00000000..03ad6a4b --- /dev/null +++ b/jyjang/smartstore/menu/CustomerMenu.java @@ -0,0 +1,30 @@ +package jyjang.smartstore.menu; + +public class CustomerMenu implements Menu { + + private static CustomerMenu customerMenu; + + public static CustomerMenu getInstance() { + if (customerMenu == null) + customerMenu = new CustomerMenu(); + return customerMenu; + } + + private CustomerMenu() { + super(); + + } + + @Override + public void manage() { + while (true) { + int choice = displayMenu(new String[] { + "Add Customer" + , "View Customer" + , "Update Customer" + , "Delete Customer" + , "Back"}); + } + + } +} diff --git a/jyjang/smartstore/menu/GroupMenu.java b/jyjang/smartstore/menu/GroupMenu.java new file mode 100644 index 00000000..462ceb52 --- /dev/null +++ b/jyjang/smartstore/menu/GroupMenu.java @@ -0,0 +1,164 @@ +package jyjang.smartstore.menu; + +import jyjang.smartstore.customer.Customers; +import jyjang.smartstore.exception.InputEndException; +import jyjang.smartstore.exception.InputRangeException; +import jyjang.smartstore.group.Group; +import jyjang.smartstore.group.GroupType; +import jyjang.smartstore.group.Groups; +import jyjang.smartstore.group.Parameter; +import jyjang.smartstore.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 = displayMenu(new String[] { + "Set Parameter" + , "View Parameter" + , "Update Parameter" + , "Back"}); + + if (choice == 1) { + setParameter(); + } else if (choice == 2) { + viewParameter(); + } else if (choice == 3) { + updateParameter(); + } else if (choice == 4) { + break; + } + } + } + + public GroupType chooseGroup() { + while (true) { + try { + System.out.println("Which group (GENERAL (G), VIP (V), VVIP (VV))? "); + // 프로그램을 끝내기 위한 신호기 때문에 내부 메소드에 입력 23.04.27 + String choice = nextLine(Message.END_MSG); + + GroupType groupType = GroupType.getGroupTypeByInitial(choice); + 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); + } + } + } + + private void setParameter() { + while (true) { + GroupType groupType = chooseGroup(); + + 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(); + + while (true) { + int choice = displayMenu(new String[] { + "Minimum Spent Time" + , "Minimum Total Pay" + , "Back" }); + if (choice == 1) { + setParameterMinimumSpentTime(parameter); + continue; + } + if (choice == 2) { + setParameterMinimumTotalPay(parameter); + continue; + } + if (choice == 3) + break; + } + + allGroups.add(new Group(groupType, parameter)); + allCustomers.refresh(); + } + } + } + + private void viewParameter() { + } + + private void updateParameter() { + } + + private void setParameterMinimumSpentTime(Parameter parameter) { + while (true) { + try { + System.out.println(); + System.out.println("Input Minimum Spent Time : "); + + int minimumSpentTime = Integer.parseInt(nextLine("end")); + if (minimumSpentTime < 0) { + throw new InputRangeException(); + } + + parameter.setMinimumSpentTime(minimumSpentTime); + return; + } catch (InputRangeException e) { + System.out.println(); + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } catch (NumberFormatException e) { + System.out.println(); + System.out.println(Message.ERR_MSG_INVALID_INPUT_TYPE); + } catch (InputEndException e) { + System.out.println(); + System.out.println(Message.ERR_MSG_INPUT_END); + break; + } + } + } + + private void setParameterMinimumTotalPay(Parameter parameter) { + while (true) { + try { + System.out.println(); + System.out.println("Input Minimum Spent Time : "); + + int minimumTotalPay = Integer.parseInt(nextLine("end")); + if (minimumTotalPay < 0) { + throw new InputRangeException(); + } + + parameter.setMinimumTotalPay(minimumTotalPay); + return; + } catch (InputRangeException e) { + System.out.println(); + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } catch (NumberFormatException e) { + System.out.println(); + System.out.println(Message.ERR_MSG_INVALID_INPUT_TYPE); + } catch (InputEndException e) { + System.out.println(); + System.out.println(Message.ERR_MSG_INPUT_END); + break; + } + } + } + +} + diff --git a/jyjang/smartstore/menu/MainMenu.java b/jyjang/smartstore/menu/MainMenu.java new file mode 100644 index 00000000..a12ae3a0 --- /dev/null +++ b/jyjang/smartstore/menu/MainMenu.java @@ -0,0 +1,44 @@ +package jyjang.smartstore.menu; + +public class MainMenu implements Menu { + + private static MainMenu mainMenu; + + public static MainMenu getInstance() { + if (mainMenu == null) + mainMenu = new MainMenu(); + return mainMenu; + } + + private MainMenu() { + + } + + private final CustomerMenu customerMenu = CustomerMenu.getInstance(); + private final GroupMenu groupMenu = GroupMenu.getInstance(); + private final SummarizedMenu summarizedMenu = SummarizedMenu.getInstance(); + + + @Override + public void manage() { + // 프로그램을 실행(유지) While + while (true) { + int choice = mainMenu.displayMenu(new String[] { + "Parameter" + , "Customer Data" + , "Classification Summary" + , "Quit"}); + + if (choice == 1) { + groupMenu.manage(); + } else if (choice == 2) { + customerMenu.manage(); + } else if (choice == 3) { + summarizedMenu.manage(); + } else if (choice == 4) { + System.out.println("Program Finished"); + break; + } + } + } +} diff --git a/jyjang/smartstore/menu/Menu.java b/jyjang/smartstore/menu/Menu.java new file mode 100644 index 00000000..0a510ad7 --- /dev/null +++ b/jyjang/smartstore/menu/Menu.java @@ -0,0 +1,61 @@ +package jyjang.smartstore.menu; + +import jyjang.smartstore.exception.InputEndException; +import jyjang.smartstore.exception.InputRangeException; +import jyjang.smartstore.util.Message; + +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) throws InputEndException { + System.out.println("** Press 'end', if you want to exit! **"); + String inputString = scanner.nextLine().toUpperCase(); + if (inputString.equals(end)) { + throw new InputEndException(); + } + + return inputString; + } + + + // 예외 복구 While + default int displayMenu(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 (NumberFormatException 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/jyjang/smartstore/menu/SummarizedMenu.java b/jyjang/smartstore/menu/SummarizedMenu.java new file mode 100644 index 00000000..d5a911e2 --- /dev/null +++ b/jyjang/smartstore/menu/SummarizedMenu.java @@ -0,0 +1,28 @@ +package jyjang.smartstore.menu; + +public class SummarizedMenu implements Menu { + + private static SummarizedMenu summarizedMenu; + + public static SummarizedMenu getInstance() { + if (summarizedMenu == null) + summarizedMenu = new SummarizedMenu(); + return summarizedMenu; + } + + private SummarizedMenu() { + + } + + @Override + public void manage() { + while (true) { + int choice = displayMenu(new String[] { + "Summary" + , "Summary (Sorted By Name)" + , "Summary (Sorted By Time)" + , "Summary (Sorted By Pay)" + , "Back"}); + } + } +} diff --git a/jyjang/smartstore/util/Message.java b/jyjang/smartstore/util/Message.java new file mode 100644 index 00000000..eb67638b --- /dev/null +++ b/jyjang/smartstore/util/Message.java @@ -0,0 +1,13 @@ +package jyjang.smartstore.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"; +} \ No newline at end of file