From d9e6386f5038083ba7ddb219be12e61c35ad421b Mon Sep 17 00:00:00 2001 From: Ussu1112 Date: Thu, 4 May 2023 19:26:52 +0900 Subject: [PATCH 01/14] =?UTF-8?q?create=20package,=20=EB=8F=99=EC=A0=81?= =?UTF-8?q?=EB=B0=B0=EC=97=B4,=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/me/smartstore/Main.java | 9 + src/me/smartstore/SmartStoreApp.java | 7 + src/me/smartstore/arrays/Collections.java | 13 ++ src/me/smartstore/arrays/DArray.java | 154 ++++++++++++++++++ src/me/smartstore/customer/Customer.java | 4 + .../exception/ArrayEmptyException.java | 14 ++ .../exception/ElementNotFoundException.java | 13 ++ .../exception/EmptyArrayException.java | 13 ++ .../exception/InputEmptyException.java | 14 ++ .../exception/InputEndException.java | 13 ++ .../exception/InputFormatException.java | 13 ++ .../exception/InputRangeException.java | 13 ++ .../exception/InputTypeException.java | 14 ++ .../exception/NullArgumentException.java | 11 ++ src/me/smartstore/group/Group.java | 4 + src/me/smartstore/menu/Menu.java | 4 + src/me/smartstore/utils/Message.java | 14 ++ 17 files changed, 327 insertions(+) create mode 100644 src/me/smartstore/Main.java create mode 100644 src/me/smartstore/SmartStoreApp.java create mode 100644 src/me/smartstore/arrays/Collections.java create mode 100644 src/me/smartstore/arrays/DArray.java create mode 100644 src/me/smartstore/customer/Customer.java create mode 100644 src/me/smartstore/exception/ArrayEmptyException.java create mode 100644 src/me/smartstore/exception/ElementNotFoundException.java create mode 100644 src/me/smartstore/exception/EmptyArrayException.java create mode 100644 src/me/smartstore/exception/InputEmptyException.java create mode 100644 src/me/smartstore/exception/InputEndException.java create mode 100644 src/me/smartstore/exception/InputFormatException.java create mode 100644 src/me/smartstore/exception/InputRangeException.java create mode 100644 src/me/smartstore/exception/InputTypeException.java create mode 100644 src/me/smartstore/exception/NullArgumentException.java create mode 100644 src/me/smartstore/group/Group.java create mode 100644 src/me/smartstore/menu/Menu.java create mode 100644 src/me/smartstore/utils/Message.java diff --git a/src/me/smartstore/Main.java b/src/me/smartstore/Main.java new file mode 100644 index 00000000..826ea714 --- /dev/null +++ b/src/me/smartstore/Main.java @@ -0,0 +1,9 @@ +package me.smartstore; + +public class Main { + public static void main(String[] args) { + + + + } +} diff --git a/src/me/smartstore/SmartStoreApp.java b/src/me/smartstore/SmartStoreApp.java new file mode 100644 index 00000000..b3f0b4da --- /dev/null +++ b/src/me/smartstore/SmartStoreApp.java @@ -0,0 +1,7 @@ +package me.smartstore; + +public class SmartStoreApp { + + private static SmartStoreApp smartStoreApp; + +} diff --git a/src/me/smartstore/arrays/Collections.java b/src/me/smartstore/arrays/Collections.java new file mode 100644 index 00000000..87a43dd1 --- /dev/null +++ b/src/me/smartstore/arrays/Collections.java @@ -0,0 +1,13 @@ +package me.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/src/me/smartstore/arrays/DArray.java b/src/me/smartstore/arrays/DArray.java new file mode 100644 index 00000000..ff633ee8 --- /dev/null +++ b/src/me/smartstore/arrays/DArray.java @@ -0,0 +1,154 @@ +package me.smartstore.arrays; + +import me.smartstore.exception.ElementNotFoundException; +import me.smartstore.exception.EmptyArrayException; +import me.smartstore.exception.NullArgumentException; + +public class DArray implements Collections { + protected static final int DEFAULT = 10; + + protected T[] arrays; + protected int size; + protected int capacity; + + @SuppressWarnings("unchecked") + public DArray() throws ClassCastException { + arrays = (T[]) new Object[DEFAULT]; + capacity = DEFAULT; + } + + @SuppressWarnings("unchecked") + public DArray(int initial) throws ClassCastException { + arrays = (T[]) new Object[initial]; + capacity = initial; + } + + public DArray(T[] arrays) { + this.arrays = arrays; + capacity = arrays.length; + size = arrays.length; + } + + ///////////////////////////////////////// + // add, set, get, pop, indexOf, size, capacity (for dynamic-sized array) + + @Override + public int size() { + return size; + } + + // 배열에 얼마나 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 { + 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 + } + + // 배열의 cap이 부족한 경우 + @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() { +// if (size == 0) return null; +// +// T popElement = arrays[size-1]; +// arrays[size-1] = null; +// size--; +// return popElement; + 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); + + // size는 그대로 + } + + @Override + public String toString() { + String toStr = ""; + for (int i = 0; i < size; i++) { + toStr += (arrays[i] + "\n"); + } + return toStr; + } +} diff --git a/src/me/smartstore/customer/Customer.java b/src/me/smartstore/customer/Customer.java new file mode 100644 index 00000000..d5bed050 --- /dev/null +++ b/src/me/smartstore/customer/Customer.java @@ -0,0 +1,4 @@ +package me.smartstore.customer; + +public class Customer { +} diff --git a/src/me/smartstore/exception/ArrayEmptyException.java b/src/me/smartstore/exception/ArrayEmptyException.java new file mode 100644 index 00000000..f333e148 --- /dev/null +++ b/src/me/smartstore/exception/ArrayEmptyException.java @@ -0,0 +1,14 @@ +package me.smartstore.exception; + +import me.smartstore.utils.Message; + +public class ArrayEmptyException extends RuntimeException { + + public ArrayEmptyException() { + super(Message.ERR_MSG_INVALID_ARR_EMPTY); + } + + public ArrayEmptyException(String message) { + super(message); + } +} diff --git a/src/me/smartstore/exception/ElementNotFoundException.java b/src/me/smartstore/exception/ElementNotFoundException.java new file mode 100644 index 00000000..b90fa497 --- /dev/null +++ b/src/me/smartstore/exception/ElementNotFoundException.java @@ -0,0 +1,13 @@ +package me.smartstore.exception; + +import me.smartstore.utils.Message; + +public class ElementNotFoundException extends RuntimeException{ + public ElementNotFoundException() { + super(Message.ERR_MSG_NULL_ARR_ELEMENT); + } + + public ElementNotFoundException(String message) { + super(message); + } +} diff --git a/src/me/smartstore/exception/EmptyArrayException.java b/src/me/smartstore/exception/EmptyArrayException.java new file mode 100644 index 00000000..759a8740 --- /dev/null +++ b/src/me/smartstore/exception/EmptyArrayException.java @@ -0,0 +1,13 @@ +package me.smartstore.exception; + +import me.smartstore.utils.Message; + +public class EmptyArrayException extends RuntimeException{ + public EmptyArrayException() { + super(Message.ERR_MSG_ARR_EMPTY); + } + + public EmptyArrayException(String message) { + super(message); + } +} diff --git a/src/me/smartstore/exception/InputEmptyException.java b/src/me/smartstore/exception/InputEmptyException.java new file mode 100644 index 00000000..f38777d4 --- /dev/null +++ b/src/me/smartstore/exception/InputEmptyException.java @@ -0,0 +1,14 @@ +package me.smartstore.exception; + +import me.smartstore.utils.Message; + +public class InputEmptyException extends RuntimeException{ + + public InputEmptyException() { + super(Message.ERR_MSG_INVALID_INPUT_EMPTY); + } + + public InputEmptyException(String message) { + super(message); + } +} diff --git a/src/me/smartstore/exception/InputEndException.java b/src/me/smartstore/exception/InputEndException.java new file mode 100644 index 00000000..b26a6a00 --- /dev/null +++ b/src/me/smartstore/exception/InputEndException.java @@ -0,0 +1,13 @@ +package me.smartstore.exception; + +import me.smartstore.utils.Message; + +public class InputEndException extends RuntimeException{ + public InputEndException() { + super(Message.ERR_MSG_INPUT_END); + } + + public InputEndException(String message) { + super(message); + } +} diff --git a/src/me/smartstore/exception/InputFormatException.java b/src/me/smartstore/exception/InputFormatException.java new file mode 100644 index 00000000..bae0431f --- /dev/null +++ b/src/me/smartstore/exception/InputFormatException.java @@ -0,0 +1,13 @@ +package me.smartstore.exception; + +import me.smartstore.utils.Message; + +public class InputFormatException extends RuntimeException{ + public InputFormatException() { + super(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } + + public InputFormatException(String message) { + super(message); + } +} diff --git a/src/me/smartstore/exception/InputRangeException.java b/src/me/smartstore/exception/InputRangeException.java new file mode 100644 index 00000000..a73cb789 --- /dev/null +++ b/src/me/smartstore/exception/InputRangeException.java @@ -0,0 +1,13 @@ +package me.smartstore.exception; + +import me.smartstore.utils.Message; + +public class InputRangeException extends RuntimeException{ + public InputRangeException() { + super(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + + public InputRangeException(String message) { + super(message); + } +} diff --git a/src/me/smartstore/exception/InputTypeException.java b/src/me/smartstore/exception/InputTypeException.java new file mode 100644 index 00000000..538ae57f --- /dev/null +++ b/src/me/smartstore/exception/InputTypeException.java @@ -0,0 +1,14 @@ +package me.smartstore.exception; + +import me.smartstore.utils.Message; + +public class InputTypeException extends RuntimeException{ + + public InputTypeException() { + super(Message.ERR_MSG_INVALID_INPUT_TYPE); + } + + public InputTypeException(String message) { + super(message); + } +} diff --git a/src/me/smartstore/exception/NullArgumentException.java b/src/me/smartstore/exception/NullArgumentException.java new file mode 100644 index 00000000..e420db6a --- /dev/null +++ b/src/me/smartstore/exception/NullArgumentException.java @@ -0,0 +1,11 @@ +package me.smartstore.exception; + +public class NullArgumentException extends RuntimeException{ + + public NullArgumentException() { + } + + public NullArgumentException(String message) { + super(message); + } +} diff --git a/src/me/smartstore/group/Group.java b/src/me/smartstore/group/Group.java new file mode 100644 index 00000000..782985d4 --- /dev/null +++ b/src/me/smartstore/group/Group.java @@ -0,0 +1,4 @@ +package me.smartstore.group; + +public class Group { +} diff --git a/src/me/smartstore/menu/Menu.java b/src/me/smartstore/menu/Menu.java new file mode 100644 index 00000000..76d62126 --- /dev/null +++ b/src/me/smartstore/menu/Menu.java @@ -0,0 +1,4 @@ +package me.smartstore.menu; + +public class Menu { +} diff --git a/src/me/smartstore/utils/Message.java b/src/me/smartstore/utils/Message.java new file mode 100644 index 00000000..b27e09b9 --- /dev/null +++ b/src/me/smartstore/utils/Message.java @@ -0,0 +1,14 @@ +package me.smartstore.utils; + +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_ARR_EMPTY = "Array is Empty"; + 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"; +} From 69c9e73ddf4eb675f15719082bbd8fccc76a1d77 Mon Sep 17 00:00:00 2001 From: Ussu1112 Date: Sun, 7 May 2023 23:36:10 +0900 Subject: [PATCH 02/14] =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EB=B0=8F=20=EA=B0=95=EC=9D=98=20=EB=B3=B5=EC=8A=B5?= =?UTF-8?q?=20=ED=9B=84=20=EC=86=8C=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/me/smartstore/Main.java | 5 +- src/me/smartstore/SmartStoreApp.java | 56 +++++++++++++++ src/me/smartstore/customer/Customer.java | 83 +++++++++++++++++++++++ src/me/smartstore/customer/Customers.java | 26 +++++++ src/me/smartstore/group/Group.java | 49 +++++++++++++ src/me/smartstore/group/GroupType.java | 20 ++++++ src/me/smartstore/group/Groups.java | 28 ++++++++ src/me/smartstore/group/Parameter.java | 53 +++++++++++++++ src/me/smartstore/menu/CustomerMenu.java | 26 +++++++ src/me/smartstore/menu/GroupMenu.java | 80 ++++++++++++++++++++++ src/me/smartstore/menu/MainMenu.java | 38 +++++++++++ src/me/smartstore/menu/Menu.java | 40 ++++++++++- src/me/smartstore/menu/SummaryMenu.java | 28 ++++++++ 13 files changed, 528 insertions(+), 4 deletions(-) create mode 100644 src/me/smartstore/customer/Customers.java create mode 100644 src/me/smartstore/group/GroupType.java create mode 100644 src/me/smartstore/group/Groups.java create mode 100644 src/me/smartstore/group/Parameter.java create mode 100644 src/me/smartstore/menu/CustomerMenu.java create mode 100644 src/me/smartstore/menu/GroupMenu.java create mode 100644 src/me/smartstore/menu/MainMenu.java create mode 100644 src/me/smartstore/menu/SummaryMenu.java diff --git a/src/me/smartstore/Main.java b/src/me/smartstore/Main.java index 826ea714..549a8040 100644 --- a/src/me/smartstore/Main.java +++ b/src/me/smartstore/Main.java @@ -2,8 +2,7 @@ public class Main { public static void main(String[] args) { - - - + SmartStoreApp.getInstance().test().run(); // function chaining + // SmartStoreApp.getInstance().run(); } } diff --git a/src/me/smartstore/SmartStoreApp.java b/src/me/smartstore/SmartStoreApp.java index b3f0b4da..3893801d 100644 --- a/src/me/smartstore/SmartStoreApp.java +++ b/src/me/smartstore/SmartStoreApp.java @@ -1,7 +1,63 @@ package me.smartstore; +import me.smartstore.customer.Customer; +import me.smartstore.customer.Customers; +import me.smartstore.group.Group; +import me.smartstore.group.GroupType; +import me.smartstore.group.Groups; +import me.smartstore.group.Parameter; +import me.smartstore.menu.MainMenu; + public class SmartStoreApp { + private final Groups allGroups = Groups.getInstance(); + private final Customers allCustomers = Customers.getInstance(); + private final MainMenu mainMenu = MainMenu.getInstance(); + 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.04.27"); + System.out.println(" Copyright 2023 Eunbin 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; // smartStoreApp + } + + public void run() { + details(); + mainMenu.manage(); + + } + } diff --git a/src/me/smartstore/customer/Customer.java b/src/me/smartstore/customer/Customer.java index d5bed050..8cc7b36b 100644 --- a/src/me/smartstore/customer/Customer.java +++ b/src/me/smartstore/customer/Customer.java @@ -1,4 +1,87 @@ package me.smartstore.customer; +import me.smartstore.group.Group; + +import java.util.Objects; + public class Customer { + private String cusName; + private String cusId; + private Integer cusTotalTime; + private Integer 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, Integer cusTotalTime, Integer cusTotalPay) { + this.cusName = cusName; + this.cusId = cusId; + this.cusTotalTime = cusTotalTime; + this.cusTotalPay = cusTotalPay; + } + + 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 Integer getCusTotalTime() { + return cusTotalTime; + } + + public void setCusTotalTime(Integer cusTotalTime) { + this.cusTotalTime = cusTotalTime; + } + + public Integer getCusTotalPay() { + return cusTotalPay; + } + + public void setCusTotalPay(Integer cusTotalPay) { + this.cusTotalPay = cusTotalPay; + } + + @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 + + '}'; + } } diff --git a/src/me/smartstore/customer/Customers.java b/src/me/smartstore/customer/Customers.java new file mode 100644 index 00000000..f6298163 --- /dev/null +++ b/src/me/smartstore/customer/Customers.java @@ -0,0 +1,26 @@ +package me.smartstore.customer; + +import me.smartstore.arrays.DArray; +import me.smartstore.group.Groups; + +public class Customers extends DArray { + private static Customers allCustomers; + + public static Customers getInstance() { + if (allCustomers == null){ + allCustomers = new Customers(); + } + return allCustomers; + } + + private Customers() {} + + // refresh 함수가 호출되는 경우 + // 1. 분류기준 바뀔 때 + // 2. 새로운 고객이 들어올 때 + public void refresh(Groups groups) { + + + } + +} diff --git a/src/me/smartstore/group/Group.java b/src/me/smartstore/group/Group.java index 782985d4..e80f33b3 100644 --- a/src/me/smartstore/group/Group.java +++ b/src/me/smartstore/group/Group.java @@ -1,4 +1,53 @@ package me.smartstore.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/src/me/smartstore/group/GroupType.java b/src/me/smartstore/group/GroupType.java new file mode 100644 index 00000000..50070aad --- /dev/null +++ b/src/me/smartstore/group/GroupType.java @@ -0,0 +1,20 @@ +package me.smartstore.group; + +public enum GroupType { + NONE("해당없음"), GENERAL("일반고객"), VIP("우수고객"), VVIP("최우수고객"), + N("해당없음"), G("일반고객"), V("우수고객"), VV("최우수고객"); + + 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/src/me/smartstore/group/Groups.java b/src/me/smartstore/group/Groups.java new file mode 100644 index 00000000..91487bf4 --- /dev/null +++ b/src/me/smartstore/group/Groups.java @@ -0,0 +1,28 @@ +package me.smartstore.group; + +import me.smartstore.arrays.DArray; + +public class Groups extends DArray { + private static Groups allGroups; + + public static Groups getInstance(){ + if (allGroups == null){ + allGroups = new Groups(); + } + return allGroups; + } + + private 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/src/me/smartstore/group/Parameter.java b/src/me/smartstore/group/Parameter.java new file mode 100644 index 00000000..c2b0b3b0 --- /dev/null +++ b/src/me/smartstore/group/Parameter.java @@ -0,0 +1,53 @@ +package me.smartstore.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 + + '}'; + } +} diff --git a/src/me/smartstore/menu/CustomerMenu.java b/src/me/smartstore/menu/CustomerMenu.java new file mode 100644 index 00000000..21c9d41a --- /dev/null +++ b/src/me/smartstore/menu/CustomerMenu.java @@ -0,0 +1,26 @@ +package me.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() {} + + @Override + public void manage() { + while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while + int choice = chooseMenu(new String[]{ + "Add Customer", + "View Customer", + "Update Customer", + "Delete Customer", + "Back"}); + } + } +} diff --git a/src/me/smartstore/menu/GroupMenu.java b/src/me/smartstore/menu/GroupMenu.java new file mode 100644 index 00000000..846b866b --- /dev/null +++ b/src/me/smartstore/menu/GroupMenu.java @@ -0,0 +1,80 @@ +package me.smartstore.menu; + +import me.smartstore.customer.Customers; +import me.smartstore.exception.InputEndException; +import me.smartstore.group.Group; +import me.smartstore.group.GroupType; +import me.smartstore.group.Groups; +import me.smartstore.group.Parameter; +import me.smartstore.utils.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 ) { // 서브 메뉴 페이지를 유지하기 위한 while + 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; // choice == 4 + } + } + + public GroupType chooseGroup() { + while ( true ) { + try { + System.out.print("Which group (GENERAL (G), VIP (V), VVIP (VV))? "); + String choice = nextLine(Message.END_MSG); + // group (str) -> GroupType (enum) + // "VIP" -> GroupType.VIP + + 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(); + + // GroupType에 해당하는 group 객체를 찾아야 함 + Group group = allGroups.find(groupType); + if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 + System.out.println("\n" + group.getGroupType() + " group already exists."); + System.out.println("\n" + group); + } else { + Parameter parameter = new Parameter(); + // time, pay 사용자 입력받은 후, 설정 필요 + + group.setParameter(parameter); + allCustomers.refresh(allGroups); // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 + } + } + } +} diff --git a/src/me/smartstore/menu/MainMenu.java b/src/me/smartstore/menu/MainMenu.java new file mode 100644 index 00000000..4157d531 --- /dev/null +++ b/src/me/smartstore/menu/MainMenu.java @@ -0,0 +1,38 @@ +package me.smartstore.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 ) { // 프로그램 실행 while + int choice = mainMenu.chooseMenu(new String[] { + "Parameter", + "Customer", + "Classification Summary", + "Quit"}); + + if (choice == 1) groupMenu.manage(); + else if (choice == 2) customerMenu.manage(); + else if (choice == 3) summaryMenu.manage(); + else { // choice == 4 + System.out.println("Program Finished"); + break; + } + } + } +} diff --git a/src/me/smartstore/menu/Menu.java b/src/me/smartstore/menu/Menu.java index 76d62126..20c4d901 100644 --- a/src/me/smartstore/menu/Menu.java +++ b/src/me/smartstore/menu/Menu.java @@ -1,4 +1,42 @@ package me.smartstore.menu; -public class Menu { +import me.smartstore.exception.InputEndException; +import me.smartstore.exception.InputRangeException; + +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(); // choice 가 범위에 벗어남 + } catch (InputMismatchException | InputRangeException e){ + System.out.println(e.getMessage()); + } + } + } + + void manage(); // 각 서브메뉴들을 관리하는 함수 (각 서브메뉴의 최상위 메뉴) } diff --git a/src/me/smartstore/menu/SummaryMenu.java b/src/me/smartstore/menu/SummaryMenu.java new file mode 100644 index 00000000..4f35b051 --- /dev/null +++ b/src/me/smartstore/menu/SummaryMenu.java @@ -0,0 +1,28 @@ +package me.smartstore.menu; + +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() { + while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while + int choice = chooseMenu(new String[]{ + "Summary", + "Summary (Sorted By Name)", + "Summary (Sorted By Time)", + "Summary (Sorted By Pay)", + "Back"}); + } + } +} + From 36d342ee35282029c2a723b69ec2d5e9719d4cd6 Mon Sep 17 00:00:00 2001 From: Ussu1112 Date: Tue, 9 May 2023 13:50:43 +0900 Subject: [PATCH 03/14] feat: implement menus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 각 기능으로 이동하는 메뉴 구현 --- src/me/smartstore/Main.java | 2 +- src/me/smartstore/SmartStoreApp.java | 2 +- src/me/smartstore/customer/Customer.java | 11 ++- src/me/smartstore/customer/Customers.java | 21 ++++++ src/me/smartstore/group/Group.java | 6 +- src/me/smartstore/group/Groups.java | 1 - src/me/smartstore/menu/CustomerMenu.java | 81 +++++++++++++++++++++-- src/me/smartstore/menu/GroupMenu.java | 47 +++++++++++-- src/me/smartstore/menu/Menu.java | 25 ++++++- src/me/smartstore/menu/SummaryMenu.java | 42 ++++++++++++ 10 files changed, 219 insertions(+), 19 deletions(-) diff --git a/src/me/smartstore/Main.java b/src/me/smartstore/Main.java index 549a8040..0f39e9fa 100644 --- a/src/me/smartstore/Main.java +++ b/src/me/smartstore/Main.java @@ -3,6 +3,6 @@ public class Main { public static void main(String[] args) { SmartStoreApp.getInstance().test().run(); // function chaining - // SmartStoreApp.getInstance().run(); +// SmartStoreApp.getInstance().run(); } } diff --git a/src/me/smartstore/SmartStoreApp.java b/src/me/smartstore/SmartStoreApp.java index 3893801d..e287d2e7 100644 --- a/src/me/smartstore/SmartStoreApp.java +++ b/src/me/smartstore/SmartStoreApp.java @@ -38,7 +38,7 @@ public SmartStoreApp test() { 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++) { + for (int i = 0; i < 5; i++) { allCustomers.add(new Customer( Character.toString((char) ('a' + i)), (char) ('a' + i) + "123", diff --git a/src/me/smartstore/customer/Customer.java b/src/me/smartstore/customer/Customer.java index 8cc7b36b..e161a5bf 100644 --- a/src/me/smartstore/customer/Customer.java +++ b/src/me/smartstore/customer/Customer.java @@ -1,6 +1,7 @@ package me.smartstore.customer; import me.smartstore.group.Group; +import me.smartstore.group.GroupType; import java.util.Objects; @@ -9,9 +10,11 @@ public class Customer { private String cusId; private Integer cusTotalTime; private Integer cusTotalPay; - private Group group; // 현재 분류 기준에 의해 각 고객을 분류된 결과 + private GroupType group; // 현재 분류 기준에 의해 각 고객을 분류된 결과 public Customer() { + //초기 값 설정 + group = GroupType.NONE; } public Customer(String cusId) { @@ -24,6 +27,7 @@ public Customer(String cusName, String cusId) { } public Customer(String cusName, String cusId, Integer cusTotalTime, Integer cusTotalPay) { + this(); this.cusName = cusName; this.cusId = cusId; this.cusTotalTime = cusTotalTime; @@ -62,6 +66,10 @@ public void setCusTotalPay(Integer cusTotalPay) { this.cusTotalPay = cusTotalPay; } + public GroupType getGroup() { + return group; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -82,6 +90,7 @@ public String toString() { ", cusId='" + cusId + '\'' + ", cusTotalTime=" + cusTotalTime + ", cusTotalPay=" + cusTotalPay + + ", group=" + group + '}'; } } diff --git a/src/me/smartstore/customer/Customers.java b/src/me/smartstore/customer/Customers.java index f6298163..b7338e3c 100644 --- a/src/me/smartstore/customer/Customers.java +++ b/src/me/smartstore/customer/Customers.java @@ -1,6 +1,8 @@ package me.smartstore.customer; import me.smartstore.arrays.DArray; +import me.smartstore.group.Group; +import me.smartstore.group.GroupType; import me.smartstore.group.Groups; public class Customers extends DArray { @@ -23,4 +25,23 @@ public void refresh(Groups groups) { } + public void viewCustomerData(){ + int num = 1; + for (int i = 0; i < allCustomers.size; i++){ + System.out.println("No. " + num + " => "+ allCustomers.get(i)); + num++; + } + } + + public void viewCustomerData(GroupType groupType) { + int num = 1; + for (int i = 0; i < allCustomers.size; i++){ + if( allCustomers.get(i).getGroup() == groupType) { + System.out.println("No. " + num + " => " + allCustomers.get(i)); + num++; + } + } + } + + } diff --git a/src/me/smartstore/group/Group.java b/src/me/smartstore/group/Group.java index e80f33b3..f69711fa 100644 --- a/src/me/smartstore/group/Group.java +++ b/src/me/smartstore/group/Group.java @@ -45,9 +45,7 @@ public int hashCode() { @Override public String toString() { - return "Group{" + - "parameter=" + parameter + - ", groupType=" + groupType + - '}'; + return "GroupType=" + groupType +"\n" + + "Parameter=" + parameter; } } diff --git a/src/me/smartstore/group/Groups.java b/src/me/smartstore/group/Groups.java index 91487bf4..423bc6bd 100644 --- a/src/me/smartstore/group/Groups.java +++ b/src/me/smartstore/group/Groups.java @@ -24,5 +24,4 @@ public Group find(GroupType groupType) { } - } diff --git a/src/me/smartstore/menu/CustomerMenu.java b/src/me/smartstore/menu/CustomerMenu.java index 21c9d41a..bbd996cd 100644 --- a/src/me/smartstore/menu/CustomerMenu.java +++ b/src/me/smartstore/menu/CustomerMenu.java @@ -1,7 +1,12 @@ package me.smartstore.menu; +import me.smartstore.customer.Customers; +import me.smartstore.exception.ArrayEmptyException; +import me.smartstore.utils.Message; + public class CustomerMenu implements Menu { private static CustomerMenu customerMenu; + private final Customers allCustomers = Customers.getInstance(); public static CustomerMenu getInstance() { if(customerMenu == null) { @@ -16,11 +21,79 @@ private CustomerMenu() {} public void manage() { while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while int choice = chooseMenu(new String[]{ - "Add Customer", - "View Customer", - "Update Customer", - "Delete Customer", + "Add Customer Data", + "View Customer Data", + "Update Customer Data", + "Delete Customer Data", + "Back"}); + + if (choice == 1) addCustomer(); + else if (choice == 2) viewCustomer(); + else if (choice == 3) updateCustomer(); + else if (choice == 4) deleteCustomer(); + else MainMenu.getInstance().manage(); + } + } + + private void addCustomer() { + System.out.println("How many customers to input?"); + int addCustomer = Integer.parseInt(nextLine(Message.END_MSG)); + int cnt = 1; + while ( cnt <= addCustomer ){ + System.out.println("====== Customer " + cnt + " Info. ======"); + int choice = chooseMenu(new String[]{ + "Customer Name", + "Customer ID", + "Customer Spent Time", + "Customer Total Pay", "Back"}); + + // Customer 에 새로운 고객 추가 + if (choice == 1) addCustomerName(); + else if (choice == 2) addCustomerID(); + else if (choice == 3) addCustomerSpentTime(); + else if (choice == 4) addCustomerTotalPay(); + else cnt++; } } + + private void viewCustomer() { + System.out.println("======= Customer Info. ======="); + allCustomers.viewCustomerData(); + } + + private void updateCustomer() { + System.out.println("updateCustomer 생성중"); + allCustomers.viewCustomerData(); + while ( true ) { + try{ + int choiceNum = nextLine(allCustomers.size()); +// return choiceNum; + //고객 선택 후 변경 add 할 때의 Customer 내용 셀렉이 또 필요 + } catch (ArrayEmptyException e){ + System.out.println(e.getMessage()); + } + } +// if( allCustomers.size() > 1) { } + } + + private void deleteCustomer() { + System.out.println("deleteCustomer 생성중"); + } + + private void addCustomerName() { + System.out.println("addCustomerName 생성중"); + } + + private void addCustomerID() { + System.out.println("addCustomerID 생성중"); + } + + private void addCustomerSpentTime() { + System.out.println("addCustomerSpentTime 생성중"); + } + + private void addCustomerTotalPay() { + System.out.println("addCustomerTotalPay 생성중"); + } } diff --git a/src/me/smartstore/menu/GroupMenu.java b/src/me/smartstore/menu/GroupMenu.java index 846b866b..97ced65a 100644 --- a/src/me/smartstore/menu/GroupMenu.java +++ b/src/me/smartstore/menu/GroupMenu.java @@ -34,16 +34,30 @@ public void manage() { "Back"}); if (choice == 1) setParameter(); - else if (choice == 2) {}// viewParameter(); - else if (choice == 3) {}// updateParameter(); - else break; // choice == 4 + else if (choice == 2) viewParameter(); + else if (choice == 3) updateParameter(); + else MainMenu.getInstance().manage(); } } + public void inputTimeAndPay(GroupType groupType) { + while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while + int choice = chooseMenu(new String[]{ + "Minimum Spent Time", + "Minimum Total Pay", + "Back"}); + + if (choice == 1) setMinimumTime(groupType); + else if (choice == 2) setMinimumPay(groupType); + else manage(); // choice == 3 + } + + } + public GroupType chooseGroup() { while ( true ) { try { - System.out.print("Which group (GENERAL (G), VIP (V), VVIP (VV))? "); + System.out.println("Which group (GENERAL (G), VIP (V), VVIP (VV))? "); String choice = nextLine(Message.END_MSG); // group (str) -> GroupType (enum) // "VIP" -> GroupType.VIP @@ -71,10 +85,33 @@ public void setParameter() { // 초기화할 때만 호출 가능 } else { Parameter parameter = new Parameter(); // time, pay 사용자 입력받은 후, 설정 필요 + inputTimeAndPay(groupType); - group.setParameter(parameter); allCustomers.refresh(allGroups); // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 } } } + + public void viewParameter() { + String choice = nextLine(Message.END_MSG); + System.out.println("viewParameter 생성중"); + manage(); + } + + public void updateParameter() { + System.out.println("updateParameter 생성중"); + manage(); + } + + public void setMinimumTime(GroupType groupType) { + //group.setParameter(parameter); + System.out.println("setMinimumTime 생성중"); + inputTimeAndPay(groupType); + } + + public void setMinimumPay(GroupType groupType) { + //group.setParameter(parameter); + System.out.println("setMinimumPay 생성중"); + inputTimeAndPay(groupType); + } } diff --git a/src/me/smartstore/menu/Menu.java b/src/me/smartstore/menu/Menu.java index 20c4d901..61ae2fc7 100644 --- a/src/me/smartstore/menu/Menu.java +++ b/src/me/smartstore/menu/Menu.java @@ -2,6 +2,8 @@ import me.smartstore.exception.InputEndException; import me.smartstore.exception.InputRangeException; +import me.smartstore.group.GroupType; +import me.smartstore.utils.Message; import java.util.InputMismatchException; import java.util.Scanner; @@ -20,6 +22,23 @@ default String nextLine(String end) { return str; } + default Integer nextLine(Integer size){ + while ( true ) { + try { + System.out.println("Which customer ( 1 ~ " + size + " )?"); + Integer num = scanner.nextInt(); + if(num <= 0 || num > size) throw new InputRangeException(); + return num; + // chooseMenu 로 통합하고 출력문만 변경? + } 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); + } + } + } + default int chooseMenu(String[] menus) { while (true){ try { @@ -32,8 +51,10 @@ default int chooseMenu(String[] menus) { int choice = Integer.parseInt(nextLine()); if (choice >= 1 && choice <= menus.length) return choice; throw new InputRangeException(); // choice 가 범위에 벗어남 - } catch (InputMismatchException | InputRangeException e){ - System.out.println(e.getMessage()); + } catch (InputMismatchException | NumberFormatException e){ + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } catch (InputRangeException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); } } } diff --git a/src/me/smartstore/menu/SummaryMenu.java b/src/me/smartstore/menu/SummaryMenu.java index 4f35b051..8c886b5d 100644 --- a/src/me/smartstore/menu/SummaryMenu.java +++ b/src/me/smartstore/menu/SummaryMenu.java @@ -1,9 +1,17 @@ package me.smartstore.menu; +import me.smartstore.customer.Customers; +import me.smartstore.group.Group; +import me.smartstore.group.GroupType; +import me.smartstore.group.Groups; + public class SummaryMenu implements Menu { private static SummaryMenu summaryMenu; + private final Groups allGroups = Groups.getInstance(); + private final Customers allCustomers = Customers.getInstance(); + public static SummaryMenu getInstance(){ if(summaryMenu == null) { summaryMenu = new SummaryMenu(); @@ -22,7 +30,41 @@ public void manage() { "Summary (Sorted By Time)", "Summary (Sorted By Pay)", "Back"}); + + if (choice == 1) showSummary(); + else if (choice == 2) showSummarySortedByName(); + else if (choice == 3) showSummarySortedBySpentTime(); + else if (choice == 4) showSummarySortedByTotalPayment(); + else MainMenu.getInstance().manage(); } + + + } + + private void showSummary() { + //출력문 통합? + + System.out.println("=============================="); + System.out.println("Group : " + GroupType.GENERAL + + " ( Time : " + allGroups.find(GroupType.GENERAL).getParameter().getMinTime() + ", " + + "Pay : " + allGroups.find(GroupType.GENERAL).getParameter().getMinPay() + " )" + ); + System.out.println("=============================="); + allCustomers.viewCustomerData(GroupType.GENERAL); + +// System.out.println("Group : " + GroupType.NONE + "( Time" + allGroups.get(GroupType.NONE) + ""); + } + + private void showSummarySortedByName() { + System.out.println("showSummarySortedByName 구현"); + } + + private void showSummarySortedBySpentTime() { + System.out.println("showSummarySortedBySpentTime 구현"); + } + + private void showSummarySortedByTotalPayment() { + System.out.println("showSummarySortedByTotalPayment 구현"); } } From 4f358212608bf0af2d0baa515fbbb83ea1a0d94e Mon Sep 17 00:00:00 2001 From: ussu1112 Date: Tue, 9 May 2023 17:58:33 +0900 Subject: [PATCH 04/14] feat: Set Parameter, View Parameter --- src/me/smartstore/Main.java | 2 +- src/me/smartstore/SmartStoreApp.java | 2 +- src/me/smartstore/customer/Customer.java | 4 + src/me/smartstore/customer/Customers.java | 78 ++++++++++++++++ src/me/smartstore/group/Groups.java | 23 ++++- src/me/smartstore/menu/GroupMenu.java | 106 ++++++++++++++++------ src/me/smartstore/menu/SummaryMenu.java | 3 +- 7 files changed, 185 insertions(+), 33 deletions(-) diff --git a/src/me/smartstore/Main.java b/src/me/smartstore/Main.java index 0f39e9fa..291f0fa5 100644 --- a/src/me/smartstore/Main.java +++ b/src/me/smartstore/Main.java @@ -3,6 +3,6 @@ public class Main { public static void main(String[] args) { SmartStoreApp.getInstance().test().run(); // function chaining -// SmartStoreApp.getInstance().run(); +// SmartStoreApp.getInstance().run(); } } diff --git a/src/me/smartstore/SmartStoreApp.java b/src/me/smartstore/SmartStoreApp.java index e287d2e7..222abc55 100644 --- a/src/me/smartstore/SmartStoreApp.java +++ b/src/me/smartstore/SmartStoreApp.java @@ -38,7 +38,7 @@ public SmartStoreApp test() { 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 < 5; i++) { + for (int i = 0; i < 10; i++) { allCustomers.add(new Customer( Character.toString((char) ('a' + i)), (char) ('a' + i) + "123", diff --git a/src/me/smartstore/customer/Customer.java b/src/me/smartstore/customer/Customer.java index e161a5bf..7507b856 100644 --- a/src/me/smartstore/customer/Customer.java +++ b/src/me/smartstore/customer/Customer.java @@ -70,6 +70,10 @@ public GroupType getGroup() { return group; } + public void setGroup(GroupType group) { + this.group = group; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/me/smartstore/customer/Customers.java b/src/me/smartstore/customer/Customers.java index b7338e3c..f7a03e7b 100644 --- a/src/me/smartstore/customer/Customers.java +++ b/src/me/smartstore/customer/Customers.java @@ -1,6 +1,7 @@ package me.smartstore.customer; import me.smartstore.arrays.DArray; +import me.smartstore.exception.NullArgumentException; import me.smartstore.group.Group; import me.smartstore.group.GroupType; import me.smartstore.group.Groups; @@ -21,8 +22,85 @@ private Customers() {} // 1. 분류기준 바뀔 때 // 2. 새로운 고객이 들어올 때 public void refresh(Groups groups) { + System.out.println("refresh()"); + int cusMinTime; + int cusMinPay; + int VVIPMinTime = 0, VVIPMinPay = 0, + VIPMinTime = 0, VIPMinPay = 0, + GENERALMinTime = 0, GENERALMInPay = 0; + int cnt = 0; + + if (groups.find(GroupType.VVIP) != null) { + VVIPMinTime = groups.find(GroupType.VVIP).getParameter().getMinTime(); + VVIPMinPay = groups.find(GroupType.VVIP).getParameter().getMinPay(); + cnt += 4; + } + if (groups.find(GroupType.VIP) != null) { + VIPMinTime = groups.find(GroupType.VIP).getParameter().getMinTime(); + VIPMinPay = groups.find(GroupType.VIP).getParameter().getMinPay(); + cnt += 2; + } + if (groups.find(GroupType.GENERAL) != null) { + GENERALMinTime = groups.find(GroupType.GENERAL).getParameter().getMinTime(); + GENERALMInPay = groups.find(GroupType.GENERAL).getParameter().getMinPay(); + cnt += 1; + } + + System.out.println(cnt); + + for (int i = 0; i < allCustomers.size; i++) { + Customer customer = allCustomers.get(i); + System.out.println("customer = " + customer); + cusMinTime = allCustomers.get(i).getCusTotalTime(); + cusMinPay = allCustomers.get(i).getCusTotalPay(); + + + switch (cnt) { + case 7: + if (cusMinTime > VVIPMinTime && cusMinPay > VVIPMinPay) + allCustomers.get(i).setGroup(GroupType.VVIP); + else if (cusMinTime > VIPMinTime && cusMinPay > VIPMinPay) + allCustomers.get(i).setGroup(GroupType.VIP); + else if (cusMinTime > GENERALMinTime && cusMinPay > GENERALMInPay) + allCustomers.get(i).setGroup(GroupType.GENERAL); +// else allCustomers.get(i).setGroup(GroupType.NONE); + case 6: + if (cusMinTime > VVIPMinTime && cusMinPay > VVIPMinPay) + allCustomers.get(i).setGroup(GroupType.VVIP); + else if (cusMinTime > VIPMinTime && cusMinPay > VIPMinPay) + allCustomers.get(i).setGroup(GroupType.VIP); + else allCustomers.get(i).setGroup(GroupType.NONE); + case 5: + if (cusMinTime > VVIPMinTime && cusMinPay > VVIPMinPay) + allCustomers.get(i).setGroup(GroupType.VVIP); + else if (cusMinTime > GENERALMinTime && cusMinPay > GENERALMInPay) + allCustomers.get(i).setGroup(GroupType.GENERAL); + else allCustomers.get(i).setGroup(GroupType.NONE); + case 4: + if (cusMinTime > VVIPMinTime && cusMinPay > VVIPMinPay) + allCustomers.get(i).setGroup(GroupType.VVIP); + else allCustomers.get(i).setGroup(GroupType.NONE); + case 3: + if (cusMinTime > VIPMinTime && cusMinPay > VIPMinPay) + allCustomers.get(i).setGroup(GroupType.VIP); + else if (cusMinTime > GENERALMinTime && cusMinPay > GENERALMInPay) + allCustomers.get(i).setGroup(GroupType.GENERAL); + else allCustomers.get(i).setGroup(GroupType.NONE); + case 2: + if (cusMinTime > VIPMinTime && cusMinPay > VIPMinPay) + allCustomers.get(i).setGroup(GroupType.VIP); + else allCustomers.get(i).setGroup(GroupType.NONE); + case 1: + if (cusMinTime > GENERALMinTime && cusMinPay > GENERALMInPay) + allCustomers.get(i).setGroup(GroupType.GENERAL); + else allCustomers.get(i).setGroup(GroupType.NONE); + + } + } + + System.out.println(allCustomers); } public void viewCustomerData(){ diff --git a/src/me/smartstore/group/Groups.java b/src/me/smartstore/group/Groups.java index 423bc6bd..c7eb268a 100644 --- a/src/me/smartstore/group/Groups.java +++ b/src/me/smartstore/group/Groups.java @@ -20,8 +20,29 @@ public Group find(GroupType groupType) { return allGroups.get(i); } } - return null; + return null; } + public void checkGroupParameter(Group group) { + // 전달 받은값으로 옳은 값인지 확인 후 적용 + // 이용시간, 금액 General < VIP < VVIP + // 시간 되면 추가하기 + if (group.getParameter().getMinTime() != null + && group.getParameter().getMinPay() != null){ + + } else if (group.getParameter().getMinTime() != null + && group.getParameter().getMinPay() == null){ + + } else if (group.getParameter().getMinTime() == null + && group.getParameter().getMinPay() != null){ + + } else if (group.getParameter().getMinTime() == null + && group.getParameter().getMinPay() == null){ + allGroups.set(allGroups.indexOf(group), group); + } + } + + + } diff --git a/src/me/smartstore/menu/GroupMenu.java b/src/me/smartstore/menu/GroupMenu.java index 97ced65a..85d329d5 100644 --- a/src/me/smartstore/menu/GroupMenu.java +++ b/src/me/smartstore/menu/GroupMenu.java @@ -8,6 +8,8 @@ import me.smartstore.group.Parameter; import me.smartstore.utils.Message; +import java.util.Objects; + public class GroupMenu implements Menu{ private final Groups allGroups = Groups.getInstance(); @@ -40,20 +42,6 @@ public void manage() { } } - public void inputTimeAndPay(GroupType groupType) { - while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while - int choice = chooseMenu(new String[]{ - "Minimum Spent Time", - "Minimum Total Pay", - "Back"}); - - if (choice == 1) setMinimumTime(groupType); - else if (choice == 2) setMinimumPay(groupType); - else manage(); // choice == 3 - } - - } - public GroupType chooseGroup() { while ( true ) { try { @@ -77,7 +65,7 @@ public void setParameter() { // 초기화할 때만 호출 가능 while ( true ) { GroupType groupType = chooseGroup(); - // GroupType에 해당하는 group 객체를 찾아야 함 + // GroupType 에 해당하는 group 객체를 찾아야 함 Group group = allGroups.find(groupType); if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 System.out.println("\n" + group.getGroupType() + " group already exists."); @@ -92,26 +80,86 @@ public void setParameter() { // 초기화할 때만 호출 가능 } } + public void inputTimeAndPay(GroupType groupType) { + // 함수 진입 시 해당 groupType 으로 Group 생성 + allGroups.add(new Group(new Parameter(null, null), groupType)); + int minimumTime = 0; + int minimumPay = 0; + while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while + + int choice = chooseMenu(new String[]{ + "Minimum Spent Time", + "Minimum Total Pay", + "Back"}); + + if (choice == 1) minimumTime = setMinimumTime(); + else if (choice == 2) minimumPay = setMinimumPay(); + else manage(); // choice == 3 + + + + + Group group = allGroups.find(groupType); + group.setParameter(new Parameter(minimumTime, minimumPay)); + allGroups.set(allGroups.indexOf(group), group); + + + // Group 내에 있는 다른 그룹 파라미터와 비교 + // allGroups.checkGroupParameter(group); + + // + allCustomers.refresh(allGroups); + } + } + public void viewParameter() { - String choice = nextLine(Message.END_MSG); - System.out.println("viewParameter 생성중"); - manage(); + while ( true ) { + GroupType groupType = chooseGroup(); + + if (groupType == null) manage(); + + Group group = allGroups.find(groupType); + + if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 + System.out.println(group); + } else if (group == null){ + // 출력문으로 표시하지 않고 null 일 때 null 로 어떻게 출력하는가.. + System.out.println("GroupType: " + groupType); + System.out.println("Parameter: " + null); + } + } } - public void updateParameter() { - System.out.println("updateParameter 생성중"); - manage(); + public int setMinimumTime() { + while ( true ) { + try { + System.out.println("Input Minimum Spent Time: "); + String choice = nextLine(Message.END_MSG); + return Integer.parseInt(choice); + } catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + } catch (IllegalArgumentException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } } - public void setMinimumTime(GroupType groupType) { - //group.setParameter(parameter); - System.out.println("setMinimumTime 생성중"); - inputTimeAndPay(groupType); + public int setMinimumPay() { + while ( true ) { + try { + System.out.println("Input Minimum Total Pay : "); + String choice = nextLine(Message.END_MSG); + return Integer.parseInt(choice); + } catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + } catch (IllegalArgumentException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } } - public void setMinimumPay(GroupType groupType) { - //group.setParameter(parameter); - System.out.println("setMinimumPay 생성중"); - inputTimeAndPay(groupType); + public void updateParameter() { + System.out.println("updateParameter 생성중"); + manage(); } } diff --git a/src/me/smartstore/menu/SummaryMenu.java b/src/me/smartstore/menu/SummaryMenu.java index 8c886b5d..97043c52 100644 --- a/src/me/smartstore/menu/SummaryMenu.java +++ b/src/me/smartstore/menu/SummaryMenu.java @@ -50,7 +50,8 @@ private void showSummary() { "Pay : " + allGroups.find(GroupType.GENERAL).getParameter().getMinPay() + " )" ); System.out.println("=============================="); - allCustomers.viewCustomerData(GroupType.GENERAL); + allCustomers.viewCustomerData(); +// allCustomers.viewCustomerData(GroupType.GENERAL); // System.out.println("Group : " + GroupType.NONE + "( Time" + allGroups.get(GroupType.NONE) + ""); } From 1f582e5222631b66aed34cd58912edf8178e48f4 Mon Sep 17 00:00:00 2001 From: Ussu1112 Date: Tue, 9 May 2023 20:17:48 +0900 Subject: [PATCH 05/14] feat: implement updateParameter --- src/me/smartstore/SmartStoreApp.java | 4 +- src/me/smartstore/customer/Customers.java | 86 ++++++++----------- .../exception/ArrayEmptyException.java | 14 --- .../CustomerArrayEmptyException.java | 14 +++ .../exception/ParameterArrEmptyException.java | 14 +++ src/me/smartstore/menu/CustomerMenu.java | 4 +- src/me/smartstore/menu/GroupMenu.java | 34 ++++---- src/me/smartstore/utils/Message.java | 3 +- 8 files changed, 91 insertions(+), 82 deletions(-) delete mode 100644 src/me/smartstore/exception/ArrayEmptyException.java create mode 100644 src/me/smartstore/exception/CustomerArrayEmptyException.java create mode 100644 src/me/smartstore/exception/ParameterArrEmptyException.java diff --git a/src/me/smartstore/SmartStoreApp.java b/src/me/smartstore/SmartStoreApp.java index 222abc55..e0c5251e 100644 --- a/src/me/smartstore/SmartStoreApp.java +++ b/src/me/smartstore/SmartStoreApp.java @@ -28,8 +28,8 @@ private SmartStoreApp() {} public void details() { System.out.println("\n\n==========================================="); System.out.println(" Title : SmartStore Customer Classification"); - System.out.println(" Release Date : 23.04.27"); - System.out.println(" Copyright 2023 Eunbin All rights reserved."); + System.out.println(" Release Date : 23.05.10"); + System.out.println(" Copyright 2023 taeHyoung All rights reserved."); System.out.println("===========================================\n"); } diff --git a/src/me/smartstore/customer/Customers.java b/src/me/smartstore/customer/Customers.java index f7a03e7b..af89cb7d 100644 --- a/src/me/smartstore/customer/Customers.java +++ b/src/me/smartstore/customer/Customers.java @@ -1,8 +1,6 @@ package me.smartstore.customer; import me.smartstore.arrays.DArray; -import me.smartstore.exception.NullArgumentException; -import me.smartstore.group.Group; import me.smartstore.group.GroupType; import me.smartstore.group.Groups; @@ -22,7 +20,6 @@ private Customers() {} // 1. 분류기준 바뀔 때 // 2. 새로운 고객이 들어올 때 public void refresh(Groups groups) { - System.out.println("refresh()"); int cusMinTime; int cusMinPay; @@ -48,58 +45,51 @@ public void refresh(Groups groups) { cnt += 1; } - System.out.println(cnt); for (int i = 0; i < allCustomers.size; i++) { - Customer customer = allCustomers.get(i); - System.out.println("customer = " + customer); cusMinTime = allCustomers.get(i).getCusTotalTime(); cusMinPay = allCustomers.get(i).getCusTotalPay(); - - switch (cnt) { - case 7: - if (cusMinTime > VVIPMinTime && cusMinPay > VVIPMinPay) - allCustomers.get(i).setGroup(GroupType.VVIP); - else if (cusMinTime > VIPMinTime && cusMinPay > VIPMinPay) - allCustomers.get(i).setGroup(GroupType.VIP); - else if (cusMinTime > GENERALMinTime && cusMinPay > GENERALMInPay) - allCustomers.get(i).setGroup(GroupType.GENERAL); -// else allCustomers.get(i).setGroup(GroupType.NONE); - case 6: - if (cusMinTime > VVIPMinTime && cusMinPay > VVIPMinPay) - allCustomers.get(i).setGroup(GroupType.VVIP); - else if (cusMinTime > VIPMinTime && cusMinPay > VIPMinPay) - allCustomers.get(i).setGroup(GroupType.VIP); - else allCustomers.get(i).setGroup(GroupType.NONE); - case 5: - if (cusMinTime > VVIPMinTime && cusMinPay > VVIPMinPay) - allCustomers.get(i).setGroup(GroupType.VVIP); - else if (cusMinTime > GENERALMinTime && cusMinPay > GENERALMInPay) - allCustomers.get(i).setGroup(GroupType.GENERAL); - else allCustomers.get(i).setGroup(GroupType.NONE); - case 4: - if (cusMinTime > VVIPMinTime && cusMinPay > VVIPMinPay) - allCustomers.get(i).setGroup(GroupType.VVIP); - else allCustomers.get(i).setGroup(GroupType.NONE); - case 3: - if (cusMinTime > VIPMinTime && cusMinPay > VIPMinPay) - allCustomers.get(i).setGroup(GroupType.VIP); - else if (cusMinTime > GENERALMinTime && cusMinPay > GENERALMInPay) - allCustomers.get(i).setGroup(GroupType.GENERAL); - else allCustomers.get(i).setGroup(GroupType.NONE); - case 2: - if (cusMinTime > VIPMinTime && cusMinPay > VIPMinPay) - allCustomers.get(i).setGroup(GroupType.VIP); - else allCustomers.get(i).setGroup(GroupType.NONE); - case 1: - if (cusMinTime > GENERALMinTime && cusMinPay > GENERALMInPay) - allCustomers.get(i).setGroup(GroupType.GENERAL); - else allCustomers.get(i).setGroup(GroupType.NONE); - + if( cnt == 7 ) { + if (cusMinTime >= VVIPMinTime && cusMinPay >= VVIPMinPay) + allCustomers.get(i).setGroup(GroupType.VVIP); + else if (cusMinTime >= VIPMinTime && cusMinPay >= VIPMinPay) + allCustomers.get(i).setGroup(GroupType.VIP); + else if (cusMinTime >= GENERALMinTime && cusMinPay >= GENERALMInPay) + allCustomers.get(i).setGroup(GroupType.GENERAL); + else allCustomers.get(i).setGroup(GroupType.NONE); + } else if ( cnt == 6 ){ + if (cusMinTime >= VVIPMinTime && cusMinPay >= VVIPMinPay) + allCustomers.get(i).setGroup(GroupType.VVIP); + else if (cusMinTime >= VIPMinTime && cusMinPay >= VIPMinPay) + allCustomers.get(i).setGroup(GroupType.VIP); + else allCustomers.get(i).setGroup(GroupType.NONE); + } else if ( cnt == 5 ){ + if (cusMinTime >= VVIPMinTime && cusMinPay >= VVIPMinPay) + allCustomers.get(i).setGroup(GroupType.VVIP); + else if (cusMinTime >= GENERALMinTime && cusMinPay >= GENERALMInPay) + allCustomers.get(i).setGroup(GroupType.GENERAL); + else allCustomers.get(i).setGroup(GroupType.NONE); + } else if ( cnt == 4 ){ + if (cusMinTime >= VVIPMinTime && cusMinPay >= VVIPMinPay) + allCustomers.get(i).setGroup(GroupType.VVIP); + else allCustomers.get(i).setGroup(GroupType.NONE); + } else if ( cnt == 3 ){ + if (cusMinTime >= VIPMinTime && cusMinPay >= VIPMinPay) + allCustomers.get(i).setGroup(GroupType.VIP); + else if (cusMinTime >= GENERALMinTime && cusMinPay >= GENERALMInPay) + allCustomers.get(i).setGroup(GroupType.GENERAL); + else allCustomers.get(i).setGroup(GroupType.NONE); + } else if ( cnt == 2 ){ + if (cusMinTime >= VIPMinTime && cusMinPay >= VIPMinPay) + allCustomers.get(i).setGroup(GroupType.VIP); + else allCustomers.get(i).setGroup(GroupType.NONE); + } else if ( cnt == 1 ){ + if (cusMinTime >= GENERALMinTime && cusMinPay >= GENERALMInPay) + allCustomers.get(i).setGroup(GroupType.GENERAL); + else allCustomers.get(i).setGroup(GroupType.NONE); } } - System.out.println(allCustomers); } diff --git a/src/me/smartstore/exception/ArrayEmptyException.java b/src/me/smartstore/exception/ArrayEmptyException.java deleted file mode 100644 index f333e148..00000000 --- a/src/me/smartstore/exception/ArrayEmptyException.java +++ /dev/null @@ -1,14 +0,0 @@ -package me.smartstore.exception; - -import me.smartstore.utils.Message; - -public class ArrayEmptyException extends RuntimeException { - - public ArrayEmptyException() { - super(Message.ERR_MSG_INVALID_ARR_EMPTY); - } - - public ArrayEmptyException(String message) { - super(message); - } -} diff --git a/src/me/smartstore/exception/CustomerArrayEmptyException.java b/src/me/smartstore/exception/CustomerArrayEmptyException.java new file mode 100644 index 00000000..7ad3fe6b --- /dev/null +++ b/src/me/smartstore/exception/CustomerArrayEmptyException.java @@ -0,0 +1,14 @@ +package me.smartstore.exception; + +import me.smartstore.utils.Message; + +public class CustomerArrayEmptyException extends RuntimeException { + + public CustomerArrayEmptyException() { + super(Message.ERR_MSG_INVALID_CUSTOMER_ARR_EMPTY); + } + + public CustomerArrayEmptyException(String message) { + super(message); + } +} diff --git a/src/me/smartstore/exception/ParameterArrEmptyException.java b/src/me/smartstore/exception/ParameterArrEmptyException.java new file mode 100644 index 00000000..b454a853 --- /dev/null +++ b/src/me/smartstore/exception/ParameterArrEmptyException.java @@ -0,0 +1,14 @@ +package me.smartstore.exception; + +import me.smartstore.utils.Message; + +public class ParameterArrEmptyException extends RuntimeException { + + public ParameterArrEmptyException() { + super(Message.ERR_MSG_INVALID_PARAMETER_ARR_EMPTY); + } + + public ParameterArrEmptyException(String message) { + super(message); + } +} diff --git a/src/me/smartstore/menu/CustomerMenu.java b/src/me/smartstore/menu/CustomerMenu.java index bbd996cd..ba525e5c 100644 --- a/src/me/smartstore/menu/CustomerMenu.java +++ b/src/me/smartstore/menu/CustomerMenu.java @@ -1,7 +1,7 @@ package me.smartstore.menu; import me.smartstore.customer.Customers; -import me.smartstore.exception.ArrayEmptyException; +import me.smartstore.exception.CustomerArrayEmptyException; import me.smartstore.utils.Message; public class CustomerMenu implements Menu { @@ -70,7 +70,7 @@ private void updateCustomer() { int choiceNum = nextLine(allCustomers.size()); // return choiceNum; //고객 선택 후 변경 add 할 때의 Customer 내용 셀렉이 또 필요 - } catch (ArrayEmptyException e){ + } catch (CustomerArrayEmptyException e){ System.out.println(e.getMessage()); } } diff --git a/src/me/smartstore/menu/GroupMenu.java b/src/me/smartstore/menu/GroupMenu.java index 85d329d5..e731cb5d 100644 --- a/src/me/smartstore/menu/GroupMenu.java +++ b/src/me/smartstore/menu/GroupMenu.java @@ -49,9 +49,7 @@ public GroupType chooseGroup() { String choice = nextLine(Message.END_MSG); // group (str) -> GroupType (enum) // "VIP" -> GroupType.VIP - - GroupType groupType = GroupType.valueOf(choice).replaceFullName(); - return groupType; + return GroupType.valueOf(choice).replaceFullName(); } catch (InputEndException e) { System.out.println(Message.ERR_MSG_INPUT_END); return null; @@ -71,11 +69,9 @@ public void setParameter() { // 초기화할 때만 호출 가능 System.out.println("\n" + group.getGroupType() + " group already exists."); System.out.println("\n" + group); } else { - Parameter parameter = new Parameter(); - // time, pay 사용자 입력받은 후, 설정 필요 inputTimeAndPay(groupType); - - allCustomers.refresh(allGroups); // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 + // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 + allCustomers.refresh(allGroups); } } } @@ -96,18 +92,13 @@ public void inputTimeAndPay(GroupType groupType) { else if (choice == 2) minimumPay = setMinimumPay(); else manage(); // choice == 3 - - - Group group = allGroups.find(groupType); group.setParameter(new Parameter(minimumTime, minimumPay)); allGroups.set(allGroups.indexOf(group), group); - - // Group 내에 있는 다른 그룹 파라미터와 비교 + // Group 내에 있는 다른 그룹 파라미터와 비교? // allGroups.checkGroupParameter(group); - // allCustomers.refresh(allGroups); } } @@ -159,7 +150,20 @@ public int setMinimumPay() { } public void updateParameter() { - System.out.println("updateParameter 생성중"); - manage(); + + while ( true ) { + GroupType groupType = chooseGroup(); + // GroupType 에 해당하는 group 객체를 찾아야 함 + Group group = allGroups.find(groupType); + if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 + inputTimeAndPay(groupType); + // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 + allCustomers.refresh(allGroups); + } else { + System.out.println(Message.ERR_MSG_INVALID_PARAMETER_ARR_EMPTY); + manage(); + } + } + } } diff --git a/src/me/smartstore/utils/Message.java b/src/me/smartstore/utils/Message.java index b27e09b9..9a3560b5 100644 --- a/src/me/smartstore/utils/Message.java +++ b/src/me/smartstore/utils/Message.java @@ -1,7 +1,8 @@ package me.smartstore.utils; public interface Message { - String ERR_MSG_INVALID_ARR_EMPTY = "No Customers. Please input one first."; + String ERR_MSG_INVALID_CUSTOMER_ARR_EMPTY = "No Customers. Please input one first."; + String ERR_MSG_INVALID_PARAMETER_ARR_EMPTY = "No parameter. Set the parameter first."; String ERR_MSG_NULL_ARR_ELEMENT = "Elements in Array has null. Array can't be sorted."; String ERR_MSG_ARR_EMPTY = "Array is Empty"; String ERR_MSG_INVALID_INPUT_NULL = "Null Input. Please input something."; From e9e807c748c5ab553c66ac4bb716a257eed7d21d Mon Sep 17 00:00:00 2001 From: Ussu1112 Date: Wed, 10 May 2023 14:04:19 +0900 Subject: [PATCH 06/14] feat: implement customerMenu( addCustomer, updateCustomer, deleteCustomer) --- src/me/smartstore/customer/Customer.java | 15 +- src/me/smartstore/customer/Customers.java | 17 ++- src/me/smartstore/menu/CustomerMenu.java | 174 +++++++++++++++++----- src/me/smartstore/menu/GroupMenu.java | 8 +- src/me/smartstore/menu/Menu.java | 19 +-- 5 files changed, 174 insertions(+), 59 deletions(-) diff --git a/src/me/smartstore/customer/Customer.java b/src/me/smartstore/customer/Customer.java index 7507b856..4450c488 100644 --- a/src/me/smartstore/customer/Customer.java +++ b/src/me/smartstore/customer/Customer.java @@ -1,20 +1,24 @@ package me.smartstore.customer; -import me.smartstore.group.Group; import me.smartstore.group.GroupType; import java.util.Objects; public class Customer { - private String cusName; + private int cusNo; private String cusId; + private String cusName; private Integer cusTotalTime; private Integer cusTotalPay; private GroupType group; // 현재 분류 기준에 의해 각 고객을 분류된 결과 + private static int seqNum = 1; + public Customer() { //초기 값 설정 + cusNo = seqNum; group = GroupType.NONE; + seqNum++; } public Customer(String cusId) { @@ -34,6 +38,10 @@ public Customer(String cusName, String cusId, Integer cusTotalTime, Integer cusT this.cusTotalPay = cusTotalPay; } + public int getCusNo() { + return cusNo; + } + public String getCusName() { return cusName; } @@ -89,7 +97,8 @@ public int hashCode() { @Override public String toString() { - return "Customer{" + + return "No. " + cusNo + " => " + + "Customer{" + "cusName='" + cusName + '\'' + ", cusId='" + cusId + '\'' + ", cusTotalTime=" + cusTotalTime + diff --git a/src/me/smartstore/customer/Customers.java b/src/me/smartstore/customer/Customers.java index af89cb7d..f0ec2bd5 100644 --- a/src/me/smartstore/customer/Customers.java +++ b/src/me/smartstore/customer/Customers.java @@ -93,10 +93,21 @@ else if (cusMinTime >= GENERALMinTime && cusMinPay >= GENERALMInPay) System.out.println(allCustomers); } + public int findCustomerDataByCusNo(int customerIdx){ + + int idx = -1; + for (int i = 0; i < allCustomers.size(); i++) { + if(allCustomers.get(i).getCusNo() == customerIdx){ + idx = allCustomers.indexOf(allCustomers.get(i)); + } + } + return idx; + } + public void viewCustomerData(){ int num = 1; for (int i = 0; i < allCustomers.size; i++){ - System.out.println("No. " + num + " => "+ allCustomers.get(i)); + System.out.println(allCustomers.get(i)); num++; } } @@ -105,11 +116,9 @@ public void viewCustomerData(GroupType groupType) { int num = 1; for (int i = 0; i < allCustomers.size; i++){ if( allCustomers.get(i).getGroup() == groupType) { - System.out.println("No. " + num + " => " + allCustomers.get(i)); + System.out.println(allCustomers.get(i)); num++; } } } - - } diff --git a/src/me/smartstore/menu/CustomerMenu.java b/src/me/smartstore/menu/CustomerMenu.java index ba525e5c..16795ae2 100644 --- a/src/me/smartstore/menu/CustomerMenu.java +++ b/src/me/smartstore/menu/CustomerMenu.java @@ -1,7 +1,8 @@ package me.smartstore.menu; +import me.smartstore.customer.Customer; import me.smartstore.customer.Customers; -import me.smartstore.exception.CustomerArrayEmptyException; +import me.smartstore.exception.InputEndException; import me.smartstore.utils.Message; public class CustomerMenu implements Menu { @@ -39,61 +40,160 @@ private void addCustomer() { System.out.println("How many customers to input?"); int addCustomer = Integer.parseInt(nextLine(Message.END_MSG)); int cnt = 1; + while ( cnt <= addCustomer ){ - System.out.println("====== Customer " + cnt + " Info. ======"); - int choice = chooseMenu(new String[]{ - "Customer Name", - "Customer ID", - "Customer Spent Time", - "Customer Total Pay", - "Back"}); - // Customer 에 새로운 고객 추가 - if (choice == 1) addCustomerName(); - else if (choice == 2) addCustomerID(); - else if (choice == 3) addCustomerSpentTime(); - else if (choice == 4) addCustomerTotalPay(); - else cnt++; + String cusName = null; + String cusId = null; + int cusTotalTime = 0; + int cusTotalPay = 0; + + Customer customer = new Customer(cusName, cusId, cusTotalTime, cusTotalPay); + + while ( true ) { + + System.out.println("====== Customer " + cnt + " Info. ======"); + int choice = chooseMenu(new String[]{ + "Customer Name", + "Customer ID", + "Customer Spent Time", + "Customer Total Pay", + "Back"}); + + // Customer 에 새로운 고객 추가 + if (choice == 1) { + cusName = setCustomerName(); + customer.setCusName(cusName); + } else if (choice == 2) { + cusId = setCustomerID(); + customer.setCusId(cusId); + } else if (choice == 3) { + cusTotalTime = setCustomerSpentTime(); + customer.setCusTotalTime(cusTotalTime); + } else if (choice == 4) { + cusTotalPay = setCustomerTotalPay(); + customer.setCusTotalPay(cusTotalPay); + } else { + allCustomers.add(customer); + System.out.println(customer); + cnt++; + break; + } + } } } - private void viewCustomer() { - System.out.println("======= Customer Info. ======="); - allCustomers.viewCustomerData(); + private String setCustomerName() { + while ( true ) { + try { + System.out.println("Input Customer`s Name: "); + String cusName = nextLine(Message.END_MSG); + return cusName; + } 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 updateCustomer() { - System.out.println("updateCustomer 생성중"); - allCustomers.viewCustomerData(); + private String setCustomerID() { while ( true ) { - try{ - int choiceNum = nextLine(allCustomers.size()); -// return choiceNum; - //고객 선택 후 변경 add 할 때의 Customer 내용 셀렉이 또 필요 - } catch (CustomerArrayEmptyException e){ - System.out.println(e.getMessage()); + try { + System.out.println("Input Customer`s Id: "); + String cusName = nextLine(Message.END_MSG); + return cusName; + } 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); } } -// if( allCustomers.size() > 1) { } } - private void deleteCustomer() { - System.out.println("deleteCustomer 생성중"); + private int setCustomerSpentTime() { + while ( true ) { + try { + System.out.println("Input Customer`s Spent Time: "); + String minTime = nextLine(Message.END_MSG); + return Integer.parseInt(minTime); + } catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + return 0; + } catch (IllegalArgumentException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } } - private void addCustomerName() { - System.out.println("addCustomerName 생성중"); + private int setCustomerTotalPay() { + while ( true ) { + try { + System.out.println("Input Customer`s Total Pay: "); + String minPay = nextLine(Message.END_MSG); + return Integer.parseInt(minPay); + } catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + return 0; + } catch (IllegalArgumentException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } } - private void addCustomerID() { - System.out.println("addCustomerID 생성중"); + private void viewCustomer() { + System.out.println("======= Customer Info. ======="); + allCustomers.viewCustomerData(); } - private void addCustomerSpentTime() { - System.out.println("addCustomerSpentTime 생성중"); + private void updateCustomer() { + allCustomers.viewCustomerData(); + int customerIdx = nextLine(allCustomers.size()); + + int saveIdx = allCustomers.findCustomerDataByCusNo(customerIdx); + Customer customer = allCustomers.get(saveIdx); + + String cusName = null; + String cusId = null; + int cusTotalTime = 0; + int cusTotalPay = 0; + + while ( true ) { + + int choice = chooseMenu(new String[]{ + "Customer Name", + "Customer ID", + "Customer Spent Time", + "Customer Total Pay", + "Back"}); + + if (choice == 1) { + cusName = setCustomerName(); + customer.setCusName(cusName); + } else if (choice == 2) { + cusId = setCustomerID(); + customer.setCusId(cusId); + } else if (choice == 3) { + cusTotalTime = setCustomerSpentTime(); + customer.setCusTotalTime(cusTotalTime); + } else if (choice == 4) { + cusTotalPay = setCustomerTotalPay(); + customer.setCusTotalPay(cusTotalPay); + } else { + System.out.println(customer); + allCustomers.set(saveIdx, customer); + manage(); + } + } } - private void addCustomerTotalPay() { - System.out.println("addCustomerTotalPay 생성중"); + private void deleteCustomer() { + allCustomers.viewCustomerData(); + int customerIdx = nextLine(allCustomers.size()); + int saveIdx = allCustomers.findCustomerDataByCusNo(customerIdx); + + allCustomers.pop(saveIdx); } } diff --git a/src/me/smartstore/menu/GroupMenu.java b/src/me/smartstore/menu/GroupMenu.java index e731cb5d..719643e5 100644 --- a/src/me/smartstore/menu/GroupMenu.java +++ b/src/me/smartstore/menu/GroupMenu.java @@ -125,8 +125,8 @@ public int setMinimumTime() { while ( true ) { try { System.out.println("Input Minimum Spent Time: "); - String choice = nextLine(Message.END_MSG); - return Integer.parseInt(choice); + String minTime = nextLine(Message.END_MSG); + return Integer.parseInt(minTime); } catch (InputEndException e) { System.out.println(Message.ERR_MSG_INPUT_END); } catch (IllegalArgumentException e) { @@ -139,8 +139,8 @@ public int setMinimumPay() { while ( true ) { try { System.out.println("Input Minimum Total Pay : "); - String choice = nextLine(Message.END_MSG); - return Integer.parseInt(choice); + String minPay = nextLine(Message.END_MSG); + return Integer.parseInt(minPay); } catch (InputEndException e) { System.out.println(Message.ERR_MSG_INPUT_END); } catch (IllegalArgumentException e) { diff --git a/src/me/smartstore/menu/Menu.java b/src/me/smartstore/menu/Menu.java index 61ae2fc7..d53f4ed8 100644 --- a/src/me/smartstore/menu/Menu.java +++ b/src/me/smartstore/menu/Menu.java @@ -2,9 +2,7 @@ import me.smartstore.exception.InputEndException; import me.smartstore.exception.InputRangeException; -import me.smartstore.group.GroupType; import me.smartstore.utils.Message; - import java.util.InputMismatchException; import java.util.Scanner; @@ -23,19 +21,18 @@ default String nextLine(String end) { } default Integer nextLine(Integer size){ - while ( true ) { + while( true ) { try { System.out.println("Which customer ( 1 ~ " + size + " )?"); - Integer num = scanner.nextInt(); - if(num <= 0 || num > size) throw new InputRangeException(); - return num; - // chooseMenu 로 통합하고 출력문만 변경? - } catch (InputEndException e) { - System.out.println(Message.ERR_MSG_INPUT_END); - return null; - } catch (IllegalArgumentException e) { + int customerIdx = Integer.parseInt(nextLine()); + if (customerIdx > 0 && customerIdx <= size) return customerIdx; + throw new InputRangeException(); + } catch (InputMismatchException | NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } catch (InputRangeException e) { System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); } + } } From 36ec32ec9755c9ebca86f6f81d37edd03b14d0fb Mon Sep 17 00:00:00 2001 From: Ussu1112 Date: Wed, 10 May 2023 19:51:19 +0900 Subject: [PATCH 07/14] =?UTF-8?q?fix:=20refresh()=20=EB=88=84=EB=9D=BD,=20?= =?UTF-8?q?updateParameter=EC=8B=9C=20setParameter=EC=99=80=20=EB=8F=99?= =?UTF-8?q?=EC=9D=BC=ED=95=98=EA=B2=8C=20=EC=9E=91=EB=8F=99=20=ED=95=98?= =?UTF-8?q?=EB=8A=94=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/me/smartstore/menu/CustomerMenu.java | 5 +++ src/me/smartstore/menu/GroupMenu.java | 45 ++++++++++++++++-------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/me/smartstore/menu/CustomerMenu.java b/src/me/smartstore/menu/CustomerMenu.java index 16795ae2..1a235652 100644 --- a/src/me/smartstore/menu/CustomerMenu.java +++ b/src/me/smartstore/menu/CustomerMenu.java @@ -3,11 +3,13 @@ import me.smartstore.customer.Customer; import me.smartstore.customer.Customers; import me.smartstore.exception.InputEndException; +import me.smartstore.group.Groups; import me.smartstore.utils.Message; public class CustomerMenu implements Menu { private static CustomerMenu customerMenu; private final Customers allCustomers = Customers.getInstance(); + private final Groups allGroups = Groups.getInstance(); public static CustomerMenu getInstance() { if(customerMenu == null) { @@ -77,6 +79,7 @@ private void addCustomer() { allCustomers.add(customer); System.out.println(customer); cnt++; + allCustomers.refresh(allGroups); break; } } @@ -184,9 +187,11 @@ private void updateCustomer() { } else { System.out.println(customer); allCustomers.set(saveIdx, customer); + allCustomers.refresh(allGroups); manage(); } } + } private void deleteCustomer() { diff --git a/src/me/smartstore/menu/GroupMenu.java b/src/me/smartstore/menu/GroupMenu.java index 719643e5..f6952f41 100644 --- a/src/me/smartstore/menu/GroupMenu.java +++ b/src/me/smartstore/menu/GroupMenu.java @@ -8,8 +8,6 @@ import me.smartstore.group.Parameter; import me.smartstore.utils.Message; -import java.util.Objects; - public class GroupMenu implements Menu{ private final Groups allGroups = Groups.getInstance(); @@ -47,8 +45,6 @@ public GroupType chooseGroup() { try { System.out.println("Which group (GENERAL (G), VIP (V), VVIP (VV))? "); String choice = nextLine(Message.END_MSG); - // group (str) -> GroupType (enum) - // "VIP" -> GroupType.VIP return GroupType.valueOf(choice).replaceFullName(); } catch (InputEndException e) { System.out.println(Message.ERR_MSG_INPUT_END); @@ -64,7 +60,7 @@ public void setParameter() { // 초기화할 때만 호출 가능 GroupType groupType = chooseGroup(); // GroupType 에 해당하는 group 객체를 찾아야 함 - Group group = allGroups.find(groupType); + Group group = allGroups.findGroupByGroupType(groupType); if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 System.out.println("\n" + group.getGroupType() + " group already exists."); System.out.println("\n" + group); @@ -77,10 +73,21 @@ public void setParameter() { // 초기화할 때만 호출 가능 } public void inputTimeAndPay(GroupType groupType) { - // 함수 진입 시 해당 groupType 으로 Group 생성 - allGroups.add(new Group(new Parameter(null, null), groupType)); + + Group group = null; + int minimumTime = 0; int minimumPay = 0; + + if (allGroups.findGroupByGroupType(groupType) != null) { + group = allGroups.findGroupByGroupType(groupType); + minimumTime = group.getParameter().getMinTime(); + minimumPay = group.getParameter().getMinPay(); + } else { + // add Parameter - 함수 진입 시 해당 groupType 으로 Group 생성 + allGroups.add(new Group(new Parameter(null, null), groupType)); + } + while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while int choice = chooseMenu(new String[]{ @@ -90,16 +97,23 @@ public void inputTimeAndPay(GroupType groupType) { if (choice == 1) minimumTime = setMinimumTime(); else if (choice == 2) minimumPay = setMinimumPay(); - else manage(); // choice == 3 + else { + System.out.println("\n" + group); + manage(); // choice == 3 + } - Group group = allGroups.find(groupType); + group = allGroups.findGroupByGroupType(groupType); group.setParameter(new Parameter(minimumTime, minimumPay)); allGroups.set(allGroups.indexOf(group), group); + // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 + allCustomers.refresh(allGroups); + + // 삭제 + System.out.println("\n" + group); + // Group 내에 있는 다른 그룹 파라미터와 비교? // allGroups.checkGroupParameter(group); - - allCustomers.refresh(allGroups); } } @@ -109,7 +123,7 @@ public void viewParameter() { if (groupType == null) manage(); - Group group = allGroups.find(groupType); + Group group = allGroups.findGroupByGroupType(groupType); if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 System.out.println(group); @@ -154,12 +168,13 @@ public void updateParameter() { while ( true ) { GroupType groupType = chooseGroup(); // GroupType 에 해당하는 group 객체를 찾아야 함 - Group group = allGroups.find(groupType); + Group group = allGroups.findGroupByGroupType(groupType); + if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 + System.out.println("\n" + group); inputTimeAndPay(groupType); - // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 - allCustomers.refresh(allGroups); } else { + // 파라미터가 없는경우 System.out.println(Message.ERR_MSG_INVALID_PARAMETER_ARR_EMPTY); manage(); } From 38f46dd149dd57fb47bd65b4889d851b5ca1bdd5 Mon Sep 17 00:00:00 2001 From: Ussu1112 Date: Wed, 10 May 2023 21:45:55 +0900 Subject: [PATCH 08/14] feat: implement SummaryMenu --- src/me/smartstore/customer/Customer.java | 7 +- src/me/smartstore/customer/Customers.java | 57 +++++++++-- src/me/smartstore/group/Groups.java | 34 +++---- src/me/smartstore/menu/SummaryMenu.java | 112 ++++++++++++++++------ 4 files changed, 151 insertions(+), 59 deletions(-) diff --git a/src/me/smartstore/customer/Customer.java b/src/me/smartstore/customer/Customer.java index 4450c488..a67df37d 100644 --- a/src/me/smartstore/customer/Customer.java +++ b/src/me/smartstore/customer/Customer.java @@ -4,7 +4,7 @@ import java.util.Objects; -public class Customer { +public class Customer implements Comparable { private int cusNo; private String cusId; private String cusName; @@ -106,4 +106,9 @@ public String toString() { ", group=" + group + '}'; } + + @Override + public int compareTo(Customer o) { + return o.getCusNo(); + } } diff --git a/src/me/smartstore/customer/Customers.java b/src/me/smartstore/customer/Customers.java index f0ec2bd5..c8ba44e1 100644 --- a/src/me/smartstore/customer/Customers.java +++ b/src/me/smartstore/customer/Customers.java @@ -3,6 +3,7 @@ import me.smartstore.arrays.DArray; import me.smartstore.group.GroupType; import me.smartstore.group.Groups; +import java.util.Arrays; public class Customers extends DArray { private static Customers allCustomers; @@ -29,19 +30,19 @@ public void refresh(Groups groups) { int cnt = 0; - if (groups.find(GroupType.VVIP) != null) { - VVIPMinTime = groups.find(GroupType.VVIP).getParameter().getMinTime(); - VVIPMinPay = groups.find(GroupType.VVIP).getParameter().getMinPay(); + if (groups.findGroupByGroupType(GroupType.VVIP) != null) { + VVIPMinTime = groups.findGroupByGroupType(GroupType.VVIP).getParameter().getMinTime(); + VVIPMinPay = groups.findGroupByGroupType(GroupType.VVIP).getParameter().getMinPay(); cnt += 4; } - if (groups.find(GroupType.VIP) != null) { - VIPMinTime = groups.find(GroupType.VIP).getParameter().getMinTime(); - VIPMinPay = groups.find(GroupType.VIP).getParameter().getMinPay(); + if (groups.findGroupByGroupType(GroupType.VIP) != null) { + VIPMinTime = groups.findGroupByGroupType(GroupType.VIP).getParameter().getMinTime(); + VIPMinPay = groups.findGroupByGroupType(GroupType.VIP).getParameter().getMinPay(); cnt += 2; } - if (groups.find(GroupType.GENERAL) != null) { - GENERALMinTime = groups.find(GroupType.GENERAL).getParameter().getMinTime(); - GENERALMInPay = groups.find(GroupType.GENERAL).getParameter().getMinPay(); + if (groups.findGroupByGroupType(GroupType.GENERAL) != null) { + GENERALMinTime = groups.findGroupByGroupType(GroupType.GENERAL).getParameter().getMinTime(); + GENERALMInPay = groups.findGroupByGroupType(GroupType.GENERAL).getParameter().getMinPay(); cnt += 1; } @@ -112,7 +113,7 @@ public void viewCustomerData(){ } } - public void viewCustomerData(GroupType groupType) { + public void viewCustomerDataByGroupType(GroupType groupType) { int num = 1; for (int i = 0; i < allCustomers.size; i++){ if( allCustomers.get(i).getGroup() == groupType) { @@ -121,4 +122,40 @@ public void viewCustomerData(GroupType groupType) { } } } + + public void viewCustomerDataByGroupType(GroupType groupType, String sortingMethod, String order) { + int num = 1; + Customer[] customers = new Customer[allCustomers.size]; + for (int i = 0; i < allCustomers.size; i++) { + customers[i] = allCustomers.get(i); + } + + Arrays.sort(customers, (o1, o2) -> { + if (sortingMethod.equals("Name")){ + if (order.equals("A")) + return o1.getCusName().compareTo(o2.getCusName()); + else if (order.equals("D")) + return o2.getCusName().compareTo(o1.getCusName()); + } else if (sortingMethod.equals("SpentTime")) { + if (order.equals("A")) + return o1.getCusTotalTime() - o2.getCusTotalTime(); + else if (order.equals("D")) + return o2.getCusTotalTime() - o1.getCusTotalTime(); + } else if (sortingMethod.equals("TotalPayment")) { + if (order.equals("A")) + return o1.getCusTotalPay() - o2.getCusTotalPay(); + else if (order.equals("D")) + return o2.getCusTotalPay() - o1.getCusTotalPay(); + } + return 0; + }); + + for (int i = 0; i < allCustomers.size; i++) { + if (allCustomers.get(i).getGroup() == groupType) { + System.out.println(customers[i]); + num++; + } + } + } + } diff --git a/src/me/smartstore/group/Groups.java b/src/me/smartstore/group/Groups.java index c7eb268a..88b29359 100644 --- a/src/me/smartstore/group/Groups.java +++ b/src/me/smartstore/group/Groups.java @@ -14,7 +14,7 @@ public static Groups getInstance(){ private Groups() {} - public Group find(GroupType groupType) { + public Group findGroupByGroupType(GroupType groupType) { for (int i = 0; i < allGroups.size; i++) { if (allGroups.get(i).getGroupType() == groupType) { return allGroups.get(i); @@ -23,26 +23,18 @@ public Group find(GroupType groupType) { return null; } - public void checkGroupParameter(Group group) { - // 전달 받은값으로 옳은 값인지 확인 후 적용 - // 이용시간, 금액 General < VIP < VVIP - // 시간 되면 추가하기 - if (group.getParameter().getMinTime() != null - && group.getParameter().getMinPay() != null){ - - } else if (group.getParameter().getMinTime() != null - && group.getParameter().getMinPay() == null){ - - } else if (group.getParameter().getMinTime() == null - && group.getParameter().getMinPay() != null){ - - } else if (group.getParameter().getMinTime() == null - && group.getParameter().getMinPay() == null){ - allGroups.set(allGroups.indexOf(group), group); + public void viewGroupTimeAndPayByGroupType(GroupType groupType){ + + if ( findGroupByGroupType(groupType) == null ) { + System.out.println("Group : " + groupType + + " ( Time : null, Pay : null )" + ); + } else { + System.out.println("Group : " + groupType + + " ( Time : " + findGroupByGroupType(groupType).getParameter().getMinTime() + ", " + + "Pay : " + findGroupByGroupType(groupType).getParameter().getMinPay() + " )" + ); } + System.out.println(findGroupByGroupType(groupType)); } - - - - } diff --git a/src/me/smartstore/menu/SummaryMenu.java b/src/me/smartstore/menu/SummaryMenu.java index 97043c52..d74b4cf9 100644 --- a/src/me/smartstore/menu/SummaryMenu.java +++ b/src/me/smartstore/menu/SummaryMenu.java @@ -1,9 +1,12 @@ package me.smartstore.menu; import me.smartstore.customer.Customers; -import me.smartstore.group.Group; +import me.smartstore.exception.InputEndException; import me.smartstore.group.GroupType; import me.smartstore.group.Groups; +import me.smartstore.utils.Message; +import java.util.Arrays; +import java.util.InputMismatchException; public class SummaryMenu implements Menu { @@ -27,45 +30,100 @@ public void manage() { int choice = chooseMenu(new String[]{ "Summary", "Summary (Sorted By Name)", - "Summary (Sorted By Time)", - "Summary (Sorted By Pay)", + "Summary (Sorted By Spent Time)", + "Summary (Sorted By Total Payment)", "Back"}); if (choice == 1) showSummary(); - else if (choice == 2) showSummarySortedByName(); - else if (choice == 3) showSummarySortedBySpentTime(); - else if (choice == 4) showSummarySortedByTotalPayment(); + else if (choice == 2) showSummarySort("Name"); + else if (choice == 3) showSummarySort("SpentTime"); + else if (choice == 4) showSummarySort("TotalPayment"); else MainMenu.getInstance().manage(); } - - } - private void showSummary() { - //출력문 통합? - - System.out.println("=============================="); - System.out.println("Group : " + GroupType.GENERAL + - " ( Time : " + allGroups.find(GroupType.GENERAL).getParameter().getMinTime() + ", " + - "Pay : " + allGroups.find(GroupType.GENERAL).getParameter().getMinPay() + " )" - ); - System.out.println("=============================="); - allCustomers.viewCustomerData(); -// allCustomers.viewCustomerData(GroupType.GENERAL); - -// System.out.println("Group : " + GroupType.NONE + "( Time" + allGroups.get(GroupType.NONE) + ""); + public GroupType[] distinctGroupTypeList() { + GroupType[] groupType = GroupType.values(); + + for (int i = 0; i < GroupType.values().length; i++) { + groupType[i] = groupType[i].replaceFullName(); + } + + GroupType[] temp = new GroupType[GroupType.values().length]; + int cnt = 0; + + for (int i = 0; i < groupType.length; i++) { + boolean flag = false; + for (int j = i+1; j < groupType.length; j++){ + if (groupType[i].equals(groupType[j])) { + flag= true; + } + } + if (!flag) { + temp[cnt++] = groupType[i]; + } + } + GroupType[] result = new GroupType[cnt]; + + for (int i = 0; i < cnt; i++) { + result[i] = temp[i]; + } + + return result; } - private void showSummarySortedByName() { - System.out.println("showSummarySortedByName 구현"); + private void showSummary() { + GroupType[] groupType = distinctGroupTypeList(); + System.out.println(Arrays.toString(groupType)); + + for (int i = 0; i < groupType.length; i++) { + System.out.println("==============================="); + allGroups.viewGroupTimeAndPayByGroupType(groupType[i]); + System.out.println("==============================="); + allCustomers.viewCustomerDataByGroupType(groupType[i]); + System.out.println("==============================="); + System.out.println(); + } } - private void showSummarySortedBySpentTime() { - System.out.println("showSummarySortedBySpentTime 구현"); + private String getSummaryOrder() { + while ( true ){ + try { + System.out.println("Which order (ASCENDING (A), DESCENDING (D))?"); + String order = nextLine(Message.END_MSG); + if (order.equals("A") || order.equals("D")) return order; + else if (order.equals("end")) { + System.out.println(Message.ERR_MSG_INPUT_END); + return order; + } + throw new InputMismatchException(); + } catch (InputMismatchException e){ + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } + } } - private void showSummarySortedByTotalPayment() { - System.out.println("showSummarySortedByTotalPayment 구현"); + private void showSummarySort(String sortingMethod) { + GroupType[] groupType = distinctGroupTypeList(); + System.out.println(Arrays.toString(groupType)); + + while ( true ){ + try { + String order = getSummaryOrder(); + + for (int i = 0; i < groupType.length; i++) { + System.out.println("==============================="); + allGroups.viewGroupTimeAndPayByGroupType(groupType[i]); + System.out.println("==============================="); + allCustomers.viewCustomerDataByGroupType(groupType[i], sortingMethod, order); + System.out.println("==============================="); + System.out.println(); + } + } catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + manage(); + } + } } } From d7831285cdbb1c0cff66fa1d902fc57327fbc801 Mon Sep 17 00:00:00 2001 From: Ussu1112 Date: Wed, 10 May 2023 22:02:20 +0900 Subject: [PATCH 09/14] =?UTF-8?q?refactor:=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=9C=EB=A0=A5=EB=AC=B8=20=EC=88=98=EC=A0=95,?= =?UTF-8?q?=20=EA=B0=9C=ED=96=89,=20=EC=A3=BC=EC=84=9D,=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=EB=AC=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/me/smartstore/SmartStoreApp.java | 8 +------- src/me/smartstore/arrays/DArray.java | 11 ----------- src/me/smartstore/customer/Customers.java | 3 --- src/me/smartstore/menu/GroupMenu.java | 3 +-- src/me/smartstore/menu/Menu.java | 4 ++-- src/me/smartstore/menu/SummaryMenu.java | 2 +- src/me/smartstore/utils/Message.java | 2 +- 7 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/me/smartstore/SmartStoreApp.java b/src/me/smartstore/SmartStoreApp.java index e0c5251e..819f3f59 100644 --- a/src/me/smartstore/SmartStoreApp.java +++ b/src/me/smartstore/SmartStoreApp.java @@ -38,17 +38,13 @@ public SmartStoreApp test() { 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 < 10; i++) { + 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; // smartStoreApp @@ -57,7 +53,5 @@ public SmartStoreApp test() { public void run() { details(); mainMenu.manage(); - } - } diff --git a/src/me/smartstore/arrays/DArray.java b/src/me/smartstore/arrays/DArray.java index ff633ee8..632d9072 100644 --- a/src/me/smartstore/arrays/DArray.java +++ b/src/me/smartstore/arrays/DArray.java @@ -29,9 +29,6 @@ public DArray(T[] arrays) { size = arrays.length; } - ///////////////////////////////////////// - // add, set, get, pop, indexOf, size, capacity (for dynamic-sized array) - @Override public int size() { return size; @@ -106,12 +103,6 @@ public void add(int index, T object) throws IndexOutOfBoundsException, NullArgum @Override public T pop() { -// if (size == 0) return null; -// -// T popElement = arrays[size-1]; -// arrays[size-1] = null; -// size--; -// return popElement; return pop(size-1); } @@ -139,8 +130,6 @@ public T pop(T object) { protected void grow() { capacity *= 2; // doubling arrays = java.util.Arrays.copyOf(arrays, capacity); - - // size는 그대로 } @Override diff --git a/src/me/smartstore/customer/Customers.java b/src/me/smartstore/customer/Customers.java index c8ba44e1..2d0ce7e0 100644 --- a/src/me/smartstore/customer/Customers.java +++ b/src/me/smartstore/customer/Customers.java @@ -46,7 +46,6 @@ public void refresh(Groups groups) { cnt += 1; } - for (int i = 0; i < allCustomers.size; i++) { cusMinTime = allCustomers.get(i).getCusTotalTime(); cusMinPay = allCustomers.get(i).getCusTotalPay(); @@ -91,7 +90,6 @@ else if (cusMinTime >= GENERALMinTime && cusMinPay >= GENERALMInPay) else allCustomers.get(i).setGroup(GroupType.NONE); } } - System.out.println(allCustomers); } public int findCustomerDataByCusNo(int customerIdx){ @@ -157,5 +155,4 @@ else if (order.equals("D")) } } } - } diff --git a/src/me/smartstore/menu/GroupMenu.java b/src/me/smartstore/menu/GroupMenu.java index f6952f41..82c5fbcc 100644 --- a/src/me/smartstore/menu/GroupMenu.java +++ b/src/me/smartstore/menu/GroupMenu.java @@ -47,7 +47,7 @@ public GroupType chooseGroup() { String choice = nextLine(Message.END_MSG); return GroupType.valueOf(choice).replaceFullName(); } catch (InputEndException e) { - System.out.println(Message.ERR_MSG_INPUT_END); + System.out.println(e.getMessage()); return null; } catch (IllegalArgumentException e) { System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); @@ -179,6 +179,5 @@ public void updateParameter() { manage(); } } - } } diff --git a/src/me/smartstore/menu/Menu.java b/src/me/smartstore/menu/Menu.java index d53f4ed8..73e726f8 100644 --- a/src/me/smartstore/menu/Menu.java +++ b/src/me/smartstore/menu/Menu.java @@ -30,7 +30,7 @@ default Integer nextLine(Integer size){ } catch (InputMismatchException | NumberFormatException e) { System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); } catch (InputRangeException e) { - System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + System.out.println(e.getMessage()); } } @@ -51,7 +51,7 @@ default int chooseMenu(String[] menus) { } catch (InputMismatchException | NumberFormatException e){ System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); } catch (InputRangeException e) { - System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + System.out.println(e.getMessage()); } } } diff --git a/src/me/smartstore/menu/SummaryMenu.java b/src/me/smartstore/menu/SummaryMenu.java index d74b4cf9..1f8897a6 100644 --- a/src/me/smartstore/menu/SummaryMenu.java +++ b/src/me/smartstore/menu/SummaryMenu.java @@ -120,7 +120,7 @@ private void showSummarySort(String sortingMethod) { System.out.println(); } } catch (InputEndException e) { - System.out.println(Message.ERR_MSG_INPUT_END); + System.out.println(e.getMessage());; manage(); } } diff --git a/src/me/smartstore/utils/Message.java b/src/me/smartstore/utils/Message.java index 9a3560b5..730c84da 100644 --- a/src/me/smartstore/utils/Message.java +++ b/src/me/smartstore/utils/Message.java @@ -10,6 +10,6 @@ public interface Message { 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 ERR_MSG_INPUT_END = "END is pressed. Exit this menu. \n"; String END_MSG = "END"; } From 35d53a8901f70820bb4fc5ea69d9e0009a368f02 Mon Sep 17 00:00:00 2001 From: Ussu1112 Date: Wed, 10 May 2023 22:22:28 +0900 Subject: [PATCH 10/14] =?UTF-8?q?fix:=20SetParameter=20end=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/me/smartstore/menu/GroupMenu.java | 7 +++++++ src/me/smartstore/utils/Message.java | 1 + 2 files changed, 8 insertions(+) diff --git a/src/me/smartstore/menu/GroupMenu.java b/src/me/smartstore/menu/GroupMenu.java index 82c5fbcc..f303001b 100644 --- a/src/me/smartstore/menu/GroupMenu.java +++ b/src/me/smartstore/menu/GroupMenu.java @@ -59,6 +59,13 @@ public void setParameter() { // 초기화할 때만 호출 가능 while ( true ) { GroupType groupType = chooseGroup(); + // end 키 입력 시 또는 N, NONE 설정 시도 시 메인 메뉴로 + if (groupType == null) manage(); + else if (groupType == GroupType.NONE) { + System.out.println(Message.ERR_MSG_INPUT_NONE); + manage(); + } + // GroupType 에 해당하는 group 객체를 찾아야 함 Group group = allGroups.findGroupByGroupType(groupType); if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 diff --git a/src/me/smartstore/utils/Message.java b/src/me/smartstore/utils/Message.java index 730c84da..68b664ff 100644 --- a/src/me/smartstore/utils/Message.java +++ b/src/me/smartstore/utils/Message.java @@ -11,5 +11,6 @@ public interface Message { 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. \n"; + String ERR_MSG_INPUT_NONE = "None(GroupType)`s cannot be changed"; String END_MSG = "END"; } From b59ddd046fa41d89ed7b5244c7586ebc08d799e8 Mon Sep 17 00:00:00 2001 From: Ussu1112 Date: Wed, 10 May 2023 22:27:30 +0900 Subject: [PATCH 11/14] =?UTF-8?q?fix:=20updateParameter=20GroupType.NONE?= =?UTF-8?q?=20=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/me/smartstore/menu/GroupMenu.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/me/smartstore/menu/GroupMenu.java b/src/me/smartstore/menu/GroupMenu.java index f303001b..0d8056ac 100644 --- a/src/me/smartstore/menu/GroupMenu.java +++ b/src/me/smartstore/menu/GroupMenu.java @@ -171,9 +171,15 @@ public int setMinimumPay() { } public void updateParameter() { - while ( true ) { GroupType groupType = chooseGroup(); + + if (groupType == null) manage(); + else if (groupType == GroupType.NONE) { + System.out.println(Message.ERR_MSG_INPUT_NONE); + manage(); + } + // GroupType 에 해당하는 group 객체를 찾아야 함 Group group = allGroups.findGroupByGroupType(groupType); From eb1837d57c6134ae360b10967a34df35987e3af0 Mon Sep 17 00:00:00 2001 From: Ussu1112 Date: Wed, 10 May 2023 23:20:47 +0900 Subject: [PATCH 12/14] =?UTF-8?q?fix:=20delete=20Customer=EC=8B=9C=20Index?= =?UTF-8?q?OutOfBoundsException=20error=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CusNo를 선언하고 대입하여 사용하였지만 삭제 시에 CusNo를 별도로 선언 하지않아 문제 발생 --- src/me/smartstore/SmartStoreApp.java | 2 +- src/me/smartstore/customer/Customer.java | 7 +++++-- src/me/smartstore/customer/Customers.java | 13 ++++++++----- src/me/smartstore/menu/CustomerMenu.java | 14 +++++++++++--- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/me/smartstore/SmartStoreApp.java b/src/me/smartstore/SmartStoreApp.java index 819f3f59..c4562e32 100644 --- a/src/me/smartstore/SmartStoreApp.java +++ b/src/me/smartstore/SmartStoreApp.java @@ -42,7 +42,7 @@ public SmartStoreApp test() { allCustomers.add(new Customer( Character.toString((char) ('a' + i)), (char) ('a' + i) + "123", - ((int) (Math.random() * 5) + 1) * 10, + ((int) (Math.random() * 10) + 1) * 5, ((int) (Math.random() * 5) + 1) * 100000)); } allCustomers.refresh(allGroups); diff --git a/src/me/smartstore/customer/Customer.java b/src/me/smartstore/customer/Customer.java index a67df37d..73a3c2ce 100644 --- a/src/me/smartstore/customer/Customer.java +++ b/src/me/smartstore/customer/Customer.java @@ -42,6 +42,10 @@ public int getCusNo() { return cusNo; } + public void setCusNo(int cusNo) { + this.cusNo = cusNo; + } + public String getCusName() { return cusName; } @@ -97,8 +101,7 @@ public int hashCode() { @Override public String toString() { - return "No. " + cusNo + " => " + - "Customer{" + + return "Customer{" + "cusName='" + cusName + '\'' + ", cusId='" + cusId + '\'' + ", cusTotalTime=" + cusTotalTime + diff --git a/src/me/smartstore/customer/Customers.java b/src/me/smartstore/customer/Customers.java index 2d0ce7e0..17b7b676 100644 --- a/src/me/smartstore/customer/Customers.java +++ b/src/me/smartstore/customer/Customers.java @@ -104,18 +104,21 @@ public int findCustomerDataByCusNo(int customerIdx){ } public void viewCustomerData(){ - int num = 1; for (int i = 0; i < allCustomers.size; i++){ - System.out.println(allCustomers.get(i)); - num++; + System.out.println("No. "+ allCustomers.get(i).getCusNo() + + " => " + allCustomers.get(i)); } } public void viewCustomerDataByGroupType(GroupType groupType) { int num = 1; + Customer[] customers = new Customer[allCustomers.size]; + for (int i = 0; i < allCustomers.size; i++) { + customers[i] = allCustomers.get(i); + } for (int i = 0; i < allCustomers.size; i++){ if( allCustomers.get(i).getGroup() == groupType) { - System.out.println(allCustomers.get(i)); + System.out.println("No. "+ num + " => " + customers[i]); num++; } } @@ -150,7 +153,7 @@ else if (order.equals("D")) for (int i = 0; i < allCustomers.size; i++) { if (allCustomers.get(i).getGroup() == groupType) { - System.out.println(customers[i]); + System.out.println("No. "+ num + " => " + customers[i]); num++; } } diff --git a/src/me/smartstore/menu/CustomerMenu.java b/src/me/smartstore/menu/CustomerMenu.java index 1a235652..0ffaeab7 100644 --- a/src/me/smartstore/menu/CustomerMenu.java +++ b/src/me/smartstore/menu/CustomerMenu.java @@ -77,9 +77,9 @@ private void addCustomer() { customer.setCusTotalPay(cusTotalPay); } else { allCustomers.add(customer); + allCustomers.refresh(allGroups); System.out.println(customer); cnt++; - allCustomers.refresh(allGroups); break; } } @@ -185,13 +185,12 @@ private void updateCustomer() { cusTotalPay = setCustomerTotalPay(); customer.setCusTotalPay(cusTotalPay); } else { - System.out.println(customer); allCustomers.set(saveIdx, customer); allCustomers.refresh(allGroups); + System.out.println(customer); manage(); } } - } private void deleteCustomer() { @@ -199,6 +198,15 @@ private void deleteCustomer() { int customerIdx = nextLine(allCustomers.size()); int saveIdx = allCustomers.findCustomerDataByCusNo(customerIdx); + // customer 삭제 allCustomers.pop(saveIdx); + + // allCustomer 의 CusNo index 당기기 + for (int i = saveIdx; i < allCustomers.size(); i++) { + Customer customer = allCustomers.get(i); + System.out.println(customer); + customer.setCusNo(customer.getCusNo()-1); + allCustomers.set(i, customer); + } } } From b5e80d654efb8266daeb8c8c2bfa4c7a1590d6a7 Mon Sep 17 00:00:00 2001 From: Ussu1112 Date: Fri, 12 May 2023 22:43:15 +0900 Subject: [PATCH 13/14] =?UTF-8?q?refactor:=20=EC=8B=B1=EA=B8=80=ED=86=A4?= =?UTF-8?q?=20=EA=B0=9D=EC=B2=B4=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=A3=BC?= =?UTF-8?q?=EC=9E=85=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD,=20Customer=20?= =?UTF-8?q?=EC=B4=88=EA=B8=B0=20=EA=B0=92=20=EC=84=A4=EC=A0=95=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/me/smartstore/SmartStoreApp.java | 13 ++++++++----- src/me/smartstore/customer/Customer.java | 13 ++++--------- src/me/smartstore/menu/CustomerMenu.java | 18 ++++++++++-------- src/me/smartstore/menu/GroupMenu.java | 11 +++++++---- src/me/smartstore/menu/MainMenu.java | 14 +++++++++----- src/me/smartstore/menu/SummaryMenu.java | 9 ++++++--- 6 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/me/smartstore/SmartStoreApp.java b/src/me/smartstore/SmartStoreApp.java index c4562e32..284d3d76 100644 --- a/src/me/smartstore/SmartStoreApp.java +++ b/src/me/smartstore/SmartStoreApp.java @@ -10,10 +10,9 @@ public class SmartStoreApp { - private final Groups allGroups = Groups.getInstance(); - private final Customers allCustomers = Customers.getInstance(); - private final MainMenu mainMenu = MainMenu.getInstance(); - + private Groups allGroups; + private Customers allCustomers; + private final MainMenu mainMenu; private static SmartStoreApp smartStoreApp; public static SmartStoreApp getInstance() { @@ -23,7 +22,11 @@ public static SmartStoreApp getInstance() { return smartStoreApp; } - private SmartStoreApp() {} + private SmartStoreApp() { + this.allCustomers = Customers.getInstance(); + this.allGroups = Groups.getInstance(); + this.mainMenu = MainMenu.getInstance(); + } public void details() { System.out.println("\n\n==========================================="); diff --git a/src/me/smartstore/customer/Customer.java b/src/me/smartstore/customer/Customer.java index 73a3c2ce..37a9fc15 100644 --- a/src/me/smartstore/customer/Customer.java +++ b/src/me/smartstore/customer/Customer.java @@ -17,19 +17,14 @@ public class Customer implements Comparable { public Customer() { //초기 값 설정 cusNo = seqNum; + cusId = null; + cusName = null; + cusTotalTime = 0; + cusTotalPay = 0; group = GroupType.NONE; seqNum++; } - 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, Integer cusTotalTime, Integer cusTotalPay) { this(); this.cusName = cusName; diff --git a/src/me/smartstore/menu/CustomerMenu.java b/src/me/smartstore/menu/CustomerMenu.java index 0ffaeab7..6074596a 100644 --- a/src/me/smartstore/menu/CustomerMenu.java +++ b/src/me/smartstore/menu/CustomerMenu.java @@ -8,8 +8,7 @@ public class CustomerMenu implements Menu { private static CustomerMenu customerMenu; - private final Customers allCustomers = Customers.getInstance(); - private final Groups allGroups = Groups.getInstance(); + private Customers allCustomers; public static CustomerMenu getInstance() { if(customerMenu == null) { @@ -18,7 +17,12 @@ public static CustomerMenu getInstance() { return customerMenu; } - private CustomerMenu() {} + private CustomerMenu() { + this.allCustomers = Customers.getInstance(); + } + + + private final Groups allGroups = Groups.getInstance(); @Override public void manage() { @@ -50,7 +54,7 @@ private void addCustomer() { int cusTotalTime = 0; int cusTotalPay = 0; - Customer customer = new Customer(cusName, cusId, cusTotalTime, cusTotalPay); + Customer customer = new Customer(); while ( true ) { @@ -90,8 +94,7 @@ private String setCustomerName() { while ( true ) { try { System.out.println("Input Customer`s Name: "); - String cusName = nextLine(Message.END_MSG); - return cusName; + return nextLine(Message.END_MSG); } catch (InputEndException e) { System.out.println(Message.ERR_MSG_INPUT_END); return null; @@ -105,8 +108,7 @@ private String setCustomerID() { while ( true ) { try { System.out.println("Input Customer`s Id: "); - String cusName = nextLine(Message.END_MSG); - return cusName; + return nextLine(Message.END_MSG); } catch (InputEndException e) { System.out.println(Message.ERR_MSG_INPUT_END); return null; diff --git a/src/me/smartstore/menu/GroupMenu.java b/src/me/smartstore/menu/GroupMenu.java index 0d8056ac..fbeb2cd3 100644 --- a/src/me/smartstore/menu/GroupMenu.java +++ b/src/me/smartstore/menu/GroupMenu.java @@ -10,11 +10,11 @@ public class GroupMenu implements Menu{ - private final Groups allGroups = Groups.getInstance(); - private final Customers allCustomers = Customers.getInstance(); - private static GroupMenu groupMenu; + private final Groups allGroups; + private final Customers allCustomers; + public static GroupMenu getInstance() { if(groupMenu == null) { groupMenu = new GroupMenu(); @@ -22,7 +22,10 @@ public static GroupMenu getInstance() { return groupMenu; } - private GroupMenu() {} + private GroupMenu() { + this.allGroups = Groups.getInstance(); + this.allCustomers = Customers.getInstance(); + } @Override public void manage() { diff --git a/src/me/smartstore/menu/MainMenu.java b/src/me/smartstore/menu/MainMenu.java index 4157d531..04491f75 100644 --- a/src/me/smartstore/menu/MainMenu.java +++ b/src/me/smartstore/menu/MainMenu.java @@ -2,12 +2,12 @@ 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; + private final CustomerMenu customerMenu; + private final GroupMenu groupMenu; + private final SummaryMenu summaryMenu; + public static MainMenu getInstance(){ if(mainMenu == null){ mainMenu = new MainMenu(); @@ -15,7 +15,11 @@ public static MainMenu getInstance(){ return mainMenu; } - private MainMenu() {} + private MainMenu() { + this.customerMenu = CustomerMenu.getInstance(); + this.groupMenu = GroupMenu.getInstance(); + this.summaryMenu = SummaryMenu.getInstance(); + } @Override public void manage() { diff --git a/src/me/smartstore/menu/SummaryMenu.java b/src/me/smartstore/menu/SummaryMenu.java index 1f8897a6..2bf1da60 100644 --- a/src/me/smartstore/menu/SummaryMenu.java +++ b/src/me/smartstore/menu/SummaryMenu.java @@ -12,8 +12,8 @@ public class SummaryMenu implements Menu { private static SummaryMenu summaryMenu; - private final Groups allGroups = Groups.getInstance(); - private final Customers allCustomers = Customers.getInstance(); + private final Groups allGroups; + private final Customers allCustomers; public static SummaryMenu getInstance(){ if(summaryMenu == null) { @@ -22,7 +22,10 @@ public static SummaryMenu getInstance(){ return summaryMenu; } - private SummaryMenu() {} + private SummaryMenu() { + this.allGroups = Groups.getInstance(); + this.allCustomers = Customers.getInstance(); + } @Override public void manage() { From c5e7bf903f6fd18017dcc52760e1d5e00638d6c2 Mon Sep 17 00:00:00 2001 From: Ussu1112 Date: Fri, 12 May 2023 23:02:34 +0900 Subject: [PATCH 14/14] =?UTF-8?q?refactor:=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C,=20Parameter=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/me/smartstore/Main.java | 2 +- src/me/smartstore/SmartStoreApp.java | 12 +++---- src/me/smartstore/arrays/DArray.java | 12 +++---- src/me/smartstore/customer/Customer.java | 3 +- src/me/smartstore/customer/Customers.java | 3 -- src/me/smartstore/group/Group.java | 20 +++++------ .../{Parameter.java => GroupConditions.java} | 12 +++---- src/me/smartstore/menu/CustomerMenu.java | 5 +-- src/me/smartstore/menu/GroupMenu.java | 34 ++++++------------- src/me/smartstore/menu/MainMenu.java | 4 +-- src/me/smartstore/menu/Menu.java | 4 +-- src/me/smartstore/menu/SummaryMenu.java | 2 +- 12 files changed, 45 insertions(+), 68 deletions(-) rename src/me/smartstore/group/{Parameter.java => GroupConditions.java} (72%) diff --git a/src/me/smartstore/Main.java b/src/me/smartstore/Main.java index 291f0fa5..8cd59151 100644 --- a/src/me/smartstore/Main.java +++ b/src/me/smartstore/Main.java @@ -2,7 +2,7 @@ public class Main { public static void main(String[] args) { - SmartStoreApp.getInstance().test().run(); // function chaining + SmartStoreApp.getInstance().test().run(); // SmartStoreApp.getInstance().run(); } } diff --git a/src/me/smartstore/SmartStoreApp.java b/src/me/smartstore/SmartStoreApp.java index 284d3d76..7b7f8cf3 100644 --- a/src/me/smartstore/SmartStoreApp.java +++ b/src/me/smartstore/SmartStoreApp.java @@ -5,14 +5,14 @@ import me.smartstore.group.Group; import me.smartstore.group.GroupType; import me.smartstore.group.Groups; -import me.smartstore.group.Parameter; +import me.smartstore.group.GroupConditions; import me.smartstore.menu.MainMenu; public class SmartStoreApp { private Groups allGroups; private Customers allCustomers; - private final MainMenu mainMenu; + private MainMenu mainMenu; private static SmartStoreApp smartStoreApp; public static SmartStoreApp getInstance() { @@ -37,9 +37,9 @@ public void details() { } 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)); + allGroups.add(new Group(new GroupConditions(10, 100000), GroupType.GENERAL)); + allGroups.add(new Group(new GroupConditions(20, 200000), GroupType.VIP)); + allGroups.add(new Group(new GroupConditions(30, 300000), GroupType.VVIP)); for (int i = 0; i < 26; i++) { allCustomers.add(new Customer( @@ -50,7 +50,7 @@ public SmartStoreApp test() { } allCustomers.refresh(allGroups); - return this; // smartStoreApp + return this; } public void run() { diff --git a/src/me/smartstore/arrays/DArray.java b/src/me/smartstore/arrays/DArray.java index 632d9072..677ee36e 100644 --- a/src/me/smartstore/arrays/DArray.java +++ b/src/me/smartstore/arrays/DArray.java @@ -34,7 +34,6 @@ public int size() { return size; } - // 배열에 얼마나 capacity 남아있는지 외부에 알려줄 필요가 없기 때문에 으로 정의 protected int capacity() { return capacity; } @@ -61,19 +60,18 @@ public void set(int index, T object) throws IndexOutOfBoundsException, NullArgum @Override public int indexOf(T object) throws NullArgumentException, ElementNotFoundException { - if (object == null) throw new NullArgumentException(); // 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 + throw new ElementNotFoundException(); } - // 배열의 cap이 부족한 경우 @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 (object == null) throw new NullArgumentException(); if (size < capacity) { arrays[size] = object; @@ -112,7 +110,7 @@ public T pop(int index) throws IndexOutOfBoundsException { if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); T popElement = arrays[index]; - arrays[index] = null; // 삭제됨을 명시적으로 표현 + arrays[index] = null; for (int i = index+1; i < size; i++) { arrays[i-1] = arrays[i]; @@ -128,7 +126,7 @@ public T pop(T object) { } protected void grow() { - capacity *= 2; // doubling + capacity *= 2; arrays = java.util.Arrays.copyOf(arrays, capacity); } diff --git a/src/me/smartstore/customer/Customer.java b/src/me/smartstore/customer/Customer.java index 37a9fc15..82c452e4 100644 --- a/src/me/smartstore/customer/Customer.java +++ b/src/me/smartstore/customer/Customer.java @@ -10,12 +10,11 @@ public class Customer implements Comparable { private String cusName; private Integer cusTotalTime; private Integer cusTotalPay; - private GroupType group; // 현재 분류 기준에 의해 각 고객을 분류된 결과 + private GroupType group; private static int seqNum = 1; public Customer() { - //초기 값 설정 cusNo = seqNum; cusId = null; cusName = null; diff --git a/src/me/smartstore/customer/Customers.java b/src/me/smartstore/customer/Customers.java index 17b7b676..a424bbc7 100644 --- a/src/me/smartstore/customer/Customers.java +++ b/src/me/smartstore/customer/Customers.java @@ -17,9 +17,6 @@ public static Customers getInstance() { private Customers() {} - // refresh 함수가 호출되는 경우 - // 1. 분류기준 바뀔 때 - // 2. 새로운 고객이 들어올 때 public void refresh(Groups groups) { int cusMinTime; int cusMinPay; diff --git a/src/me/smartstore/group/Group.java b/src/me/smartstore/group/Group.java index f69711fa..29ac4879 100644 --- a/src/me/smartstore/group/Group.java +++ b/src/me/smartstore/group/Group.java @@ -3,23 +3,23 @@ import java.util.Objects; public class Group { - private Parameter parameter; + private GroupConditions groupConditions; private GroupType groupType; public Group() { } - public Group(Parameter parameter, GroupType groupType) { - this.parameter = parameter; + public Group(GroupConditions groupConditions, GroupType groupType) { + this.groupConditions = groupConditions; this.groupType = groupType; } - public Parameter getParameter() { - return parameter; + public GroupConditions getParameter() { + return groupConditions; } - public void setParameter(Parameter parameter) { - this.parameter = parameter; + public void setParameter(GroupConditions groupConditions) { + this.groupConditions = groupConditions; } public GroupType getGroupType() { @@ -35,17 +35,17 @@ 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; + return Objects.equals(groupConditions, group.groupConditions) && groupType == group.groupType; } @Override public int hashCode() { - return Objects.hash(parameter, groupType); + return Objects.hash(groupConditions, groupType); } @Override public String toString() { return "GroupType=" + groupType +"\n" + - "Parameter=" + parameter; + "Parameter=" + groupConditions; } } diff --git a/src/me/smartstore/group/Parameter.java b/src/me/smartstore/group/GroupConditions.java similarity index 72% rename from src/me/smartstore/group/Parameter.java rename to src/me/smartstore/group/GroupConditions.java index c2b0b3b0..a0c5120a 100644 --- a/src/me/smartstore/group/Parameter.java +++ b/src/me/smartstore/group/GroupConditions.java @@ -2,14 +2,14 @@ import java.util.Objects; -public class Parameter { +public class GroupConditions { private Integer minTime; private Integer minPay; - public Parameter() { + public GroupConditions() { } - public Parameter(Integer minTime, Integer minPay) { + public GroupConditions(Integer minTime, Integer minPay) { this.minTime = minTime; this.minPay = minPay; } @@ -34,8 +34,8 @@ public void setMinPay(Integer minPay) { 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); + GroupConditions groupConditions = (GroupConditions) o; + return Objects.equals(minTime, groupConditions.minTime) && Objects.equals(minPay, groupConditions.minPay); } @Override @@ -45,7 +45,7 @@ public int hashCode() { @Override public String toString() { - return "Parameter{" + + return "GroupConditions{" + "minTime=" + minTime + ", minPay=" + minPay + '}'; diff --git a/src/me/smartstore/menu/CustomerMenu.java b/src/me/smartstore/menu/CustomerMenu.java index 6074596a..e1d814e9 100644 --- a/src/me/smartstore/menu/CustomerMenu.java +++ b/src/me/smartstore/menu/CustomerMenu.java @@ -26,7 +26,7 @@ private CustomerMenu() { @Override public void manage() { - while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while + while ( true ) { int choice = chooseMenu(new String[]{ "Add Customer Data", "View Customer Data", @@ -66,7 +66,6 @@ private void addCustomer() { "Customer Total Pay", "Back"}); - // Customer 에 새로운 고객 추가 if (choice == 1) { cusName = setCustomerName(); customer.setCusName(cusName); @@ -200,10 +199,8 @@ private void deleteCustomer() { int customerIdx = nextLine(allCustomers.size()); int saveIdx = allCustomers.findCustomerDataByCusNo(customerIdx); - // customer 삭제 allCustomers.pop(saveIdx); - // allCustomer 의 CusNo index 당기기 for (int i = saveIdx; i < allCustomers.size(); i++) { Customer customer = allCustomers.get(i); System.out.println(customer); diff --git a/src/me/smartstore/menu/GroupMenu.java b/src/me/smartstore/menu/GroupMenu.java index fbeb2cd3..16e8e42b 100644 --- a/src/me/smartstore/menu/GroupMenu.java +++ b/src/me/smartstore/menu/GroupMenu.java @@ -5,7 +5,7 @@ import me.smartstore.group.Group; import me.smartstore.group.GroupType; import me.smartstore.group.Groups; -import me.smartstore.group.Parameter; +import me.smartstore.group.GroupConditions; import me.smartstore.utils.Message; public class GroupMenu implements Menu{ @@ -29,7 +29,7 @@ private GroupMenu() { @Override public void manage() { - while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while + while ( true ) { int choice = chooseMenu(new String[]{ "Set Parameter", "View Parameter", @@ -58,25 +58,22 @@ public GroupType chooseGroup() { } } - public void setParameter() { // 초기화할 때만 호출 가능 + public void setParameter() { while ( true ) { GroupType groupType = chooseGroup(); - // end 키 입력 시 또는 N, NONE 설정 시도 시 메인 메뉴로 if (groupType == null) manage(); else if (groupType == GroupType.NONE) { System.out.println(Message.ERR_MSG_INPUT_NONE); manage(); } - // GroupType 에 해당하는 group 객체를 찾아야 함 Group group = allGroups.findGroupByGroupType(groupType); - if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 + if (group != null && group.getParameter() != null) { System.out.println("\n" + group.getGroupType() + " group already exists."); System.out.println("\n" + group); } else { inputTimeAndPay(groupType); - // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 allCustomers.refresh(allGroups); } } @@ -94,11 +91,10 @@ public void inputTimeAndPay(GroupType groupType) { minimumTime = group.getParameter().getMinTime(); minimumPay = group.getParameter().getMinPay(); } else { - // add Parameter - 함수 진입 시 해당 groupType 으로 Group 생성 - allGroups.add(new Group(new Parameter(null, null), groupType)); + allGroups.add(new Group(new GroupConditions(null, null), groupType)); } - while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while + while ( true ) { int choice = chooseMenu(new String[]{ "Minimum Spent Time", @@ -109,21 +105,14 @@ public void inputTimeAndPay(GroupType groupType) { else if (choice == 2) minimumPay = setMinimumPay(); else { System.out.println("\n" + group); - manage(); // choice == 3 + manage(); } group = allGroups.findGroupByGroupType(groupType); - group.setParameter(new Parameter(minimumTime, minimumPay)); + group.setParameter(new GroupConditions(minimumTime, minimumPay)); allGroups.set(allGroups.indexOf(group), group); - // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 allCustomers.refresh(allGroups); - - // 삭제 - System.out.println("\n" + group); - - // Group 내에 있는 다른 그룹 파라미터와 비교? - // allGroups.checkGroupParameter(group); } } @@ -135,10 +124,9 @@ public void viewParameter() { Group group = allGroups.findGroupByGroupType(groupType); - if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 + if (group != null && group.getParameter() != null) { System.out.println(group); } else if (group == null){ - // 출력문으로 표시하지 않고 null 일 때 null 로 어떻게 출력하는가.. System.out.println("GroupType: " + groupType); System.out.println("Parameter: " + null); } @@ -183,14 +171,12 @@ else if (groupType == GroupType.NONE) { manage(); } - // GroupType 에 해당하는 group 객체를 찾아야 함 Group group = allGroups.findGroupByGroupType(groupType); - if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 + if (group != null && group.getParameter() != null) { System.out.println("\n" + group); inputTimeAndPay(groupType); } else { - // 파라미터가 없는경우 System.out.println(Message.ERR_MSG_INVALID_PARAMETER_ARR_EMPTY); manage(); } diff --git a/src/me/smartstore/menu/MainMenu.java b/src/me/smartstore/menu/MainMenu.java index 04491f75..299764dd 100644 --- a/src/me/smartstore/menu/MainMenu.java +++ b/src/me/smartstore/menu/MainMenu.java @@ -23,7 +23,7 @@ private MainMenu() { @Override public void manage() { - while ( true ) { // 프로그램 실행 while + while ( true ) { int choice = mainMenu.chooseMenu(new String[] { "Parameter", "Customer", @@ -33,7 +33,7 @@ public void manage() { if (choice == 1) groupMenu.manage(); else if (choice == 2) customerMenu.manage(); else if (choice == 3) summaryMenu.manage(); - else { // choice == 4 + else { System.out.println("Program Finished"); break; } diff --git a/src/me/smartstore/menu/Menu.java b/src/me/smartstore/menu/Menu.java index 73e726f8..2033c023 100644 --- a/src/me/smartstore/menu/Menu.java +++ b/src/me/smartstore/menu/Menu.java @@ -47,7 +47,7 @@ default int chooseMenu(String[] menus) { System.out.print("Choose One: "); int choice = Integer.parseInt(nextLine()); if (choice >= 1 && choice <= menus.length) return choice; - throw new InputRangeException(); // choice 가 범위에 벗어남 + throw new InputRangeException(); } catch (InputMismatchException | NumberFormatException e){ System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); } catch (InputRangeException e) { @@ -56,5 +56,5 @@ default int chooseMenu(String[] menus) { } } - void manage(); // 각 서브메뉴들을 관리하는 함수 (각 서브메뉴의 최상위 메뉴) + void manage(); } diff --git a/src/me/smartstore/menu/SummaryMenu.java b/src/me/smartstore/menu/SummaryMenu.java index 2bf1da60..560ecbde 100644 --- a/src/me/smartstore/menu/SummaryMenu.java +++ b/src/me/smartstore/menu/SummaryMenu.java @@ -29,7 +29,7 @@ private SummaryMenu() { @Override public void manage() { - while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while + while ( true ) { int choice = chooseMenu(new String[]{ "Summary", "Summary (Sorted By Name)",