From d06259453426e291e766773d0f993b6dbd89637f Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Wed, 3 May 2023 20:52:58 +0900 Subject: [PATCH 01/30] =?UTF-8?q?Feat:=20Collections=20=EC=9D=B8=ED=84=B0?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=8A=A4,=20DArray=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 코드 --- me/smartstore/arrays/Collections.java | 16 +++ me/smartstore/arrays/DArray.java | 145 ++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 me/smartstore/arrays/Collections.java create mode 100644 me/smartstore/arrays/DArray.java diff --git a/me/smartstore/arrays/Collections.java b/me/smartstore/arrays/Collections.java new file mode 100644 index 00000000..847ada31 --- /dev/null +++ b/me/smartstore/arrays/Collections.java @@ -0,0 +1,16 @@ +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/me/smartstore/arrays/DArray.java b/me/smartstore/arrays/DArray.java new file mode 100644 index 00000000..97f65ff9 --- /dev/null +++ b/me/smartstore/arrays/DArray.java @@ -0,0 +1,145 @@ +package me.smartstore.arrays; + +import me.smartstore.exception.ElementNotFoundException; +import me.smartstore.exception.EmptyArrayException; +import me.smartstore.exception.NullArgumentException; + +public class DArray implements Collections { // Dynamic Array + + protected static final int DEFAULT = 10; + + protected T[] arrays; + protected int size; + protected int capacity; + + public DArray() throws ClassCastException { + arrays = (T[]) new Object[DEFAULT]; + capacity = DEFAULT; + } + + 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() { + return pop(size-1); + } + + @Override + public T pop(int index) throws IndexOutOfBoundsException { + if (size == 0) throw new EmptyArrayException(); + if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); + + T popElement = arrays[index]; + arrays[index] = null; // 삭제됨을 명시적으로 표현 + + for (int i = index+1; i < size; i++) { + arrays[i-1] = arrays[i]; + } + arrays[size-1] = null; + size--; + return popElement; + } + + @Override + public T pop(T object) { + return pop(indexOf(object)); + } + + protected void grow() { + capacity *= 2; + arrays = java.util.Arrays.copyOf(arrays, capacity); + } + + @Override + public String toString() { + String toStr = ""; + for (int i = 0; i < size; i++) { + toStr += (arrays[i] + "\n"); + } + return toStr; + } +} From 358e961b87995848f8f3a162331ee18773af7b07 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Wed, 3 May 2023 21:08:27 +0900 Subject: [PATCH 02/30] =?UTF-8?q?Feat:=20Customer,=20Customers=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 코드에 refresh 함수 구현 --- me/smartstore/customer/Customer.java | 111 ++++++++++++++++++++++++++ me/smartstore/customer/Customers.java | 34 ++++++++ 2 files changed, 145 insertions(+) create mode 100644 me/smartstore/customer/Customer.java create mode 100644 me/smartstore/customer/Customers.java diff --git a/me/smartstore/customer/Customer.java b/me/smartstore/customer/Customer.java new file mode 100644 index 00000000..175596d0 --- /dev/null +++ b/me/smartstore/customer/Customer.java @@ -0,0 +1,111 @@ +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, Group group) { + this.cusName = cusName; + this.cusId = cusId; + this.cusTotalTime = cusTotalTime; + this.cusTotalPay = cusTotalPay; + this.group = group; + } + + public String getCusName() { + return cusName; + } + + public void setCusName(String cusName) { + this.cusName = cusName; + } + + public String getCusId() { + return cusId; + } + + public void setCusId(String cusId) { + this.cusId = cusId; + } + + public 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; + } + + public Group getGroup() { + return group; + } + + public void setGroup(Group group) { + this.group = group; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Customer customer = (Customer) o; + + if (getCusName() != null ? !getCusName().equals(customer.getCusName()) : customer.getCusName() != null) + return false; + if (getCusId() != null ? !getCusId().equals(customer.getCusId()) : customer.getCusId() != null) return false; + if (getCusTotalTime() != null ? !getCusTotalTime().equals(customer.getCusTotalTime()) : customer.getCusTotalTime() != null) + return false; + if (getCusTotalPay() != null ? !getCusTotalPay().equals(customer.getCusTotalPay()) : customer.getCusTotalPay() != null) + return false; + return getGroup() != null ? getGroup().equals(customer.getGroup()) : customer.getGroup() == null; + } + + @Override + public int hashCode() { + int result = getCusName() != null ? getCusName().hashCode() : 0; + result = 31 * result + (getCusId() != null ? getCusId().hashCode() : 0); + result = 31 * result + (getCusTotalTime() != null ? getCusTotalTime().hashCode() : 0); + result = 31 * result + (getCusTotalPay() != null ? getCusTotalPay().hashCode() : 0); + result = 31 * result + (getGroup() != null ? getGroup().hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "Customer{" + + "cusName='" + cusName + '\'' + + ", cusId='" + cusId + '\'' + + ", cusTotalTime=" + cusTotalTime + + ", cusTotalPay=" + cusTotalPay + + ", group=" + group.getGroupType() + + '}'; + } +} diff --git a/me/smartstore/customer/Customers.java b/me/smartstore/customer/Customers.java new file mode 100644 index 00000000..f90b34a1 --- /dev/null +++ b/me/smartstore/customer/Customers.java @@ -0,0 +1,34 @@ +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) { + for(int i = 0; i < allCustomers.size(); i++) { + for(int j = 0; j <= groups.size() - 1; j++) { + if(allCustomers.get(i).getCusTotalTime() >= groups.get(j).getParameter().getMinTime() && + allCustomers.get(i).getCusTotalPay() >= groups.get(j).getParameter().getMinPay()) { + allCustomers.get(i).setGroup(groups.get(j)); + } + } + } + } + +} From a9736c8e2ad8774c207fdf97519a3b8482a83804 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Wed, 3 May 2023 21:10:28 +0900 Subject: [PATCH 03/30] =?UTF-8?q?Feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98=20Exception=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EB=93=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/ArrayEmptyException.java | 14 ++++++++++++ .../exception/ElementNotFoundException.java | 22 +++++++++++++++++++ .../exception/EmptyArrayException.java | 22 +++++++++++++++++++ .../exception/InputEmptyException.java | 14 ++++++++++++ .../exception/InputEndException.java | 13 +++++++++++ .../exception/InputFormatException.java | 13 +++++++++++ .../exception/InputRangeException.java | 13 +++++++++++ .../exception/InputTypeException.java | 13 +++++++++++ .../exception/NullArgumentException.java | 22 +++++++++++++++++++ 9 files changed, 146 insertions(+) create mode 100644 me/smartstore/exception/ArrayEmptyException.java create mode 100644 me/smartstore/exception/ElementNotFoundException.java create mode 100644 me/smartstore/exception/EmptyArrayException.java create mode 100644 me/smartstore/exception/InputEmptyException.java create mode 100644 me/smartstore/exception/InputEndException.java create mode 100644 me/smartstore/exception/InputFormatException.java create mode 100644 me/smartstore/exception/InputRangeException.java create mode 100644 me/smartstore/exception/InputTypeException.java create mode 100644 me/smartstore/exception/NullArgumentException.java diff --git a/me/smartstore/exception/ArrayEmptyException.java b/me/smartstore/exception/ArrayEmptyException.java new file mode 100644 index 00000000..737945ac --- /dev/null +++ b/me/smartstore/exception/ArrayEmptyException.java @@ -0,0 +1,14 @@ +package me.smartstore.exception; + +import me.smartstore.util.Message; + +public class ArrayEmptyException extends RuntimeException { + + public ArrayEmptyException() { + super(Message.ERR_MSG_INVALID_ARR_EMPTY); + } + + public ArrayEmptyException(String message) { + super(message); + } +} diff --git a/me/smartstore/exception/ElementNotFoundException.java b/me/smartstore/exception/ElementNotFoundException.java new file mode 100644 index 00000000..6e934998 --- /dev/null +++ b/me/smartstore/exception/ElementNotFoundException.java @@ -0,0 +1,22 @@ +package me.smartstore.exception; + +public class ElementNotFoundException extends RuntimeException { + public ElementNotFoundException() { + } + + public ElementNotFoundException(String message) { + super(message); + } + + public ElementNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public ElementNotFoundException(Throwable cause) { + super(cause); + } + + public ElementNotFoundException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/me/smartstore/exception/EmptyArrayException.java b/me/smartstore/exception/EmptyArrayException.java new file mode 100644 index 00000000..b19aeac3 --- /dev/null +++ b/me/smartstore/exception/EmptyArrayException.java @@ -0,0 +1,22 @@ +package me.smartstore.exception; + +public class EmptyArrayException extends RuntimeException { + public EmptyArrayException() { + } + + public EmptyArrayException(String message) { + super(message); + } + + public EmptyArrayException(String message, Throwable cause) { + super(message, cause); + } + + public EmptyArrayException(Throwable cause) { + super(cause); + } + + public EmptyArrayException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/me/smartstore/exception/InputEmptyException.java b/me/smartstore/exception/InputEmptyException.java new file mode 100644 index 00000000..2053e665 --- /dev/null +++ b/me/smartstore/exception/InputEmptyException.java @@ -0,0 +1,14 @@ +package me.smartstore.exception; + +import me.smartstore.util.Message; + +public class InputEmptyException extends RuntimeException { + + public InputEmptyException() { + super(Message.ERR_MSG_INVALID_INPUT_EMPTY); + } + + public InputEmptyException(String message) { + super(message); + } +} diff --git a/me/smartstore/exception/InputEndException.java b/me/smartstore/exception/InputEndException.java new file mode 100644 index 00000000..ffba020a --- /dev/null +++ b/me/smartstore/exception/InputEndException.java @@ -0,0 +1,13 @@ +package me.smartstore.exception; + +import me.smartstore.util.Message; + +public class InputEndException extends RuntimeException { + public InputEndException() { + super(Message.ERR_MSG_INPUT_END); + } + + public InputEndException(String message) { + super(message); + } +} diff --git a/me/smartstore/exception/InputFormatException.java b/me/smartstore/exception/InputFormatException.java new file mode 100644 index 00000000..edc44e44 --- /dev/null +++ b/me/smartstore/exception/InputFormatException.java @@ -0,0 +1,13 @@ +package me.smartstore.exception; + +import me.smartstore.util.Message; + +public class InputFormatException extends RuntimeException { + public InputFormatException() { + super(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } + + public InputFormatException(String message) { + super(message); + } +} diff --git a/me/smartstore/exception/InputRangeException.java b/me/smartstore/exception/InputRangeException.java new file mode 100644 index 00000000..10d7b011 --- /dev/null +++ b/me/smartstore/exception/InputRangeException.java @@ -0,0 +1,13 @@ +package me.smartstore.exception; + +import me.smartstore.util.Message; + +public class InputRangeException extends RuntimeException { + public InputRangeException() { + super(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + + public InputRangeException(String message) { + super(message); + } +} diff --git a/me/smartstore/exception/InputTypeException.java b/me/smartstore/exception/InputTypeException.java new file mode 100644 index 00000000..0226f9c3 --- /dev/null +++ b/me/smartstore/exception/InputTypeException.java @@ -0,0 +1,13 @@ +package me.smartstore.exception; + +import me.smartstore.util.Message; + +public class InputTypeException extends RuntimeException { + public InputTypeException() { + super(Message.ERR_MSG_INVALID_INPUT_TYPE); + } + + public InputTypeException(String message) { + super(message); + } +} diff --git a/me/smartstore/exception/NullArgumentException.java b/me/smartstore/exception/NullArgumentException.java new file mode 100644 index 00000000..e2a8531d --- /dev/null +++ b/me/smartstore/exception/NullArgumentException.java @@ -0,0 +1,22 @@ +package me.smartstore.exception; + +public class NullArgumentException extends RuntimeException { + public NullArgumentException() { + } + + public NullArgumentException(String message) { + super(message); + } + + public NullArgumentException(String message, Throwable cause) { + super(message, cause); + } + + public NullArgumentException(Throwable cause) { + super(cause); + } + + public NullArgumentException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} From caa8d74c52de345e9a529f0a2e5e29c48f5fd417 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Wed, 3 May 2023 21:16:57 +0900 Subject: [PATCH 04/30] =?UTF-8?q?Feat:=20GroupType,=20Group,=20Parameter?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Group 은 Parameter, GroupType 타입의 필드를 가지고 있으며 Parameter 클래스에는 minTime, minPay 각 각 최소 시간과 최소 비용을 필드, GroupType 은 enum 타입으로 되어있다. --- me/smartstore/group/Group.java | 53 +++++++++++++++++++++++++++++ me/smartstore/group/GroupType.java | 22 ++++++++++++ me/smartstore/group/Parameter.java | 54 ++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 me/smartstore/group/Group.java create mode 100644 me/smartstore/group/GroupType.java create mode 100644 me/smartstore/group/Parameter.java diff --git a/me/smartstore/group/Group.java b/me/smartstore/group/Group.java new file mode 100644 index 00000000..bbffe1ab --- /dev/null +++ b/me/smartstore/group/Group.java @@ -0,0 +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/me/smartstore/group/GroupType.java b/me/smartstore/group/GroupType.java new file mode 100644 index 00000000..d6ccca37 --- /dev/null +++ b/me/smartstore/group/GroupType.java @@ -0,0 +1,22 @@ +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/me/smartstore/group/Parameter.java b/me/smartstore/group/Parameter.java new file mode 100644 index 00000000..9b711f41 --- /dev/null +++ b/me/smartstore/group/Parameter.java @@ -0,0 +1,54 @@ +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 + + '}'; + } +} From 9fdf64bd7f6e3ba62c81a6c7de478b11cea49eee Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Wed, 3 May 2023 21:23:29 +0900 Subject: [PATCH 05/30] =?UTF-8?q?Feat:=20Groups=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DArray를 상속받는 Groups는 싱글턴 객체로 이루어져 있음 - find 함수는 매개변수로 들어오는 GroupType 타입의 변수를 for문을 이용하여 찾아내는 함수이다. --- me/smartstore/group/Groups.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 me/smartstore/group/Groups.java diff --git a/me/smartstore/group/Groups.java b/me/smartstore/group/Groups.java new file mode 100644 index 00000000..8c0bbd50 --- /dev/null +++ b/me/smartstore/group/Groups.java @@ -0,0 +1,25 @@ +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; + } +} From 7f95b332a169462fc185d0157ce67dba359f686c Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Wed, 3 May 2023 21:24:45 +0900 Subject: [PATCH 06/30] =?UTF-8?q?Feat:=20Main,=20SmartStoreApp=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 코드 --- me/smartstore/Main.java | 8 ++++ me/smartstore/SmartStoreApp.java | 65 ++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 me/smartstore/Main.java create mode 100644 me/smartstore/SmartStoreApp.java diff --git a/me/smartstore/Main.java b/me/smartstore/Main.java new file mode 100644 index 00000000..0f39e9fa --- /dev/null +++ b/me/smartstore/Main.java @@ -0,0 +1,8 @@ +package me.smartstore; + +public class Main { + public static void main(String[] args) { + SmartStoreApp.getInstance().test().run(); // function chaining +// SmartStoreApp.getInstance().run(); + } +} diff --git a/me/smartstore/SmartStoreApp.java b/me/smartstore/SmartStoreApp.java new file mode 100644 index 00000000..daebf373 --- /dev/null +++ b/me/smartstore/SmartStoreApp.java @@ -0,0 +1,65 @@ +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.05.03"); + System.out.println(" Copyright 2023 YongHyun 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, + null)); + } + + // @TODO: refresh do not implemented yet. + allCustomers.refresh(allGroups); + + System.out.println("allCustomers = " + allCustomers); + System.out.println("allGroups = " + allGroups); + + return this; // smartStoreApp + } + + public void run() { + details(); + mainMenu.manage(); + + } +} From d6d5544e1db92eaf6e9ccb3478553a6bd2c61fa9 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Thu, 4 May 2023 16:33:35 +0900 Subject: [PATCH 07/30] =?UTF-8?q?Feat:=20Menu=20=EC=9D=B8=ED=84=B0?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 코드에서 font 출력문 style 수정 --- me/smartstore/menu/Menu.java | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 me/smartstore/menu/Menu.java diff --git a/me/smartstore/menu/Menu.java b/me/smartstore/menu/Menu.java new file mode 100644 index 00000000..f7db0af4 --- /dev/null +++ b/me/smartstore/menu/Menu.java @@ -0,0 +1,57 @@ +package me.smartstore.menu; + +import me.smartstore.exception.InputEndException; +import me.smartstore.exception.InputRangeException; +import me.smartstore.util.Message; + +import java.util.InputMismatchException; +import java.util.Scanner; + +public interface Menu { + Scanner scanner = new Scanner(System.in); + + default String nextLine() { // 하나의 프로그램 상에서 nextLine() 함수를 통해서 사용자 입력을 받음 + return scanner.nextLine().toUpperCase(); + } + + default String nextLine(String end) { + System.out.println("** Press 'end', if you want to exit! **"); + System.out.print(">>>> input : "); + String str = nextLine(); + if (str.equals(end)) throw new InputEndException(); + return str; + } + + default int chooseMenu(String[] menus) { + while ( true ) { // 예외 복구 while + try { + System.out.println( + " ╔╦╗╔═╗╔╗╔╦ ╦ \n" + + "─────────────── ║║║║╣ ║║║║ ║ ───────────────\n" + + " ╩ ╩╚═╝╝╚╝╚═╝ " + ); + + for (int i = 0; i < menus.length; i++) { + System.out.printf(" %d. %s\n", i + 1, menus[i]); + } + System.out.println( + " \n" + + "──────────────────────────────────────────────\n" + + " " + ); + System.out.print("Choose One: "); + int choice = Integer.parseInt(nextLine()); + if (choice >= 1 && choice <= menus.length) return choice; + throw new InputRangeException(); // choice 가 범위에 벗어남 + } 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); + + } + } + } + + void manage(); // 각 서브메뉴들을 관리하는 함수 (각 서브메뉴의 최상위 메뉴) +} From d0d116d2670e2304e1610509e37364a4a492b411 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Thu, 4 May 2023 19:38:05 +0900 Subject: [PATCH 08/30] =?UTF-8?q?refactor:=20allGroups=20->=20this=20?= =?UTF-8?q?=EB=A1=9C=20=EB=A6=AC=ED=8E=99=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- me/smartstore/group/Groups.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/me/smartstore/group/Groups.java b/me/smartstore/group/Groups.java index 8c0bbd50..996c558e 100644 --- a/me/smartstore/group/Groups.java +++ b/me/smartstore/group/Groups.java @@ -15,9 +15,9 @@ public static Groups getInstance() { 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); + for(int i = 0; i < this.size; i++) { + if(this.get(i).getGroupType() == groupType) { + return this.get(i); } } return null; From 084fe2053237fffd87bb559a1d54186382dff794 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Sat, 6 May 2023 02:37:00 +0900 Subject: [PATCH 09/30] =?UTF-8?q?refactor:=20refresh=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=20=EB=A6=AC=ED=8E=99=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 refresh 함수의 경우 분류기준이 바뀌는 경우에 매개변수로 들어온 groups 의 순서가 정렬되어 있지 않기 때문에 allCustomers 의 group 상태가 모두 NONE 으로 바뀌게 되었었다. (GENERAL, VIP, VVIP, NONE) 를 Arrays.sort() 함수를 사용하여 이용요금과 이용시간 을 기준으로 다시 정렬한 fixGroup 을 이용하여 각 customer 의 맞는 group을 넣도록 리펙터링 하였다. --- me/smartstore/customer/Customers.java | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/me/smartstore/customer/Customers.java b/me/smartstore/customer/Customers.java index f90b34a1..6596a092 100644 --- a/me/smartstore/customer/Customers.java +++ b/me/smartstore/customer/Customers.java @@ -2,8 +2,11 @@ import me.smartstore.arrays.DArray; +import me.smartstore.group.Group; import me.smartstore.group.Groups; +import java.util.Arrays; + public class Customers extends DArray { private static Customers allCustomers; @@ -21,11 +24,21 @@ private Customers() {} // 1. 분류기준 바뀔 때 // 2. 새로운 고객이 들어올 때 public void refresh(Groups groups) { - for(int i = 0; i < allCustomers.size(); i++) { - for(int j = 0; j <= groups.size() - 1; j++) { - if(allCustomers.get(i).getCusTotalTime() >= groups.get(j).getParameter().getMinTime() && - allCustomers.get(i).getCusTotalPay() >= groups.get(j).getParameter().getMinPay()) { - allCustomers.get(i).setGroup(groups.get(j)); + + Group[] fixGroup = new Group[groups.size()]; + for(int i = 0; i < groups.size(); i++) { + fixGroup[i] = groups.get(i); + } + + Arrays.sort(fixGroup, (o1, o2) -> o1.getParameter().getMinPay() != o2.getParameter().getMinPay() ? + o1.getParameter().getMinPay() - o2.getParameter().getMinPay() : + o1.getParameter().getMinTime() - o2.getParameter().getMinTime()); + + for(int i = 0; i < this.size(); i++) { + for(int j = 0; j <= fixGroup.length - 1; j++) { + if(this.get(i).getCusTotalTime() >= fixGroup[j].getParameter().getMinTime() && + this.get(i).getCusTotalPay() >= fixGroup[j].getParameter().getMinPay()) { + this.get(i).setGroup(fixGroup[j]); } } } From fe33cabd076ce448f436565b5e287d683a763475 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Sat, 6 May 2023 02:38:53 +0900 Subject: [PATCH 10/30] =?UTF-8?q?style:=20=EC=BB=A4=EB=8B=A4=EB=9E=80=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95=EC=9D=B4=20=EC=97=86?= =?UTF-8?q?=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- me/smartstore/SmartStoreApp.java | 13 +++++++------ me/smartstore/customer/Customer.java | 2 -- me/smartstore/group/Group.java | 7 +++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/me/smartstore/SmartStoreApp.java b/me/smartstore/SmartStoreApp.java index daebf373..f62dd0eb 100644 --- a/me/smartstore/SmartStoreApp.java +++ b/me/smartstore/SmartStoreApp.java @@ -26,11 +26,13 @@ public static SmartStoreApp getInstance() { private SmartStoreApp() {} public void details() { - System.out.println("\n\n==========================================="); - System.out.println(" Title : SmartStore Customer Classification"); - System.out.println(" Release Date : 23.05.03"); - System.out.println(" Copyright 2023 YongHyun All rights reserved."); - System.out.println("===========================================\n"); + System.out.println("\n" + + "███████╗███╗ ███╗ █████╗ ██████╗ ████████╗ ███████╗████████╗ ██████╗ ██████╗ ███████╗\n" + + "██╔════╝████╗ ████║██╔══██╗██╔══██╗╚══██╔══╝ ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝\n" + + "███████╗██╔████╔██║███████║██████╔╝ ██║ ███████╗ ██║ ██║ ██║██████╔╝█████╗ \n" + + "╚════██║██║╚██╔╝██║██╔══██║██╔══██╗ ██║ ╚════██║ ██║ ██║ ██║██╔══██╗██╔══╝ \n" + + "███████║██║ ╚═╝ ██║██║ ██║██║ ██║ ██║ ███████║ ██║ ╚██████╔╝██║ ██║███████╗\n" + + "╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝\n"); } public SmartStoreApp test() { @@ -48,7 +50,6 @@ public SmartStoreApp test() { null)); } - // @TODO: refresh do not implemented yet. allCustomers.refresh(allGroups); System.out.println("allCustomers = " + allCustomers); diff --git a/me/smartstore/customer/Customer.java b/me/smartstore/customer/Customer.java index 175596d0..fb77b461 100644 --- a/me/smartstore/customer/Customer.java +++ b/me/smartstore/customer/Customer.java @@ -2,8 +2,6 @@ import me.smartstore.group.Group; -import java.util.Objects; - public class Customer { private String cusName; private String cusId; diff --git a/me/smartstore/group/Group.java b/me/smartstore/group/Group.java index bbffe1ab..afcd0b4e 100644 --- a/me/smartstore/group/Group.java +++ b/me/smartstore/group/Group.java @@ -45,9 +45,8 @@ public int hashCode() { @Override public String toString() { - return "Group{" + - "parameter=" + parameter + - ", groupType=" + groupType + - '}'; + return + parameter + "\n" + + "groupType=" + groupType + "\n"; } } From 531c86f0911425fbdfbe2b9096b1bcc47bf8ab14 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Sat, 6 May 2023 13:30:14 +0900 Subject: [PATCH 11/30] =?UTF-8?q?feat:=20Message=20=EC=9D=B8=ED=84=B0?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- me/smartstore/util/Message.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 me/smartstore/util/Message.java diff --git a/me/smartstore/util/Message.java b/me/smartstore/util/Message.java new file mode 100644 index 00000000..1c67d21e --- /dev/null +++ b/me/smartstore/util/Message.java @@ -0,0 +1,13 @@ +package me.smartstore.util; + +public interface Message { + String ERR_MSG_INVALID_ARR_EMPTY = "No Customers. Please input one first."; + String ERR_MSG_NULL_ARR_ELEMENT = "Elements in Array has null. Array can't be sorted."; + String ERR_MSG_INVALID_INPUT_NULL = "Null Input. Please input something."; + String ERR_MSG_INVALID_INPUT_EMPTY = "Empty Input. Please input something."; + String ERR_MSG_INVALID_INPUT_RANGE = "Invalid Input. Please try again."; + String ERR_MSG_INVALID_INPUT_TYPE = "Invalid Type for Input. Please try again."; + String ERR_MSG_INVALID_INPUT_FORMAT = "Invalid Format for Input. Please try again."; + String ERR_MSG_INPUT_END = "END is pressed. Exit this menu."; + String END_MSG = "END"; +} From b88530f858cf8af783e6488fb0d5bec1b9946915 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Sat, 6 May 2023 13:31:09 +0900 Subject: [PATCH 12/30] =?UTF-8?q?feat:=20GroupMenu=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit setParameter, viewParameter, updateParameter 함수 추가 --- me/smartstore/menu/GroupMenu.java | 178 ++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 me/smartstore/menu/GroupMenu.java diff --git a/me/smartstore/menu/GroupMenu.java b/me/smartstore/menu/GroupMenu.java new file mode 100644 index 00000000..815465ef --- /dev/null +++ b/me/smartstore/menu/GroupMenu.java @@ -0,0 +1,178 @@ +package me.smartstore.menu; + +import me.smartstore.customer.Customers; +import me.smartstore.exception.InputEndException; +import me.smartstore.exception.NullArgumentException; +import me.smartstore.group.Group; +import me.smartstore.group.GroupType; +import me.smartstore.group.Groups; +import me.smartstore.group.Parameter; +import me.smartstore.util.Message; + +public class GroupMenu implements Menu { + private final Groups allGroups = Groups.getInstance(); + private final Customers allCustomers = Customers.getInstance(); + // singleton + 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 void setParameter() { // 초기화할 때만 호출 가능 + while ( true ) { + try { + GroupType groupType = chooseGroup(); +// if(groupType == null) { +// break; +// } + // 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 사용자 입력받은 후, 설정 필요 + inputParameter(parameter); + + Group addGroup = new Group(); + addGroup.setParameter(parameter); + addGroup.setGroupType(groupType); + allGroups.add(addGroup); + allCustomers.refresh(allGroups); // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 + break; + } + }catch (NullArgumentException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); + System.out.println(); + break; + } + + } + } + + private void inputParameter(Parameter parameter) { + while(true) { + try { + int choice = chooseMenu(new String[]{ + "Minimum Spent Time", + "Minimum Total Pay", + "Back" + }); + if (choice == 1) { + System.out.println("Input Minimum Spent Time"); + parameter.setMinTime(Integer.parseInt(nextLine(Message.END_MSG))); + System.out.println(parameter); + } else if (choice == 2) { + System.out.println("Input Minimum Total Pay"); + parameter.setMinPay(Integer.parseInt(nextLine(Message.END_MSG))); + System.out.println(parameter); + } else { + if(parameter.getMinPay() == null || parameter.getMinTime() == null) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); + }else { + System.out.printf( + "_人人人人人人人人人人人人人人人人人人人人人人人人人人_\n" + + "> Success !!! %s <\n" + + " ̄^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄\n" + + " .A__A ✨\uD83C\uDF82✨ A__A\n" + + " ( •⩊•) _______ (•⩊• )\n" + + " (>\uD83C\uDF70>) | | (<\uD83D\uDD2A<)\n", parameter); + break; + } + } + }catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + break; + }catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } + } + } + + private void viewParameter() { + while(true) { + GroupType groupType = chooseGroup(); + if(groupType == null) { + break; + } + Group group = allGroups.find(groupType); + if (group != null && group.getParameter() != null) { + System.out.println("\n ─────────[" + group.getGroupType() + "]─────────"); + System.out.println(group); + System.out.println("──────────────────────────────────────────"); + } else { + System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); + System.out.println(); + } + } + + } + + private void updateParameter() { + while ( true ) { + GroupType groupType = chooseGroup(); + if(groupType == null) { + break; + } + Group group = allGroups.find(groupType); + if (group != null && group.getParameter() != null) { + inputParameter(group.getParameter()); + allCustomers.refresh(allGroups); + } else { + System.out.println(Message.ERR_MSG_INVALID_INPUT_EMPTY); + System.out.println(); + } + } + } + + public GroupType chooseGroup() { + while ( true ) { + try { + System.out.println( + "┬ ┬┬ ┬┬┌─┐┬ ┬ ┌─┐┬─┐┌─┐┬ ┬┌─┐\n" + + "│││├─┤││ ├─┤ │ ┬├┬┘│ ││ │├─┘\n" + + "└┴┘┴ ┴┴└─┘┴ ┴ └─┘┴└─└─┘└─┘┴ \n" + + "─────────────────────────────────"); + GroupType[] groupTypes = GroupType.values(); + for(int i = 0; i < groupTypes.length / 2; i++) { + System.out.printf(" → %s (%s) ? \n", groupTypes[i], groupTypes[i + groupTypes.length / 2]); + } + System.out.println("─────────────────────────────────"); + 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); + } + } + } +} From 71a24d3fda9ebf95cc3df7b6be959c076fe9f6d3 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Sat, 6 May 2023 13:32:00 +0900 Subject: [PATCH 13/30] =?UTF-8?q?feat:=20CustomerMenu=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit addCustomer, viewCustomer, deleteCustomer 함수 추가 --- me/smartstore/menu/CustomerMenu.java | 156 +++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 me/smartstore/menu/CustomerMenu.java diff --git a/me/smartstore/menu/CustomerMenu.java b/me/smartstore/menu/CustomerMenu.java new file mode 100644 index 00000000..6c36543a --- /dev/null +++ b/me/smartstore/menu/CustomerMenu.java @@ -0,0 +1,156 @@ +package me.smartstore.menu; + +import me.smartstore.customer.Customer; +import me.smartstore.customer.Customers; +import me.smartstore.exception.InputEndException; +import me.smartstore.group.Groups; +import me.smartstore.util.Message; + +public class CustomerMenu implements Menu { + // singleton + + private final Groups allGroups = Groups.getInstance(); + private final Customers allCustomers = Customers.getInstance(); + 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"}); + if(choice == 1) addCustomer(); + else if(choice == 2) viewCustomer(); + else if(choice == 3) updateCustomer(); + else if(choice == 4) deleteCustomer(); + else break; + } + } + + private void addCustomer() { + while(true) { + try { + System.out.println("How many customers to input : "); + int inputCount = Integer.parseInt(nextLine(Message.END_MSG)); + for(int i = 0; i < inputCount; i++) { + customerInfoInput(i + 1); + } + break; + }catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + } + + } + } + + private void customerInfoInput(int count) { + Customer addCustomer = new Customer(); + while(true) { + System.out.printf("====== Customer %d Info. ======\n", count); + int choice = chooseMenu(new String[]{ + "Customer Name", + "Customer ID", + "Customer Spent Time", + "Customer Total Pay", + "Back" + }); + if(choice == 1) { + System.out.print("Input Customer Name : "); + String customerName = nextLine(); + addCustomer.setCusName(customerName); + }else if (choice == 2) { + System.out.print("Input Customer ID : "); + String customerId = nextLine(); + addCustomer.setCusId(customerId); + }else if(choice == 3) { + System.out.print("Input Customer Spent Time : "); + int customerSpentTime = Integer.parseInt(nextLine()); + addCustomer.setCusTotalTime(customerSpentTime); + }else if(choice == 4) { + System.out.print("Input Customer Total Pay : "); + int customerTotalPay = Integer.parseInt(nextLine()); + addCustomer.setCusTotalPay(customerTotalPay); + }else { + allCustomers.add(addCustomer); + allCustomers.refresh(allGroups); + System.out.println(addCustomer); + break; + } + } + } + + private void viewCustomer() { + System.out.println("======= Customer Info. ======="); + for(int i = 0; i < allCustomers.size(); i++) { + System.out.printf("No. %3d => ", i + 1 ); + System.out.println(allCustomers.get(i)); + } + } + + private void updateCustomer() { + while(true) { + try { + viewCustomer(); + System.out.printf("Which customer ( 1 ~ %d ) ? : ", allCustomers.size()); + int updateIndex = Integer.parseInt(nextLine()); + Customer updateCustomer = allCustomers.get(updateIndex - 1); + while(true) { + int choice = chooseMenu(new String[]{ + "Customer Name", + "Customer ID", + "Customer Spent Time", + "Customer Total Pay", + "Back" + }); + if(choice == 1) { + System.out.print("Input Customer Name : "); + String customerName = nextLine(); + updateCustomer.setCusName(customerName); + }else if (choice == 2) { + System.out.print("Input Customer ID : "); + String customerId = nextLine(); + updateCustomer.setCusId(customerId); + }else if(choice == 3) { + System.out.print("Input Customer Spent Time : "); + int customerSpentTime = Integer.parseInt(nextLine()); + updateCustomer.setCusTotalTime(customerSpentTime); + }else if(choice == 4) { + System.out.print("Input Customer Total Pay : "); + int customerTotalPay = Integer.parseInt(nextLine()); + updateCustomer.setCusTotalPay(customerTotalPay); + }else { + System.out.println(updateCustomer); + allCustomers.refresh(allGroups); + break; + } + } + }catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + break; + } + + } + } + + private void deleteCustomer() { + while(true) { + viewCustomer(); + System.out.printf("Which customer ( 1 ~ %d ) ? : ", allCustomers.size()); + int updateIndex = Integer.parseInt(nextLine()); + allCustomers.pop(updateIndex); + } + + } +} From 5f0175b9db319356816ebd69d6609d428985c839 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Sat, 6 May 2023 13:32:50 +0900 Subject: [PATCH 14/30] =?UTF-8?q?feat:=20SummaryMenu=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit summary, summaryName, summaryTime, summaryPay 함수 추가 --- me/smartstore/menu/SummaryMenu.java | 198 ++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 me/smartstore/menu/SummaryMenu.java diff --git a/me/smartstore/menu/SummaryMenu.java b/me/smartstore/menu/SummaryMenu.java new file mode 100644 index 00000000..74c2a572 --- /dev/null +++ b/me/smartstore/menu/SummaryMenu.java @@ -0,0 +1,198 @@ +package me.smartstore.menu; + +import me.smartstore.customer.Customer; +import me.smartstore.customer.Customers; +import me.smartstore.exception.InputEndException; +import me.smartstore.group.Group; +import me.smartstore.group.Groups; +import me.smartstore.util.Message; + +import java.util.Arrays; +import java.util.Comparator; + +public class SummaryMenu implements Menu { + // singleton + 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(); + } + 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"}); + if(choice == 1) summary(); + else if(choice == 2) summaryName(); + else if(choice == 3) summaryTime(); + else if(choice == 4) summaryPay(); + else break; + } + } + + private void summary() { + for(int i = 0; i < allGroups.size(); i++) { + System.out.print("=============================="); + Group findGroup = allGroups.get(i); + System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), + findGroup.getParameter().getMinTime(), + findGroup.getParameter().getMinPay()); + System.out.println("=============================="); + int count = 1; + for(int j = 0; j < allCustomers.size(); j++) { + if(allCustomers.get(j).getGroup() == findGroup) { + System.out.printf("No. %3d => %s \n", count++, allCustomers.get(j).toString()); + } + } + System.out.println(); + } + } + + private void summaryName() { + while(true) { + try { + System.out.println("Which order (ASCENDING (A), DESCENDING (D))?"); + String order = nextLine(Message.END_MSG); + for(int i = 0; i < allGroups.size(); i++) { + System.out.print("=============================="); + Group findGroup = allGroups.get(i); + System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), + findGroup.getParameter().getMinTime(), + findGroup.getParameter().getMinPay()); + System.out.println("=============================="); + int size = 0; + for(int j = 0; j < allCustomers.size(); j++) { + if(allCustomers.get(j).getGroup() == findGroup) { + size++; + } + } + Customer[] customers = new Customer[size]; + int index = 0; + for(int j = 0; j < allCustomers.size(); j++) { + if(allCustomers.get(j).getGroup() == findGroup) { + customers[index++] = allCustomers.get(j); + } + } + + if(order.equals("A") || order.equals("ASCENDING")) { + Arrays.sort(customers, Comparator.comparing(Customer::getCusName)); + for(int j = 0; j < customers.length; j++) { + System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + } + } else { + Arrays.sort(customers, (o1, o2) -> o2.getCusName().compareTo(o1.getCusName())); + for(int j = 0; j < customers.length; j++) { + System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + } + } + } + }catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + break; + } + } + } + + private void summaryTime() { + while(true) { + try { + System.out.println("Which order (ASCENDING (A), DESCENDING (D))?"); + String order = nextLine(Message.END_MSG); + for(int i = 0; i < allGroups.size(); i++) { + System.out.print("=============================="); + Group findGroup = allGroups.get(i); + System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), + findGroup.getParameter().getMinTime(), + findGroup.getParameter().getMinPay()); + System.out.println("=============================="); + int size = 0; + for(int j = 0; j < allCustomers.size(); j++) { + if(allCustomers.get(j).getGroup() == findGroup) { + size++; + } + } + Customer[] customers = new Customer[size]; + int index = 0; + for(int j = 0; j < allCustomers.size(); j++) { + if(allCustomers.get(j).getGroup() == findGroup) { + customers[index++] = allCustomers.get(j); + } + } + + if(order.equals("A") || order.equals("ASCENDING")) { + Arrays.sort(customers, Comparator.comparing(Customer::getCusTotalTime)); + for(int j = 0; j < customers.length; j++) { + System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + } + } else { + Arrays.sort(customers, (o1, o2) -> o2.getCusTotalTime().compareTo(o1.getCusTotalTime())); + for(int j = 0; j < customers.length; j++) { + System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + } + } + } + }catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + break; + } + } + } + + private void summaryPay() { + while(true) { + try { + System.out.println("Which order (ASCENDING (A), DESCENDING (D))?"); + String order = nextLine(Message.END_MSG); + for(int i = 0; i < allGroups.size(); i++) { + System.out.print("=============================="); + Group findGroup = allGroups.get(i); + System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), + findGroup.getParameter().getMinTime(), + findGroup.getParameter().getMinPay()); + System.out.println("=============================="); + int size = 0; + for(int j = 0; j < allCustomers.size(); j++) { + if(allCustomers.get(j).getGroup() == findGroup) { + size++; + } + } + Customer[] customers = new Customer[size]; + int index = 0; + for(int j = 0; j < allCustomers.size(); j++) { + if(allCustomers.get(j).getGroup() == findGroup) { + customers[index++] = allCustomers.get(j); + } + } + + if(order.equals("A") || order.equals("ASCENDING")) { + Arrays.sort(customers, Comparator.comparing(Customer::getCusTotalPay)); + for(int j = 0; j < customers.length; j++) { + System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + } + } else { + Arrays.sort(customers, (o1, o2) -> o2.getCusTotalPay().compareTo(o1.getCusTotalPay())); + for(int j = 0; j < customers.length; j++) { + System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + } + } + } + }catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + break; + } + } + } +} From a339717a9b9e7339eec31dc1c4e741240336c400 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Sat, 6 May 2023 13:33:15 +0900 Subject: [PATCH 15/30] =?UTF-8?q?feat:=20MainMenu=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- me/smartstore/menu/MainMenu.java | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 me/smartstore/menu/MainMenu.java diff --git a/me/smartstore/menu/MainMenu.java b/me/smartstore/menu/MainMenu.java new file mode 100644 index 00000000..a7768657 --- /dev/null +++ b/me/smartstore/menu/MainMenu.java @@ -0,0 +1,39 @@ +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(); + + // singleton + 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; + } + } + } +} From 899c6bdb4f08a5bc8a5e4bbb57a05f90f1a7db54 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Sat, 6 May 2023 14:22:58 +0900 Subject: [PATCH 16/30] =?UTF-8?q?fix:=20setParameter=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit parameter 에 minPay, minTime 중 하나라도 null 값이 포함되어 있을 경우에는 다시 입력받을 수 있도록 코드를 수정 --- me/smartstore/menu/GroupMenu.java | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/me/smartstore/menu/GroupMenu.java b/me/smartstore/menu/GroupMenu.java index 815465ef..251a3d67 100644 --- a/me/smartstore/menu/GroupMenu.java +++ b/me/smartstore/menu/GroupMenu.java @@ -45,9 +45,9 @@ public void setParameter() { // 초기화할 때만 호출 가능 while ( true ) { try { GroupType groupType = chooseGroup(); -// if(groupType == null) { -// break; -// } + if(groupType == null) { + break; + } // GroupType에 해당하는 group 객체를 찾아야 함 Group group = allGroups.find(groupType); if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 @@ -58,12 +58,16 @@ public void setParameter() { // 초기화할 때만 호출 가능 // time, pay 사용자 입력받은 후, 설정 필요 inputParameter(parameter); - Group addGroup = new Group(); - addGroup.setParameter(parameter); - addGroup.setGroupType(groupType); - allGroups.add(addGroup); - allCustomers.refresh(allGroups); // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 - break; + if(parameter.getMinPay() == null || parameter.getMinTime() == null) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); + }else { + Group addGroup = new Group(); + addGroup.setParameter(parameter); + addGroup.setGroupType(groupType); + allGroups.add(addGroup); + allCustomers.refresh(allGroups); // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 + break; + } } }catch (NullArgumentException e) { System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); @@ -125,7 +129,8 @@ private void viewParameter() { System.out.println(group); System.out.println("──────────────────────────────────────────"); } else { - System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); + System.out.printf("Please Set Parameter first %s\n", groupType); +// System.out.println(Message.ERR_MSG_INVALID_INPUT_EMPTY); System.out.println(); } } From efd3cb0bcc2ca5e875fbada006f122fde9257ecb Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Sat, 6 May 2023 15:37:20 +0900 Subject: [PATCH 17/30] =?UTF-8?q?fix:=20addCustomer,=20updateCustomer,=20v?= =?UTF-8?q?iewCustomer=20=ED=95=A8=EC=88=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - addCustomer 의 customerInfoInput 함수에 새로운 고객을 추가할때 null 체크를 해주는 코드 추가 및 출력문 수정 - updateCustomer 의 END 를 입력하면 이전 메뉴로 이동할 수 있도록 수정, 예외처리 NumberFormatException, IndexOutOfBoundsException 코드 수정 및 출력문 수정 - deleteCustomer 의 END 를 입력하면 이전 메뉴로 이동할 수 있도록 수정, 예외처리 InputEndException, NumberFormatException, IndexOutOfBoundsException 코드 수정 및 출력문 수정 출력문 수정 --- me/smartstore/menu/Menu.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/me/smartstore/menu/Menu.java b/me/smartstore/menu/Menu.java index f7db0af4..15051939 100644 --- a/me/smartstore/menu/Menu.java +++ b/me/smartstore/menu/Menu.java @@ -32,7 +32,7 @@ default int chooseMenu(String[] menus) { ); for (int i = 0; i < menus.length; i++) { - System.out.printf(" %d. %s\n", i + 1, menus[i]); + System.out.printf(" %d. %s\n", i + 1, menus[i]); } System.out.println( " \n" + @@ -45,10 +45,8 @@ default int chooseMenu(String[] menus) { throw new InputRangeException(); // choice 가 범위에 벗어남 } 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 b9237148fc320a25fe9d2184bb59fb4201f297cc Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Sat, 6 May 2023 15:37:39 +0900 Subject: [PATCH 18/30] =?UTF-8?q?fix:=20addCustomer,=20updateCustomer,=20v?= =?UTF-8?q?iewCustomer=20=ED=95=A8=EC=88=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - addCustomer 의 customerInfoInput 함수에 새로운 고객을 추가할때 null 체크를 해주는 코드 추가 및 출력문 수정 - updateCustomer 의 END 를 입력하면 이전 메뉴로 이동할 수 있도록 수정, 예외처리 NumberFormatException, IndexOutOfBoundsException 코드 수정 및 출력문 수정 - deleteCustomer 의 END 를 입력하면 이전 메뉴로 이동할 수 있도록 수정, 예외처리 InputEndException, NumberFormatException, IndexOutOfBoundsException 코드 수정 및 출력문 수정 출력문 수정 --- me/smartstore/menu/CustomerMenu.java | 61 ++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/me/smartstore/menu/CustomerMenu.java b/me/smartstore/menu/CustomerMenu.java index 6c36543a..3a55fd5d 100644 --- a/me/smartstore/menu/CustomerMenu.java +++ b/me/smartstore/menu/CustomerMenu.java @@ -83,10 +83,21 @@ private void customerInfoInput(int count) { int customerTotalPay = Integer.parseInt(nextLine()); addCustomer.setCusTotalPay(customerTotalPay); }else { - allCustomers.add(addCustomer); - allCustomers.refresh(allGroups); - System.out.println(addCustomer); - break; + if(addCustomer.getCusId() == null || addCustomer.getCusName() == null || + addCustomer.getCusTotalTime() == null || addCustomer.getCusTotalPay() == null) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); + }else { + allCustomers.add(addCustomer); + allCustomers.refresh(allGroups); + System.out.printf( + "_人人人人人人人人人人人人人人人人人人人人人人人人人人_\n" + + "> Success !!! %s <\n" + + " ̄^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄\n" + + " .A__A ✨\uD83C\uDF82✨ A__A\n" + + " ( •⩊•) _______ (•⩊• )\n" + + " (>\uD83C\uDF70>) | | (<\uD83D\uDD2A<)\n", addCustomer); + break; + } } } } @@ -104,7 +115,7 @@ private void updateCustomer() { try { viewCustomer(); System.out.printf("Which customer ( 1 ~ %d ) ? : ", allCustomers.size()); - int updateIndex = Integer.parseInt(nextLine()); + int updateIndex = Integer.parseInt(nextLine(Message.END_MSG)); Customer updateCustomer = allCustomers.get(updateIndex - 1); while(true) { int choice = chooseMenu(new String[]{ @@ -131,25 +142,51 @@ private void updateCustomer() { int customerTotalPay = Integer.parseInt(nextLine()); updateCustomer.setCusTotalPay(customerTotalPay); }else { - System.out.println(updateCustomer); allCustomers.refresh(allGroups); + System.out.printf( + "SUCCESS UPDATE!!\n" + + "%s\n" + + "두다다다다다다다\n" + + " (∩`・ω・)\n" + + "_/_ミつ/ ̄ ̄ ̄/\n" + + "  \/___/\n", updateCustomer); break; } } - }catch (InputEndException e) { + }catch (InputEndException e ) { System.out.println(Message.ERR_MSG_INPUT_END); break; + }catch (NumberFormatException e){ + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + }catch (IndexOutOfBoundsException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); } - } } private void deleteCustomer() { while(true) { - viewCustomer(); - System.out.printf("Which customer ( 1 ~ %d ) ? : ", allCustomers.size()); - int updateIndex = Integer.parseInt(nextLine()); - allCustomers.pop(updateIndex); + try { + viewCustomer(); + System.out.printf("Which customer ( 1 ~ %d ) ? : ", allCustomers.size()); + int updateIndex = Integer.parseInt(nextLine(Message.END_MSG)); + allCustomers.pop(updateIndex - 1); + System.out.println( + "SUCCESS DELETE!!\n" + + "두다다다다다다다\n" + + "두다다다다다다다\n" + + " (∩`・ω・)\n" + + "_/_ミつ/ ̄ ̄ ̄/\n" + + "  \/___/\n"); + }catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + break; + }catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + }catch (IndexOutOfBoundsException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } } From f01356b81099dd502f79e1d93e340b66a7985a25 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Sat, 6 May 2023 15:39:21 +0900 Subject: [PATCH 19/30] =?UTF-8?q?refactor:=20Customer=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20=ED=95=A8=EC=88=98=20=EB=A6=AC=ED=8E=99=ED=84=B0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Customer 객체가 생성될 때마다 기본적으로 NONE GroupType 을 가지도록 수정하였음 --- me/smartstore/customer/Customer.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/me/smartstore/customer/Customer.java b/me/smartstore/customer/Customer.java index fb77b461..563d79f4 100644 --- a/me/smartstore/customer/Customer.java +++ b/me/smartstore/customer/Customer.java @@ -1,6 +1,8 @@ package me.smartstore.customer; import me.smartstore.group.Group; +import me.smartstore.group.GroupType; +import me.smartstore.group.Parameter; public class Customer { private String cusName; @@ -10,6 +12,7 @@ public class Customer { private Group group; public Customer() { + this.group = new Group(new Parameter(0, 0), GroupType.NONE); } public Customer(String cusId) { From c0756adb85c7c7fbfd70d91eef331603d6fea936 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Tue, 9 May 2023 00:29:02 +0900 Subject: [PATCH 20/30] =?UTF-8?q?feat:=20OrderType=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SummaryMenu 에 A(오름차순), D(내림차순) 을 지정해 주기 위해서 enum 타입의 OrderType 을 추가하였다. --- me/smartstore/menu/OrderType.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 me/smartstore/menu/OrderType.java diff --git a/me/smartstore/menu/OrderType.java b/me/smartstore/menu/OrderType.java new file mode 100644 index 00000000..494c59a0 --- /dev/null +++ b/me/smartstore/menu/OrderType.java @@ -0,0 +1,20 @@ +package me.smartstore.menu; + +public enum OrderType { + + A("오름차순"), D("내림차순"), + ASCENDING("오름차순"), DESCENDING("내림차순"); + + + String orderType = ""; + + OrderType(String orderType) { + this.orderType = orderType; + } + + public OrderType replaceFullName() { + if (this == A) return ASCENDING; + else if (this == D) return DESCENDING; + return this; + } +} From 4ff3512bdd90fb2219a76449366e57e6993b5f6d Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Tue, 9 May 2023 00:33:49 +0900 Subject: [PATCH 21/30] =?UTF-8?q?refactor:=20=EA=B3=A0=EA=B0=9D=EC=9D=B4?= =?UTF-8?q?=20=EC=97=86=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - allCustomers.size() 가 0일 경우 요약 기능을 이용하지 못하도록 수정 - findOrder 함수를 이용하여 A(오름차순), D(내림차순) 이외의 값을 입력하면 예외 처리 및 return 한 orderType 변수에 따라 정렬 기능 수행 --- me/smartstore/menu/SummaryMenu.java | 228 ++++++++++++++++------------ 1 file changed, 132 insertions(+), 96 deletions(-) diff --git a/me/smartstore/menu/SummaryMenu.java b/me/smartstore/menu/SummaryMenu.java index 74c2a572..db589008 100644 --- a/me/smartstore/menu/SummaryMenu.java +++ b/me/smartstore/menu/SummaryMenu.java @@ -28,23 +28,27 @@ 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"}); - if(choice == 1) summary(); - else if(choice == 2) summaryName(); - else if(choice == 3) summaryTime(); - else if(choice == 4) summaryPay(); - else break; + if(allCustomers.size() == 0) { + System.out.println(Message.ERR_MSG_INVALID_ARR_EMPTY); + }else { + while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while + int choice = chooseMenu(new String[]{ + "Summary", + "Summary (Sorted By Name)", + "Summary (Sorted By Time)", + "Summary (Sorted By Pay)", + "Back"}); + if (choice == 1) summary(); + else if (choice == 2) summaryName(); + else if (choice == 3) summaryTime(); + else if (choice == 4) summaryPay(); + else break; + } } } private void summary() { - for(int i = 0; i < allGroups.size(); i++) { + for (int i = 0; i < allGroups.size(); i++) { System.out.print("=============================="); Group findGroup = allGroups.get(i); System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), @@ -52,8 +56,8 @@ private void summary() { findGroup.getParameter().getMinPay()); System.out.println("=============================="); int count = 1; - for(int j = 0; j < allCustomers.size(); j++) { - if(allCustomers.get(j).getGroup() == findGroup) { + for (int j = 0; j < allCustomers.size(); j++) { + if (allCustomers.get(j).getGroup() == findGroup) { System.out.printf("No. %3d => %s \n", count++, allCustomers.get(j).toString()); } } @@ -66,44 +70,63 @@ private void summaryName() { try { System.out.println("Which order (ASCENDING (A), DESCENDING (D))?"); String order = nextLine(Message.END_MSG); - for(int i = 0; i < allGroups.size(); i++) { - System.out.print("=============================="); - Group findGroup = allGroups.get(i); - System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), - findGroup.getParameter().getMinTime(), - findGroup.getParameter().getMinPay()); - System.out.println("=============================="); - int size = 0; - for(int j = 0; j < allCustomers.size(); j++) { - if(allCustomers.get(j).getGroup() == findGroup) { - size++; + + OrderType orderType = findOrder(order); + if(orderType == null) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + }else { + for(int i = 0; i < allGroups.size(); i++) { + System.out.print("=============================="); + Group findGroup = allGroups.get(i); + System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), + findGroup.getParameter().getMinTime(), + findGroup.getParameter().getMinPay()); + System.out.println("=============================="); + int size = 0; + for (int j = 0; j < allCustomers.size(); j++) { + if (allCustomers.get(j).getGroup() == findGroup) { + size++; + } } - } - Customer[] customers = new Customer[size]; - int index = 0; - for(int j = 0; j < allCustomers.size(); j++) { - if(allCustomers.get(j).getGroup() == findGroup) { - customers[index++] = allCustomers.get(j); + Customer[] customers = new Customer[size]; + int index = 0; + for (int j = 0; j < allCustomers.size(); j++) { + if (allCustomers.get(j).getGroup() == findGroup) { + customers[index++] = allCustomers.get(j); + } } - } - if(order.equals("A") || order.equals("ASCENDING")) { - Arrays.sort(customers, Comparator.comparing(Customer::getCusName)); - for(int j = 0; j < customers.length; j++) { - System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); - } - } else { - Arrays.sort(customers, (o1, o2) -> o2.getCusName().compareTo(o1.getCusName())); - for(int j = 0; j < customers.length; j++) { - System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + if (String.valueOf(orderType).equals("ASCENDING")) { + Arrays.sort(customers, Comparator.comparing(Customer::getCusName)); + for (int j = 0; j < customers.length; j++) { + System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + } + } else { + Arrays.sort(customers, (o1, o2) -> o2.getCusName().compareTo(o1.getCusName())); + for (int j = 0; j < customers.length; j++) { + System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + } } } } }catch (InputEndException e) { System.out.println(Message.ERR_MSG_INPUT_END); break; + }catch (IndexOutOfBoundsException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_EMPTY); + break; + } + } + } + + private OrderType findOrder(String order) { + OrderType[] values = OrderType.values(); + for(int i = 0; i < values.length; i++) { + if(values[i].toString().equals(order)) { + return values[i].replaceFullName(); } } + return null; } private void summaryTime() { @@ -111,36 +134,42 @@ private void summaryTime() { try { System.out.println("Which order (ASCENDING (A), DESCENDING (D))?"); String order = nextLine(Message.END_MSG); - for(int i = 0; i < allGroups.size(); i++) { - System.out.print("=============================="); - Group findGroup = allGroups.get(i); - System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), - findGroup.getParameter().getMinTime(), - findGroup.getParameter().getMinPay()); - System.out.println("=============================="); - int size = 0; - for(int j = 0; j < allCustomers.size(); j++) { - if(allCustomers.get(j).getGroup() == findGroup) { - size++; + + OrderType orderType = findOrder(order); + if(orderType == null) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + }else { + for(int i = 0; i < allGroups.size(); i++) { + System.out.print("=============================="); + Group findGroup = allGroups.get(i); + System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), + findGroup.getParameter().getMinTime(), + findGroup.getParameter().getMinPay()); + System.out.println("=============================="); + int size = 0; + for (int j = 0; j < allCustomers.size(); j++) { + if (allCustomers.get(j).getGroup() == findGroup) { + size++; + } } - } - Customer[] customers = new Customer[size]; - int index = 0; - for(int j = 0; j < allCustomers.size(); j++) { - if(allCustomers.get(j).getGroup() == findGroup) { - customers[index++] = allCustomers.get(j); + Customer[] customers = new Customer[size]; + int index = 0; + for (int j = 0; j < allCustomers.size(); j++) { + if (allCustomers.get(j).getGroup() == findGroup) { + customers[index++] = allCustomers.get(j); + } } - } - if(order.equals("A") || order.equals("ASCENDING")) { - Arrays.sort(customers, Comparator.comparing(Customer::getCusTotalTime)); - for(int j = 0; j < customers.length; j++) { - System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); - } - } else { - Arrays.sort(customers, (o1, o2) -> o2.getCusTotalTime().compareTo(o1.getCusTotalTime())); - for(int j = 0; j < customers.length; j++) { - System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + if (String.valueOf(orderType).equals("ASCENDING")) { + Arrays.sort(customers, Comparator.comparing(Customer::getCusTotalTime)); + for (int j = 0; j < customers.length; j++) { + System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + } + } else { + Arrays.sort(customers, (o1, o2) -> o2.getCusTotalTime().compareTo(o1.getCusTotalTime())); + for (int j = 0; j < customers.length; j++) { + System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + } } } } @@ -156,36 +185,43 @@ private void summaryPay() { try { System.out.println("Which order (ASCENDING (A), DESCENDING (D))?"); String order = nextLine(Message.END_MSG); - for(int i = 0; i < allGroups.size(); i++) { - System.out.print("=============================="); - Group findGroup = allGroups.get(i); - System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), - findGroup.getParameter().getMinTime(), - findGroup.getParameter().getMinPay()); - System.out.println("=============================="); - int size = 0; - for(int j = 0; j < allCustomers.size(); j++) { - if(allCustomers.get(j).getGroup() == findGroup) { - size++; + + OrderType orderType = findOrder(order); + + if(orderType == null) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + }else { + for(int i = 0; i < allGroups.size(); i++) { + System.out.print("=============================="); + Group findGroup = allGroups.get(i); + System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), + findGroup.getParameter().getMinTime(), + findGroup.getParameter().getMinPay()); + System.out.println("=============================="); + int size = 0; + for(int j = 0; j < allCustomers.size(); j++) { + if(allCustomers.get(j).getGroup() == findGroup) { + size++; + } } - } - Customer[] customers = new Customer[size]; - int index = 0; - for(int j = 0; j < allCustomers.size(); j++) { - if(allCustomers.get(j).getGroup() == findGroup) { - customers[index++] = allCustomers.get(j); + Customer[] customers = new Customer[size]; + int index = 0; + for(int j = 0; j < allCustomers.size(); j++) { + if(allCustomers.get(j).getGroup() == findGroup) { + customers[index++] = allCustomers.get(j); + } } - } - if(order.equals("A") || order.equals("ASCENDING")) { - Arrays.sort(customers, Comparator.comparing(Customer::getCusTotalPay)); - for(int j = 0; j < customers.length; j++) { - System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); - } - } else { - Arrays.sort(customers, (o1, o2) -> o2.getCusTotalPay().compareTo(o1.getCusTotalPay())); - for(int j = 0; j < customers.length; j++) { - System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + if(String.valueOf(orderType).equals("ASCENDING")) { + Arrays.sort(customers, Comparator.comparing(Customer::getCusTotalPay)); + for(int j = 0; j < customers.length; j++) { + System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + } + } else { + Arrays.sort(customers, (o1, o2) -> o2.getCusTotalPay().compareTo(o1.getCusTotalPay())); + for(int j = 0; j < customers.length; j++) { + System.out.printf("No. %3d => %s \n", j + 1, customers[j].toString()); + } } } } From ea1306ea53141f28b4780b926ef1d6382178faa7 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Tue, 9 May 2023 00:36:30 +0900 Subject: [PATCH 22/30] =?UTF-8?q?style:=20Group=20=EC=9D=B4=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=EB=90=98=EC=97=88=EC=9D=84=20=EB=95=8C=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=EB=AC=B8,=20Message=20=EC=B6=9C=EB=A0=A5=EB=AC=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- me/smartstore/menu/GroupMenu.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/me/smartstore/menu/GroupMenu.java b/me/smartstore/menu/GroupMenu.java index 251a3d67..a49ccb81 100644 --- a/me/smartstore/menu/GroupMenu.java +++ b/me/smartstore/menu/GroupMenu.java @@ -99,9 +99,9 @@ private void inputParameter(Parameter parameter) { System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); }else { System.out.printf( - "_人人人人人人人人人人人人人人人人人人人人人人人人人人_\n" + + "_人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人_\n" + "> Success !!! %s <\n" + - " ̄^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄\n" + + " ̄^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄\n" + " .A__A ✨\uD83C\uDF82✨ A__A\n" + " ( •⩊•) _______ (•⩊• )\n" + " (>\uD83C\uDF70>) | | (<\uD83D\uDD2A<)\n", parameter); @@ -148,7 +148,7 @@ private void updateParameter() { inputParameter(group.getParameter()); allCustomers.refresh(allGroups); } else { - System.out.println(Message.ERR_MSG_INVALID_INPUT_EMPTY); + System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); System.out.println(); } } From 3565a27c6e1e3633bc7e0a9bb5ad9bfff8d32346 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Tue, 9 May 2023 00:40:32 +0900 Subject: [PATCH 23/30] =?UTF-8?q?fix:=20Customer=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=ED=95=A0=20=EC=8B=9C=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 고객을 추가할 때 잘못된 값이 입력되었을 때 NumberFormatException 예외처리 하도록 수정 - allCustomers.size() 의 값이 0일 경우 viewCustomer(), updateCustomer(), deleteCustomer() 메뉴 선택시 "No Customers. Please input one first." 출력문이 나오도록 수정 --- me/smartstore/menu/CustomerMenu.java | 179 +++++++++++++++------------ 1 file changed, 100 insertions(+), 79 deletions(-) diff --git a/me/smartstore/menu/CustomerMenu.java b/me/smartstore/menu/CustomerMenu.java index 3a55fd5d..1bd611aa 100644 --- a/me/smartstore/menu/CustomerMenu.java +++ b/me/smartstore/menu/CustomerMenu.java @@ -50,6 +50,11 @@ private void addCustomer() { break; }catch (InputEndException e) { System.out.println(Message.ERR_MSG_INPUT_END); + System.out.println(); + break; + }catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + System.out.println(); } } @@ -58,7 +63,7 @@ private void addCustomer() { private void customerInfoInput(int count) { Customer addCustomer = new Customer(); while(true) { - System.out.printf("====== Customer %d Info. ======\n", count); + System.out.printf("=============== Customer %d Info. ===============\n", count); int choice = chooseMenu(new String[]{ "Customer Name", "Customer ID", @@ -90,12 +95,10 @@ private void customerInfoInput(int count) { allCustomers.add(addCustomer); allCustomers.refresh(allGroups); System.out.printf( - "_人人人人人人人人人人人人人人人人人人人人人人人人人人_\n" + "> Success !!! %s <\n" + - " ̄^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄\n" + - " .A__A ✨\uD83C\uDF82✨ A__A\n" + - " ( •⩊•) _______ (•⩊• )\n" + - " (>\uD83C\uDF70>) | | (<\uD83D\uDD2A<)\n", addCustomer); + " .A__A ✨\uD83C\uDF82✨ A__A\n" + + " ( •⩊•) _______ (•⩊• )\n" + + " (>\uD83C\uDF70>) | | (<\uD83D\uDD2A<)\n", addCustomer); break; } } @@ -103,91 +106,109 @@ private void customerInfoInput(int count) { } private void viewCustomer() { - System.out.println("======= Customer Info. ======="); - for(int i = 0; i < allCustomers.size(); i++) { - System.out.printf("No. %3d => ", i + 1 ); - System.out.println(allCustomers.get(i)); + if(allCustomers.size() == 0) { + System.out.println(Message.ERR_MSG_INVALID_ARR_EMPTY); + System.out.println(); + }else { + System.out.println("======= Customer Info. ======="); + for(int i = 0; i < allCustomers.size(); i++) { + System.out.printf("No. %3d => ", i + 1 ); + System.out.println(allCustomers.get(i)); + System.out.println(); + } } } private void updateCustomer() { - while(true) { - try { - viewCustomer(); - System.out.printf("Which customer ( 1 ~ %d ) ? : ", allCustomers.size()); - int updateIndex = Integer.parseInt(nextLine(Message.END_MSG)); - Customer updateCustomer = allCustomers.get(updateIndex - 1); - while(true) { - int choice = chooseMenu(new String[]{ - "Customer Name", - "Customer ID", - "Customer Spent Time", - "Customer Total Pay", - "Back" - }); - if(choice == 1) { - System.out.print("Input Customer Name : "); - String customerName = nextLine(); - updateCustomer.setCusName(customerName); - }else if (choice == 2) { - System.out.print("Input Customer ID : "); - String customerId = nextLine(); - updateCustomer.setCusId(customerId); - }else if(choice == 3) { - System.out.print("Input Customer Spent Time : "); - int customerSpentTime = Integer.parseInt(nextLine()); - updateCustomer.setCusTotalTime(customerSpentTime); - }else if(choice == 4) { - System.out.print("Input Customer Total Pay : "); - int customerTotalPay = Integer.parseInt(nextLine()); - updateCustomer.setCusTotalPay(customerTotalPay); - }else { - allCustomers.refresh(allGroups); - System.out.printf( - "SUCCESS UPDATE!!\n" + - "%s\n" + - "두다다다다다다다\n" + - " (∩`・ω・)\n" + - "_/_ミつ/ ̄ ̄ ̄/\n" + - "  \/___/\n", updateCustomer); - break; + if(allCustomers.size() == 0) { + System.out.println(Message.ERR_MSG_INVALID_ARR_EMPTY); + System.out.println(); + }else { + while(true) { + try { + viewCustomer(); + System.out.printf("Which customer ( 1 ~ %d ) ? : ", allCustomers.size()); + int updateIndex = Integer.parseInt(nextLine(Message.END_MSG)); + Customer updateCustomer = allCustomers.get(updateIndex - 1); + while(true) { + int choice = chooseMenu(new String[]{ + "Customer Name", + "Customer ID", + "Customer Spent Time", + "Customer Total Pay", + "Back" + }); + if(choice == 1) { + System.out.print("Input Customer Name : "); + String customerName = nextLine(); + updateCustomer.setCusName(customerName); + }else if (choice == 2) { + System.out.print("Input Customer ID : "); + String customerId = nextLine(); + updateCustomer.setCusId(customerId); + }else if(choice == 3) { + System.out.print("Input Customer Spent Time : "); + int customerSpentTime = Integer.parseInt(nextLine()); + updateCustomer.setCusTotalTime(customerSpentTime); + }else if(choice == 4) { + System.out.print("Input Customer Total Pay : "); + int customerTotalPay = Integer.parseInt(nextLine()); + updateCustomer.setCusTotalPay(customerTotalPay); + }else { + allCustomers.refresh(allGroups); + System.out.printf( + "SUCCESS UPDATE!!\n" + + "%s\n" + + "두다다다다다다다\n" + + " (∩`・ω・)\n" + + "_/_ミつ/ ̄ ̄ ̄/\n" + + "  \/___/\n", updateCustomer); + break; + } } + }catch (InputEndException e ) { + System.out.println(Message.ERR_MSG_INPUT_END); + break; + }catch (NumberFormatException e){ + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + }catch (IndexOutOfBoundsException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); } - }catch (InputEndException e ) { - System.out.println(Message.ERR_MSG_INPUT_END); - break; - }catch (NumberFormatException e){ - System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); - }catch (IndexOutOfBoundsException e) { - System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); } } } private void deleteCustomer() { - while(true) { - try { - viewCustomer(); - System.out.printf("Which customer ( 1 ~ %d ) ? : ", allCustomers.size()); - int updateIndex = Integer.parseInt(nextLine(Message.END_MSG)); - allCustomers.pop(updateIndex - 1); - System.out.println( - "SUCCESS DELETE!!\n" + - "두다다다다다다다\n" + - "두다다다다다다다\n" + - " (∩`・ω・)\n" + - "_/_ミつ/ ̄ ̄ ̄/\n" + - "  \/___/\n"); - }catch (InputEndException e) { - System.out.println(Message.ERR_MSG_INPUT_END); - break; - }catch (NumberFormatException e) { - System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); - }catch (IndexOutOfBoundsException e) { - System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + if(allCustomers.size() == 0) { + System.out.println(Message.ERR_MSG_INVALID_ARR_EMPTY); + System.out.println(); + }else { + while(true) { + try { + viewCustomer(); + if(allCustomers.size() == 0) { + System.out.println(Message.ERR_MSG_INVALID_ARR_EMPTY); + break; + } + System.out.printf("Which customer ( 1 ~ %d ) ? : ", allCustomers.size()); + int updateIndex = Integer.parseInt(nextLine(Message.END_MSG)); + allCustomers.pop(updateIndex - 1); + System.out.println( + "SUCCESS DELETE!!\n" + + "두다다다다다다다\n" + + "두다다다다다다다\n" + + " (∩`・ω・)\n" + + "_/_ミつ/ ̄ ̄ ̄/\n" + + "  \/___/\n"); + }catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + break; + }catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + }catch (IndexOutOfBoundsException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } } - } - } } From d41f83d6f39cb8ebcdd765bc7c794371e13dd304 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Tue, 9 May 2023 20:03:42 +0900 Subject: [PATCH 24/30] =?UTF-8?q?refactor:=20null=20=EC=B2=98=EB=A6=AC,=20?= =?UTF-8?q?Group=20=EC=83=9D=EC=84=B1=EC=9E=90=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EA=B0=9D=EC=B2=B4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - set 메서드를 사용하지 않고 생성자를 사용하도록 리펙터링 함 - Group 생성자에 Parameter, GroupType 에 null 이 들어올 경우 NullArgumentException 에러를 던지도록 리펙터링 --- me/smartstore/group/Group.java | 10 ++++++++-- me/smartstore/menu/GroupMenu.java | 29 ++++++++++------------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/me/smartstore/group/Group.java b/me/smartstore/group/Group.java index afcd0b4e..ee40263a 100644 --- a/me/smartstore/group/Group.java +++ b/me/smartstore/group/Group.java @@ -1,5 +1,7 @@ package me.smartstore.group; +import me.smartstore.exception.NullArgumentException; + import java.util.Objects; public class Group { @@ -10,8 +12,12 @@ public Group() { } public Group(Parameter parameter, GroupType groupType) { - this.parameter = parameter; - this.groupType = groupType; + if(parameter.getMinTime() == null || parameter.getMinPay() == null || groupType == null){ + throw new NullArgumentException(); + }else { + this.parameter = parameter; + this.groupType = groupType; + } } public Parameter getParameter() { diff --git a/me/smartstore/menu/GroupMenu.java b/me/smartstore/menu/GroupMenu.java index a49ccb81..69c067a8 100644 --- a/me/smartstore/menu/GroupMenu.java +++ b/me/smartstore/menu/GroupMenu.java @@ -45,7 +45,7 @@ public void setParameter() { // 초기화할 때만 호출 가능 while ( true ) { try { GroupType groupType = chooseGroup(); - if(groupType == null) { + if (groupType == null) { break; } // GroupType에 해당하는 group 객체를 찾아야 함 @@ -58,23 +58,15 @@ public void setParameter() { // 초기화할 때만 호출 가능 // time, pay 사용자 입력받은 후, 설정 필요 inputParameter(parameter); - if(parameter.getMinPay() == null || parameter.getMinTime() == null) { - System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); - }else { - Group addGroup = new Group(); - addGroup.setParameter(parameter); - addGroup.setGroupType(groupType); - allGroups.add(addGroup); - allCustomers.refresh(allGroups); // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 - break; - } + Group addGroup = new Group(parameter, groupType); + allGroups.add(addGroup); + allCustomers.refresh(allGroups); // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 + break; + } }catch (NullArgumentException e) { System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); - System.out.println(); - break; } - } } @@ -96,15 +88,15 @@ private void inputParameter(Parameter parameter) { System.out.println(parameter); } else { if(parameter.getMinPay() == null || parameter.getMinTime() == null) { - System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); + break; }else { System.out.printf( "_人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人_\n" + "> Success !!! %s <\n" + " ̄^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄\n" + - " .A__A ✨\uD83C\uDF82✨ A__A\n" + - " ( •⩊•) _______ (•⩊• )\n" + - " (>\uD83C\uDF70>) | | (<\uD83D\uDD2A<)\n", parameter); + " .A__A ✨\uD83C\uDF82✨ A__A\n" + + " ( •⩊•) _______ (•⩊• )\n" + + " (>\uD83C\uDF70>) | | (<\uD83D\uDD2A<)\n", parameter); break; } } @@ -130,7 +122,6 @@ private void viewParameter() { System.out.println("──────────────────────────────────────────"); } else { System.out.printf("Please Set Parameter first %s\n", groupType); -// System.out.println(Message.ERR_MSG_INVALID_INPUT_EMPTY); System.out.println(); } } From 1dba2bf30061bb8a6d3dc07843423b28298f729e Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Tue, 9 May 2023 21:13:35 +0900 Subject: [PATCH 25/30] =?UTF-8?q?fix:=20Enter=20=EB=A5=BC=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=EB=B0=9B=EC=9D=84=20=EC=8B=9C=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Customer Name, Customer ID Enter 로 입력 받을 시 InputEmptyException 예외를 던지도록 수정 - Customer 에 setCusName(), setCusId() 메서드에 예외처리 기능 추가 - NumberFormatException 예외 처리 customerInfoInput 메서드 안쪽으로 이동 --- me/smartstore/customer/Customer.java | 15 ++++- me/smartstore/menu/CustomerMenu.java | 97 +++++++++++++++------------- 2 files changed, 64 insertions(+), 48 deletions(-) diff --git a/me/smartstore/customer/Customer.java b/me/smartstore/customer/Customer.java index 563d79f4..3cf8ec75 100644 --- a/me/smartstore/customer/Customer.java +++ b/me/smartstore/customer/Customer.java @@ -1,9 +1,12 @@ package me.smartstore.customer; +import me.smartstore.exception.InputEmptyException; import me.smartstore.group.Group; import me.smartstore.group.GroupType; import me.smartstore.group.Parameter; +import java.util.EmptyStackException; + public class Customer { private String cusName; private String cusId; @@ -37,7 +40,11 @@ public String getCusName() { } public void setCusName(String cusName) { - this.cusName = cusName; + if(cusName.equals("")){ + throw new InputEmptyException(); + }else { + this.cusName = cusName; + } } public String getCusId() { @@ -45,7 +52,11 @@ public String getCusId() { } public void setCusId(String cusId) { - this.cusId = cusId; + if(cusId.equals("")){ + throw new InputEmptyException(); + }else { + this.cusId = cusId; + } } public Integer getCusTotalTime() { diff --git a/me/smartstore/menu/CustomerMenu.java b/me/smartstore/menu/CustomerMenu.java index 1bd611aa..88415108 100644 --- a/me/smartstore/menu/CustomerMenu.java +++ b/me/smartstore/menu/CustomerMenu.java @@ -2,6 +2,7 @@ import me.smartstore.customer.Customer; import me.smartstore.customer.Customers; +import me.smartstore.exception.InputEmptyException; import me.smartstore.exception.InputEndException; import me.smartstore.group.Groups; import me.smartstore.util.Message; @@ -30,7 +31,8 @@ public void manage() { "View Customer", "Update Customer", "Delete Customer", - "Back"}); + "Back" + }); if(choice == 1) addCustomer(); else if(choice == 2) viewCustomer(); else if(choice == 3) updateCustomer(); @@ -52,55 +54,58 @@ private void addCustomer() { System.out.println(Message.ERR_MSG_INPUT_END); System.out.println(); break; - }catch (NumberFormatException e) { - System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); - System.out.println(); } - } } private void customerInfoInput(int count) { Customer addCustomer = new Customer(); while(true) { - System.out.printf("=============== Customer %d Info. ===============\n", count); - int choice = chooseMenu(new String[]{ - "Customer Name", - "Customer ID", - "Customer Spent Time", - "Customer Total Pay", - "Back" - }); - if(choice == 1) { - System.out.print("Input Customer Name : "); - String customerName = nextLine(); - addCustomer.setCusName(customerName); - }else if (choice == 2) { - System.out.print("Input Customer ID : "); - String customerId = nextLine(); - addCustomer.setCusId(customerId); - }else if(choice == 3) { - System.out.print("Input Customer Spent Time : "); - int customerSpentTime = Integer.parseInt(nextLine()); - addCustomer.setCusTotalTime(customerSpentTime); - }else if(choice == 4) { - System.out.print("Input Customer Total Pay : "); - int customerTotalPay = Integer.parseInt(nextLine()); - addCustomer.setCusTotalPay(customerTotalPay); - }else { - if(addCustomer.getCusId() == null || addCustomer.getCusName() == null || - addCustomer.getCusTotalTime() == null || addCustomer.getCusTotalPay() == null) { - System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); + try { + System.out.printf("=============== Customer %d Info. ===============\n", count); + int choice = chooseMenu(new String[]{ + "Customer Name", + "Customer ID", + "Customer Spent Time", + "Customer Total Pay", + "Back" + }); + if(choice == 1) { + System.out.print("Input Customer Name : "); + String customerName = nextLine(Message.END_MSG); + addCustomer.setCusName(customerName); + }else if (choice == 2) { + System.out.print("Input Customer ID : "); + String customerId = nextLine(Message.END_MSG); + addCustomer.setCusId(customerId); + }else if(choice == 3) { + System.out.print("Input Customer Spent Time : "); + int customerSpentTime = Integer.parseInt(nextLine(Message.END_MSG)); + addCustomer.setCusTotalTime(customerSpentTime); + }else if(choice == 4) { + System.out.print("Input Customer Total Pay : "); + int customerTotalPay = Integer.parseInt(nextLine(Message.END_MSG)); + addCustomer.setCusTotalPay(customerTotalPay); }else { - allCustomers.add(addCustomer); - allCustomers.refresh(allGroups); - System.out.printf( - "> Success !!! %s <\n" + - " .A__A ✨\uD83C\uDF82✨ A__A\n" + - " ( •⩊•) _______ (•⩊• )\n" + - " (>\uD83C\uDF70>) | | (<\uD83D\uDD2A<)\n", addCustomer); - break; + if(addCustomer.getCusId() == null || addCustomer.getCusName() == null || + addCustomer.getCusTotalTime() == null || addCustomer.getCusTotalPay() == null) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); + }else { + allCustomers.add(addCustomer); + allCustomers.refresh(allGroups); + System.out.printf( + "> Success !!! %s <\n" + + " .A__A ✨\uD83C\uDF82✨ A__A\n" + + " ( •⩊•) _______ (•⩊• )\n" + + " (>\uD83C\uDF70>) | | (<\uD83D\uDD2A<)\n", addCustomer); + break; + } } + }catch (InputEmptyException e){ + System.out.println(Message.ERR_MSG_INVALID_INPUT_EMPTY); + }catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + System.out.println(); } } } @@ -158,11 +163,11 @@ private void updateCustomer() { allCustomers.refresh(allGroups); System.out.printf( "SUCCESS UPDATE!!\n" + - "%s\n" + - "두다다다다다다다\n" + - " (∩`・ω・)\n" + - "_/_ミつ/ ̄ ̄ ̄/\n" + - "  \/___/\n", updateCustomer); + "%s\n" + + "두다다다다다다다\n" + + " (∩`・ω・)\n" + + "_/_ミつ/ ̄ ̄ ̄/\n" + + "  \/___/\n", updateCustomer); break; } } From f5b2a3371537e8a415fec92f3cb6e6fe91a62af1 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Wed, 10 May 2023 01:16:18 +0900 Subject: [PATCH 26/30] =?UTF-8?q?style:=20=ED=95=84=EC=9A=94=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20import=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- me/smartstore/customer/Customer.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/me/smartstore/customer/Customer.java b/me/smartstore/customer/Customer.java index 3cf8ec75..58a1cb51 100644 --- a/me/smartstore/customer/Customer.java +++ b/me/smartstore/customer/Customer.java @@ -5,8 +5,6 @@ import me.smartstore.group.GroupType; import me.smartstore.group.Parameter; -import java.util.EmptyStackException; - public class Customer { private String cusName; private String cusId; From b3c2299b648990baca67d1f8dfa2958481a4d191 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Wed, 10 May 2023 01:22:28 +0900 Subject: [PATCH 27/30] =?UTF-8?q?refactor:=20Groups=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=97=90=20findAllGroup=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 refresh() 함수는 분류기준이 바뀔 때, 새로운 고객이 들어올 때 실행되는 함수로 모든 Group 을 가져와야 하는 로직을 Groups 에게로 옮겨서 refresh() 함수는 groups.findAllGroup() 로 모든 Group 을 불러오도록 수정하였다. --- me/smartstore/customer/Customers.java | 16 +++++++--------- me/smartstore/group/Groups.java | 8 ++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/me/smartstore/customer/Customers.java b/me/smartstore/customer/Customers.java index 6596a092..a4284433 100644 --- a/me/smartstore/customer/Customers.java +++ b/me/smartstore/customer/Customers.java @@ -3,6 +3,7 @@ import me.smartstore.arrays.DArray; import me.smartstore.group.Group; +import me.smartstore.group.GroupType; import me.smartstore.group.Groups; import java.util.Arrays; @@ -25,20 +26,17 @@ private Customers() {} // 2. 새로운 고객이 들어올 때 public void refresh(Groups groups) { - Group[] fixGroup = new Group[groups.size()]; - for(int i = 0; i < groups.size(); i++) { - fixGroup[i] = groups.get(i); - } + Group[] allGroup = groups.findAllGroup(); - Arrays.sort(fixGroup, (o1, o2) -> o1.getParameter().getMinPay() != o2.getParameter().getMinPay() ? + Arrays.sort(allGroup, (o1, o2) -> o1.getParameter().getMinPay() != o2.getParameter().getMinPay() ? o1.getParameter().getMinPay() - o2.getParameter().getMinPay() : o1.getParameter().getMinTime() - o2.getParameter().getMinTime()); for(int i = 0; i < this.size(); i++) { - for(int j = 0; j <= fixGroup.length - 1; j++) { - if(this.get(i).getCusTotalTime() >= fixGroup[j].getParameter().getMinTime() && - this.get(i).getCusTotalPay() >= fixGroup[j].getParameter().getMinPay()) { - this.get(i).setGroup(fixGroup[j]); + for(int j = 0; j <= allGroup.length - 1; j++) { + if(this.get(i).getCusTotalTime() >= allGroup[j].getParameter().getMinTime() && + this.get(i).getCusTotalPay() >= allGroup[j].getParameter().getMinPay()) { + this.get(i).setGroup(allGroup[j]); } } } diff --git a/me/smartstore/group/Groups.java b/me/smartstore/group/Groups.java index 996c558e..c67396b6 100644 --- a/me/smartstore/group/Groups.java +++ b/me/smartstore/group/Groups.java @@ -22,4 +22,12 @@ public Group find(GroupType groupType) { } return null; } + + public Group[] findAllGroup() { + Group[] result = new Group[this.size]; + for(int i = 0; i < this.size; i++) { + result[i] = this.get(i); + } + return result; + } } From 16668d683f8aa81b3daa296ee4cd8bab567560de Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Mon, 15 May 2023 15:49:30 +0900 Subject: [PATCH 28/30] =?UTF-8?q?refactor:=20addCustomer(),=20updateCustom?= =?UTF-8?q?er()=20=EC=A4=91=EB=B3=B5=EB=90=9C=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8E=99=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 코드의 중복을 피하기 위해서 customerInfoInput() 메서드를 이용하여 customer 를 수정하거나 추가할 때 사용하도록 수정 --- me/smartstore/menu/CustomerMenu.java | 93 ++++++++-------------------- 1 file changed, 27 insertions(+), 66 deletions(-) diff --git a/me/smartstore/menu/CustomerMenu.java b/me/smartstore/menu/CustomerMenu.java index 88415108..2bc92ed2 100644 --- a/me/smartstore/menu/CustomerMenu.java +++ b/me/smartstore/menu/CustomerMenu.java @@ -47,7 +47,15 @@ private void addCustomer() { System.out.println("How many customers to input : "); int inputCount = Integer.parseInt(nextLine(Message.END_MSG)); for(int i = 0; i < inputCount; i++) { - customerInfoInput(i + 1); + System.out.printf("=============== Customer %d Info. ===============\n", i + 1); + Customer addCustomer = customerInfoInput(new Customer()); + allCustomers.add(addCustomer); + allCustomers.refresh(allGroups); + System.out.printf( + "> Success !!! %s <\n" + + " .A__A ✨\uD83C\uDF82✨ A__A\n" + + " ( •⩊•) _______ (•⩊• )\n" + + " (>\uD83C\uDF70>) | | (<\uD83D\uDD2A<)\n", addCustomer); } break; }catch (InputEndException e) { @@ -58,11 +66,9 @@ private void addCustomer() { } } - private void customerInfoInput(int count) { - Customer addCustomer = new Customer(); + private Customer customerInfoInput(Customer customer) { while(true) { try { - System.out.printf("=============== Customer %d Info. ===============\n", count); int choice = chooseMenu(new String[]{ "Customer Name", "Customer ID", @@ -72,40 +78,30 @@ private void customerInfoInput(int count) { }); if(choice == 1) { System.out.print("Input Customer Name : "); - String customerName = nextLine(Message.END_MSG); - addCustomer.setCusName(customerName); + customer.setCusName(nextLine(Message.END_MSG)); }else if (choice == 2) { System.out.print("Input Customer ID : "); - String customerId = nextLine(Message.END_MSG); - addCustomer.setCusId(customerId); + customer.setCusId(nextLine(Message.END_MSG)); }else if(choice == 3) { System.out.print("Input Customer Spent Time : "); - int customerSpentTime = Integer.parseInt(nextLine(Message.END_MSG)); - addCustomer.setCusTotalTime(customerSpentTime); + customer.setCusTotalTime(Integer.parseInt(nextLine(Message.END_MSG))); }else if(choice == 4) { System.out.print("Input Customer Total Pay : "); - int customerTotalPay = Integer.parseInt(nextLine(Message.END_MSG)); - addCustomer.setCusTotalPay(customerTotalPay); + customer.setCusTotalPay(Integer.parseInt(nextLine(Message.END_MSG))); }else { - if(addCustomer.getCusId() == null || addCustomer.getCusName() == null || - addCustomer.getCusTotalTime() == null || addCustomer.getCusTotalPay() == null) { + if(customer.getCusId() == null || customer.getCusName() == null || + customer.getCusTotalTime() == null || customer.getCusTotalPay() == null) { System.out.println(Message.ERR_MSG_INVALID_INPUT_NULL); }else { - allCustomers.add(addCustomer); - allCustomers.refresh(allGroups); - System.out.printf( - "> Success !!! %s <\n" + - " .A__A ✨\uD83C\uDF82✨ A__A\n" + - " ( •⩊•) _______ (•⩊• )\n" + - " (>\uD83C\uDF70>) | | (<\uD83D\uDD2A<)\n", addCustomer); - break; + return customer; } } }catch (InputEmptyException e){ System.out.println(Message.ERR_MSG_INVALID_INPUT_EMPTY); }catch (NumberFormatException e) { System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); - System.out.println(); + } catch (IndexOutOfBoundsException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); } } } @@ -115,12 +111,14 @@ private void viewCustomer() { System.out.println(Message.ERR_MSG_INVALID_ARR_EMPTY); System.out.println(); }else { - System.out.println("======= Customer Info. ======="); - for(int i = 0; i < allCustomers.size(); i++) { + System.out.println("======================================== Customer Info. ========================================"); + int size = allCustomers.size(); + for(int i = 0; i < size; i++) { System.out.printf("No. %3d => ", i + 1 ); System.out.println(allCustomers.get(i)); System.out.println(); } + System.out.println("=================================================================================================="); } } @@ -135,49 +133,12 @@ private void updateCustomer() { System.out.printf("Which customer ( 1 ~ %d ) ? : ", allCustomers.size()); int updateIndex = Integer.parseInt(nextLine(Message.END_MSG)); Customer updateCustomer = allCustomers.get(updateIndex - 1); - while(true) { - int choice = chooseMenu(new String[]{ - "Customer Name", - "Customer ID", - "Customer Spent Time", - "Customer Total Pay", - "Back" - }); - if(choice == 1) { - System.out.print("Input Customer Name : "); - String customerName = nextLine(); - updateCustomer.setCusName(customerName); - }else if (choice == 2) { - System.out.print("Input Customer ID : "); - String customerId = nextLine(); - updateCustomer.setCusId(customerId); - }else if(choice == 3) { - System.out.print("Input Customer Spent Time : "); - int customerSpentTime = Integer.parseInt(nextLine()); - updateCustomer.setCusTotalTime(customerSpentTime); - }else if(choice == 4) { - System.out.print("Input Customer Total Pay : "); - int customerTotalPay = Integer.parseInt(nextLine()); - updateCustomer.setCusTotalPay(customerTotalPay); - }else { - allCustomers.refresh(allGroups); - System.out.printf( - "SUCCESS UPDATE!!\n" + - "%s\n" + - "두다다다다다다다\n" + - " (∩`・ω・)\n" + - "_/_ミつ/ ̄ ̄ ̄/\n" + - "  \/___/\n", updateCustomer); - break; - } - } - }catch (InputEndException e ) { + customerInfoInput(updateCustomer); + allCustomers.refresh(allGroups); + }catch (InputEndException e) { System.out.println(Message.ERR_MSG_INPUT_END); + System.out.println(); break; - }catch (NumberFormatException e){ - System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); - }catch (IndexOutOfBoundsException e) { - System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); } } } From b33d4b0d05f0d724c818c616a2cdde31e1766550 Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Mon, 15 May 2023 16:03:52 +0900 Subject: [PATCH 29/30] =?UTF-8?q?refactor:=20allGroups,=20allCustomers=20s?= =?UTF-8?q?ize=20=ED=98=B8=EC=B6=9C=20=EB=A6=AC=ED=8E=99=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 반복문 for 문 안에서 메서드를 호출하는 것 보다는 바깥쪽에서 호출한 상태에서 진행하는 것이 속도 면에서 이점을 받을 수 있어서 수정 --- me/smartstore/menu/SummaryMenu.java | 30 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/me/smartstore/menu/SummaryMenu.java b/me/smartstore/menu/SummaryMenu.java index db589008..280af1f6 100644 --- a/me/smartstore/menu/SummaryMenu.java +++ b/me/smartstore/menu/SummaryMenu.java @@ -48,7 +48,9 @@ public void manage() { } private void summary() { - for (int i = 0; i < allGroups.size(); i++) { + int groupSize = allGroups.size(); + int customerSize = allCustomers.size(); + for (int i = 0; i < groupSize; i++) { System.out.print("=============================="); Group findGroup = allGroups.get(i); System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), @@ -56,7 +58,7 @@ private void summary() { findGroup.getParameter().getMinPay()); System.out.println("=============================="); int count = 1; - for (int j = 0; j < allCustomers.size(); j++) { + for (int j = 0; j < customerSize; j++) { if (allCustomers.get(j).getGroup() == findGroup) { System.out.printf("No. %3d => %s \n", count++, allCustomers.get(j).toString()); } @@ -66,6 +68,8 @@ private void summary() { } private void summaryName() { + int groupSize = allGroups.size(); + int customerSize = allCustomers.size(); while(true) { try { System.out.println("Which order (ASCENDING (A), DESCENDING (D))?"); @@ -75,7 +79,7 @@ private void summaryName() { if(orderType == null) { System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); }else { - for(int i = 0; i < allGroups.size(); i++) { + for(int i = 0; i < groupSize; i++) { System.out.print("=============================="); Group findGroup = allGroups.get(i); System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), @@ -83,14 +87,14 @@ private void summaryName() { findGroup.getParameter().getMinPay()); System.out.println("=============================="); int size = 0; - for (int j = 0; j < allCustomers.size(); j++) { + for (int j = 0; j < customerSize; j++) { if (allCustomers.get(j).getGroup() == findGroup) { size++; } } Customer[] customers = new Customer[size]; int index = 0; - for (int j = 0; j < allCustomers.size(); j++) { + for (int j = 0; j < customerSize; j++) { if (allCustomers.get(j).getGroup() == findGroup) { customers[index++] = allCustomers.get(j); } @@ -130,6 +134,8 @@ private OrderType findOrder(String order) { } private void summaryTime() { + int groupSize = allGroups.size(); + int customerSize = allCustomers.size(); while(true) { try { System.out.println("Which order (ASCENDING (A), DESCENDING (D))?"); @@ -139,7 +145,7 @@ private void summaryTime() { if(orderType == null) { System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); }else { - for(int i = 0; i < allGroups.size(); i++) { + for(int i = 0; i < groupSize; i++) { System.out.print("=============================="); Group findGroup = allGroups.get(i); System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), @@ -147,14 +153,14 @@ private void summaryTime() { findGroup.getParameter().getMinPay()); System.out.println("=============================="); int size = 0; - for (int j = 0; j < allCustomers.size(); j++) { + for (int j = 0; j < customerSize; j++) { if (allCustomers.get(j).getGroup() == findGroup) { size++; } } Customer[] customers = new Customer[size]; int index = 0; - for (int j = 0; j < allCustomers.size(); j++) { + for (int j = 0; j < customerSize; j++) { if (allCustomers.get(j).getGroup() == findGroup) { customers[index++] = allCustomers.get(j); } @@ -181,6 +187,8 @@ private void summaryTime() { } private void summaryPay() { + int groupSize = allGroups.size(); + int customerSize = allCustomers.size(); while(true) { try { System.out.println("Which order (ASCENDING (A), DESCENDING (D))?"); @@ -191,7 +199,7 @@ private void summaryPay() { if(orderType == null) { System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); }else { - for(int i = 0; i < allGroups.size(); i++) { + for(int i = 0; i < groupSize; i++) { System.out.print("=============================="); Group findGroup = allGroups.get(i); System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), @@ -199,14 +207,14 @@ private void summaryPay() { findGroup.getParameter().getMinPay()); System.out.println("=============================="); int size = 0; - for(int j = 0; j < allCustomers.size(); j++) { + for(int j = 0; j < customerSize; j++) { if(allCustomers.get(j).getGroup() == findGroup) { size++; } } Customer[] customers = new Customer[size]; int index = 0; - for(int j = 0; j < allCustomers.size(); j++) { + for(int j = 0; j < customerSize; j++) { if(allCustomers.get(j).getGroup() == findGroup) { customers[index++] = allCustomers.get(j); } From 936a72f3ded0176d26b33cdbf5e483cbd79353ac Mon Sep 17 00:00:00 2001 From: seoyonghyun Date: Mon, 15 May 2023 20:07:45 +0900 Subject: [PATCH 30/30] =?UTF-8?q?refactor:=20Customers=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EC=97=90=20groupCount(),=20findCustomerByGro?= =?UTF-8?q?up=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SummaryMenu 에서 매개변수로 들어온 group 에 속한 Customer 의 수를 카운팅 해주는 groupCount 추가 모든 Customer 의 정보를 가져오기 위한 메서드 findCustomerByGroup 메서드 추가 SummaryMenu 에 중복되어 있는 코드를 모두 수정 --- me/smartstore/customer/Customers.java | 23 ++++++- me/smartstore/menu/SummaryMenu.java | 86 +++++++-------------------- 2 files changed, 42 insertions(+), 67 deletions(-) diff --git a/me/smartstore/customer/Customers.java b/me/smartstore/customer/Customers.java index a4284433..49370c4f 100644 --- a/me/smartstore/customer/Customers.java +++ b/me/smartstore/customer/Customers.java @@ -3,7 +3,6 @@ import me.smartstore.arrays.DArray; import me.smartstore.group.Group; -import me.smartstore.group.GroupType; import me.smartstore.group.Groups; import java.util.Arrays; @@ -42,4 +41,26 @@ public void refresh(Groups groups) { } } + public int groupCount(Group group) { + int count = 0; + for(int i = 0; i < this.size; i++) { + if(this.get(i).getGroup() == group) { + count++; + } + } + return count; + } + + public Customer[] findCustomerByGroup(Group group) { + Customer[] customers = new Customer[groupCount(group)]; + + int index = 0; + for(int i = 0; i < this.size; i++) { + if(this.get(i).getGroup() == group) { + customers[index++] = this.get(i); + } + } + return customers; + } + } diff --git a/me/smartstore/menu/SummaryMenu.java b/me/smartstore/menu/SummaryMenu.java index 280af1f6..7ccd1ba5 100644 --- a/me/smartstore/menu/SummaryMenu.java +++ b/me/smartstore/menu/SummaryMenu.java @@ -51,12 +51,7 @@ private void summary() { int groupSize = allGroups.size(); int customerSize = allCustomers.size(); for (int i = 0; i < groupSize; i++) { - System.out.print("=============================="); - Group findGroup = allGroups.get(i); - System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), - findGroup.getParameter().getMinTime(), - findGroup.getParameter().getMinPay()); - System.out.println("=============================="); + Group findGroup = showGroupInfo(i); int count = 1; for (int j = 0; j < customerSize; j++) { if (allCustomers.get(j).getGroup() == findGroup) { @@ -69,7 +64,6 @@ private void summary() { private void summaryName() { int groupSize = allGroups.size(); - int customerSize = allCustomers.size(); while(true) { try { System.out.println("Which order (ASCENDING (A), DESCENDING (D))?"); @@ -80,25 +74,9 @@ private void summaryName() { System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); }else { for(int i = 0; i < groupSize; i++) { - System.out.print("=============================="); - Group findGroup = allGroups.get(i); - System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), - findGroup.getParameter().getMinTime(), - findGroup.getParameter().getMinPay()); - System.out.println("=============================="); - int size = 0; - for (int j = 0; j < customerSize; j++) { - if (allCustomers.get(j).getGroup() == findGroup) { - size++; - } - } - Customer[] customers = new Customer[size]; - int index = 0; - for (int j = 0; j < customerSize; j++) { - if (allCustomers.get(j).getGroup() == findGroup) { - customers[index++] = allCustomers.get(j); - } - } + Group findGroup = showGroupInfo(i); + + Customer[] customers = allCustomers.findCustomerByGroup(findGroup); if (String.valueOf(orderType).equals("ASCENDING")) { Arrays.sort(customers, Comparator.comparing(Customer::getCusName)); @@ -135,7 +113,6 @@ private OrderType findOrder(String order) { private void summaryTime() { int groupSize = allGroups.size(); - int customerSize = allCustomers.size(); while(true) { try { System.out.println("Which order (ASCENDING (A), DESCENDING (D))?"); @@ -146,25 +123,9 @@ private void summaryTime() { System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); }else { for(int i = 0; i < groupSize; i++) { - System.out.print("=============================="); - Group findGroup = allGroups.get(i); - System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), - findGroup.getParameter().getMinTime(), - findGroup.getParameter().getMinPay()); - System.out.println("=============================="); - int size = 0; - for (int j = 0; j < customerSize; j++) { - if (allCustomers.get(j).getGroup() == findGroup) { - size++; - } - } - Customer[] customers = new Customer[size]; - int index = 0; - for (int j = 0; j < customerSize; j++) { - if (allCustomers.get(j).getGroup() == findGroup) { - customers[index++] = allCustomers.get(j); - } - } + Group findGroup = showGroupInfo(i); + + Customer[] customers = allCustomers.findCustomerByGroup(findGroup); if (String.valueOf(orderType).equals("ASCENDING")) { Arrays.sort(customers, Comparator.comparing(Customer::getCusTotalTime)); @@ -188,7 +149,6 @@ private void summaryTime() { private void summaryPay() { int groupSize = allGroups.size(); - int customerSize = allCustomers.size(); while(true) { try { System.out.println("Which order (ASCENDING (A), DESCENDING (D))?"); @@ -200,25 +160,9 @@ private void summaryPay() { System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); }else { for(int i = 0; i < groupSize; i++) { - System.out.print("=============================="); - Group findGroup = allGroups.get(i); - System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), - findGroup.getParameter().getMinTime(), - findGroup.getParameter().getMinPay()); - System.out.println("=============================="); - int size = 0; - for(int j = 0; j < customerSize; j++) { - if(allCustomers.get(j).getGroup() == findGroup) { - size++; - } - } - Customer[] customers = new Customer[size]; - int index = 0; - for(int j = 0; j < customerSize; j++) { - if(allCustomers.get(j).getGroup() == findGroup) { - customers[index++] = allCustomers.get(j); - } - } + Group findGroup = showGroupInfo(i); + + Customer[] customers = allCustomers.findCustomerByGroup(findGroup); if(String.valueOf(orderType).equals("ASCENDING")) { Arrays.sort(customers, Comparator.comparing(Customer::getCusTotalPay)); @@ -239,4 +183,14 @@ private void summaryPay() { } } } + + private Group showGroupInfo(int i) { + System.out.print("=============================="); + Group findGroup = allGroups.get(i); + System.out.printf("Group : %s ( Time : %d, Pay : %d )", findGroup.getGroupType(), + findGroup.getParameter().getMinTime(), + findGroup.getParameter().getMinPay()); + System.out.println("=============================="); + return findGroup; + } }