From 9b186dd6ba6dcd59dd9893b0e5a3437e97562b38 Mon Sep 17 00:00:00 2001 From: ParkSeongUk Date: Tue, 9 May 2023 14:36:45 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[1=EC=B0=A8=20VER1.0...]=20Java=20ToyProjec?= =?UTF-8?q?t=20upload=20by=20ParkSeongWook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 3 +++ .idea/KDTBE5_Java_ToyProject.iml | 11 +++++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ 5 files changed, 34 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/KDTBE5_Java_ToyProject.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/KDTBE5_Java_ToyProject.iml b/.idea/KDTBE5_Java_ToyProject.iml new file mode 100644 index 00000000..8545f145 --- /dev/null +++ b/.idea/KDTBE5_Java_ToyProject.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..639900d1 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..576cf688 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From 7f26317e626e11b9863525c06daa1419dc03ff18 Mon Sep 17 00:00:00 2001 From: ParkSeongUk Date: Wed, 10 May 2023 23:28:24 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[1=EC=B0=A8=20VER1.1...]=20Java=20ToyProjec?= =?UTF-8?q?t=20upload=20by=20ParkSeongWook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 6 + .idea/KDTBE5_Java_ToyProject.iml | 28 ++++ .idea/misc.xml | 2 +- .idea/uiDesigner.xml | 124 ++++++++++++++ me.smartstore/Main.java | 6 + me.smartstore/SmartStoreApp.java | 63 +++++++ me.smartstore/arrays/Collections.java | 13 ++ me.smartstore/arrays/DArray.java | 140 ++++++++++++++++ me.smartstore/customer/Customer.java | 105 ++++++++++++ me.smartstore/customer/Customers.java | 72 ++++++++ .../exception/ArrayEmptyException.java | 14 ++ .../exception/ElementNotFoundException.java | 22 +++ .../exception/EmptyArrayException.java | 22 +++ .../exception/InputEmptyException.java | 15 ++ .../exception/InputEndException.java | 13 ++ .../exception/InputFormatException.java | 13 ++ .../exception/InputRangeException.java | 14 ++ .../exception/InputTypeException.java | 14 ++ .../exception/NullArgumentException.java | 22 +++ me.smartstore/group/Group.java | 56 +++++++ me.smartstore/group/GroupType.java | 21 +++ me.smartstore/group/Groups.java | 53 ++++++ me.smartstore/group/Parameter.java | 59 +++++++ me.smartstore/menu/CustomerMenu.java | 117 +++++++++++++ me.smartstore/menu/GroupMenu.java | 158 ++++++++++++++++++ me.smartstore/menu/MainMenu.java | 76 +++++++++ me.smartstore/menu/Menu.java | 48 ++++++ me.smartstore/menu/SummaryMenu.java | 44 +++++ me.smartstore/util/Message.java | 13 ++ 29 files changed, 1352 insertions(+), 1 deletion(-) create mode 100644 .idea/uiDesigner.xml create mode 100644 me.smartstore/Main.java create mode 100644 me.smartstore/SmartStoreApp.java create mode 100644 me.smartstore/arrays/Collections.java create mode 100644 me.smartstore/arrays/DArray.java create mode 100644 me.smartstore/customer/Customer.java create mode 100644 me.smartstore/customer/Customers.java 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 create mode 100644 me.smartstore/group/Group.java create mode 100644 me.smartstore/group/GroupType.java create mode 100644 me.smartstore/group/Groups.java create mode 100644 me.smartstore/group/Parameter.java create mode 100644 me.smartstore/menu/CustomerMenu.java create mode 100644 me.smartstore/menu/GroupMenu.java create mode 100644 me.smartstore/menu/MainMenu.java create mode 100644 me.smartstore/menu/Menu.java create mode 100644 me.smartstore/menu/SummaryMenu.java create mode 100644 me.smartstore/util/Message.java diff --git a/.idea/.gitignore b/.idea/.gitignore index 26d33521..577b0f7e 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -1,3 +1,9 @@ # Default ignored files /shelf/ /workspace.xml +/vcs.xml +/uiDesigner.xml +/modules.xml +/modules.xml +/misc.xml +/KDTBE5_Java_ToyProject.iml \ No newline at end of file diff --git a/.idea/KDTBE5_Java_ToyProject.iml b/.idea/KDTBE5_Java_ToyProject.iml index 8545f145..5890ca80 100644 --- a/.idea/KDTBE5_Java_ToyProject.iml +++ b/.idea/KDTBE5_Java_ToyProject.iml @@ -4,8 +4,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 639900d1..4458232f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/me.smartstore/Main.java b/me.smartstore/Main.java new file mode 100644 index 00000000..1e809849 --- /dev/null +++ b/me.smartstore/Main.java @@ -0,0 +1,6 @@ + +public class Main { + public static void main(String[] args) { + SmartStoreApp.getInstance().test().run(); + } +} diff --git a/me.smartstore/SmartStoreApp.java b/me.smartstore/SmartStoreApp.java new file mode 100644 index 00000000..e1909877 --- /dev/null +++ b/me.smartstore/SmartStoreApp.java @@ -0,0 +1,63 @@ + +import customer.Customer; +import customer.Customers; +import group.Group; +import group.GroupType; +import group.Groups; +import group.Parameter; +import menu.*; + +public class SmartStoreApp { + private final Groups allGroups = Groups.getInstance(); + private final Customers allCustomers = Customers.getInstance(); + private final MainMenu mainMenu = MainMenu.getInstance(); + + // singleton + private static SmartStoreApp smartStoreApp; + + public static SmartStoreApp getInstance() { + if (smartStoreApp == null) { + smartStoreApp = new SmartStoreApp(); + } + return smartStoreApp; + } + + private SmartStoreApp() {} + + public void details() { + System.out.println("\n\n==========================================="); + System.out.println(" Title : SmartStore Customer Classification"); + System.out.println(" Release Date : 23.05.10"); + System.out.println(" Copyright 2023 Gyeongmin All rights reserved."); + System.out.println("===========================================\n"); + } + + public SmartStoreApp test() { + allGroups.add(new Group(new Parameter(10, 100000), GroupType.GENERAL)); + allGroups.add(new Group(new Parameter(20, 200000), GroupType.VIP)); + allGroups.add(new Group(new Parameter(30, 300000), GroupType.VVIP)); + + //고객 정보 + for (int i = 0; i < 26; i++) { + allCustomers.add(new Customer( + Character.toString( + (char) ('a' + i)), + (char) ('a' + i) + "123", + ((int) (Math.random() * 5) + 1) * 10, + ((int) (Math.random() * 5) + 1) * 100000)); + } + + System.out.println("allCustomers = " + allCustomers); + System.out.println("allGroups = " + allGroups); + + allCustomers.refresh(allGroups); + + return this; + } + + public void run() { + details(); + mainMenu.manage(); + + } +} \ No newline at end of file diff --git a/me.smartstore/arrays/Collections.java b/me.smartstore/arrays/Collections.java new file mode 100644 index 00000000..0b2c65bf --- /dev/null +++ b/me.smartstore/arrays/Collections.java @@ -0,0 +1,13 @@ +package arrays; + +public interface Collections { + int size(); + T get(int index); + void set(int index, T object); + int indexOf(T object); + void add(T object); + void add(int index, T object); + T pop(); + T pop(int index); + T pop(T object); +} \ No newline at end of file diff --git a/me.smartstore/arrays/DArray.java b/me.smartstore/arrays/DArray.java new file mode 100644 index 00000000..a768a9db --- /dev/null +++ b/me.smartstore/arrays/DArray.java @@ -0,0 +1,140 @@ +package arrays; + +import customer.Customer; +import exception.ElementNotFoundException; +import exception.EmptyArrayException; +import exception.NullArgumentException; + +public class DArray implements Collections { // Dynamic Array + + protected static final int DEFAULT = 10; + + protected T[] arrays; + protected int size; + protected int capacity; + + @SuppressWarnings("unchecked") + public DArray() { + arrays = (T[]) new Object[DEFAULT]; + capacity = DEFAULT; + } + + @SuppressWarnings("unchecked") + public DArray(int initial) { + arrays = (T[]) new Object[initial]; + capacity = initial; + } + + public DArray(T[] arrays) { + this.arrays = arrays; + capacity = arrays.length; + size = arrays.length; + } + + @Override + public int size() { + return size; + } + + protected int capacity() { + return capacity; + } + + @Override + public T get(int index) throws IndexOutOfBoundsException { + if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); + return arrays[index]; + } + + @Override + public void set(int index, T object) throws IndexOutOfBoundsException, NullArgumentException { + if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); + if (object == null) throw new NullArgumentException(); + + arrays[index] = object; + } + + @Override + public int indexOf(T object) throws NullArgumentException, ElementNotFoundException { + if (object == null) throw new NullArgumentException(); // not found (instead of throwing exception) + + for (int i = 0; i < size; i++) { + if (arrays[i] == null) continue; + if (arrays[i].equals(object)) return i; + } + throw new ElementNotFoundException(); // not found + } + + @Override + public void add(T object) throws NullArgumentException { + if (object == null) throw new NullArgumentException(); // if argument is null, do not add null value in array + + if (size < capacity) { + arrays[size] = object; + size++; + } else { + grow(); + add(object); + } + } + + @Override + public void add(int index, T object) throws IndexOutOfBoundsException, NullArgumentException { + if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); + if (object == null) throw new NullArgumentException(); + + if (size < capacity) { + for (int i = size-1; i >= index ; i--) { + arrays[i+1] = arrays[i]; + } + arrays[index] = object; + size++; + } else { + grow(); + add(index, object); + } + } + + @Override + public T pop() { + return pop(size-1); + } + + @Override + public T pop(int index) throws IndexOutOfBoundsException { + if (size == 0) throw new EmptyArrayException(); + if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); + + T popElement = arrays[index]; + arrays[index] = null; // 삭제됨을 명시적으로 표현 + + for (int i = index+1; i < size; i++) { + arrays[i-1] = arrays[i]; + } + arrays[size-1] = null; + size--; + return popElement; + } + + @Override + public T pop(T object) { + return pop(indexOf(object)); + } + + protected void grow() { + capacity *= 2; // doubling + arrays = java.util.Arrays.copyOf(arrays, capacity); + } + + @Override + public String toString() { + String toStr = ""; + for (int i = 0; i < size; i++) { + toStr += (arrays[i] + "\n"); + } + return toStr; + } + + public void remove(Customer customerToDelete) { + } +} \ No newline at end of file diff --git a/me.smartstore/customer/Customer.java b/me.smartstore/customer/Customer.java new file mode 100644 index 00000000..d8c17081 --- /dev/null +++ b/me.smartstore/customer/Customer.java @@ -0,0 +1,105 @@ +package customer; + +import group.Group; + +import java.util.Objects; + +public class Customer { + private String cusName; + private String cusId; + private Integer cusTotalTime; + private Integer cusTotalPay; + private Group group; + + public Customer() { + } + + public Customer(String cusId) { + this.cusId = cusId; + } + + public Customer(String cusName, String cusId) { + this.cusName = cusName; + this.cusId = cusId; + } + + public Customer(String cusName, String cusId, Integer cusTotalTime, Integer cusTotalPay) { + this.cusName = cusName; + this.cusId = cusId; + this.cusTotalTime = cusTotalTime; + this.cusTotalPay = cusTotalPay; + } + + public String getCusName() { + return cusName; + } + + public void setCusName(String cusName) { + this.cusName = cusName; + } + + public String getCusId() { + return cusId; + } + + public void setCusId(String cusId) { + this.cusId = cusId; + } + + public Integer getCusTotalTime() { + return cusTotalTime; + } + + public void setCusTotalTime(Integer cusTotalTime) { + this.cusTotalTime = cusTotalTime; + } + + public Integer getCusTotalPay() { + return cusTotalPay; + } + + public void setCusTotalPay(Integer cusTotalPay) { + this.cusTotalPay = cusTotalPay; + } + + public Group getGroup() { + return group; + } + + public void setGroup(Group group) { + this.group = group; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Customer customer = (Customer) o; + return Objects.equals(cusId, customer.cusId); + } + + @Override + public int hashCode() { + return Objects.hash(cusId); + } + + @Override + public String toString() { + return "Customer{" + + "cusName='" + cusName + '\'' + + ", cusId='" + cusId + '\'' + + ", cusTotalTime=" + cusTotalTime + + ", cusTotalPay=" + cusTotalPay + + ", group=" + group + + '}'; + } + 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; + } + + +} diff --git a/me.smartstore/customer/Customers.java b/me.smartstore/customer/Customers.java new file mode 100644 index 00000000..ab66ea75 --- /dev/null +++ b/me.smartstore/customer/Customers.java @@ -0,0 +1,72 @@ +package customer; + +import arrays.DArray; +import group.Groups; + +import java.util.Iterator; + +import static group.Groups.allGroups; + +public class Customers extends DArray implements Iterable { + + private static Customers allCustomers; + + public static Customers getInstance() { + if (allCustomers == null) { + allCustomers = new Customers(); + } + return allCustomers; + } + + private Customers() { + } + + // 분류 기준에 따라 모든 고객을 분류하고, 각 고객의 group 필드를 업데이트하는 함수 + public void refresh(Groups allGroups) { + Groups groups = new Groups(); + groups.grouping(this); + } + + // 새로운 고객을 추가하고, refresh() 함수를 호출하는 함수 + @Override + public void add(Customer customer) { + super.add(customer); + refresh(allGroups); + } + + public Customer find(Object o) { + return null; + } + + @Override + public Iterator iterator() { + return new CustomerIterator(); + } + + private class CustomerIterator implements Iterator { + private int index; + + public CustomerIterator() { + index = 0; + } + + @Override + public boolean hasNext() { + return index < size(); + } + + @Override + public Customer next() { + if (!hasNext()) { + throw new IllegalStateException("No more elements"); + } + return get(index++); + } + } + + public void printAll() { + for (Customer customer : this) { + System.out.println(customer); + } + } +} diff --git a/me.smartstore/exception/ArrayEmptyException.java b/me.smartstore/exception/ArrayEmptyException.java new file mode 100644 index 00000000..a649f689 --- /dev/null +++ b/me.smartstore/exception/ArrayEmptyException.java @@ -0,0 +1,14 @@ +package exception; + +import util.Message; + +public class ArrayEmptyException extends RuntimeException { + + public ArrayEmptyException() { + super(Message.ERR_MSG_INVALID_ARR_EMPTY); + } + + public ArrayEmptyException(String message) { + super(message); + } +} diff --git a/me.smartstore/exception/ElementNotFoundException.java b/me.smartstore/exception/ElementNotFoundException.java new file mode 100644 index 00000000..f163a3e8 --- /dev/null +++ b/me.smartstore/exception/ElementNotFoundException.java @@ -0,0 +1,22 @@ +package exception; + +public class ElementNotFoundException extends RuntimeException { + public ElementNotFoundException() { + } + + public ElementNotFoundException(String message) { + super(message); + } + + public ElementNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public ElementNotFoundException(Throwable cause) { + super(cause); + } + + public ElementNotFoundException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/me.smartstore/exception/EmptyArrayException.java b/me.smartstore/exception/EmptyArrayException.java new file mode 100644 index 00000000..4ece8b3b --- /dev/null +++ b/me.smartstore/exception/EmptyArrayException.java @@ -0,0 +1,22 @@ +package exception; + +public class EmptyArrayException extends RuntimeException { + public EmptyArrayException() { + } + + public EmptyArrayException(String message) { + super(message); + } + + public EmptyArrayException(String message, Throwable cause) { + super(message, cause); + } + + public EmptyArrayException(Throwable cause) { + super(cause); + } + + public EmptyArrayException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/me.smartstore/exception/InputEmptyException.java b/me.smartstore/exception/InputEmptyException.java new file mode 100644 index 00000000..2327adb2 --- /dev/null +++ b/me.smartstore/exception/InputEmptyException.java @@ -0,0 +1,15 @@ +package exception; + + +import util.Message; + +public class InputEmptyException extends RuntimeException { + + public InputEmptyException() { + super(Message.ERR_MSG_INVALID_INPUT_EMPTY); + } + + public InputEmptyException(String message) { + super(message); + } +} diff --git a/me.smartstore/exception/InputEndException.java b/me.smartstore/exception/InputEndException.java new file mode 100644 index 00000000..defe48fe --- /dev/null +++ b/me.smartstore/exception/InputEndException.java @@ -0,0 +1,13 @@ +package exception; + +import util.Message; + +public class InputEndException extends RuntimeException { + public InputEndException() { + super(Message.ERR_MSG_INPUT_END); + } + + public InputEndException(String message) { + super(message); + } +} diff --git a/me.smartstore/exception/InputFormatException.java b/me.smartstore/exception/InputFormatException.java new file mode 100644 index 00000000..c21e71f5 --- /dev/null +++ b/me.smartstore/exception/InputFormatException.java @@ -0,0 +1,13 @@ +package exception; + +import util.Message; + +public class InputFormatException extends RuntimeException { + public InputFormatException() { + super(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } + + public InputFormatException(String message) { + super(message); + } +} diff --git a/me.smartstore/exception/InputRangeException.java b/me.smartstore/exception/InputRangeException.java new file mode 100644 index 00000000..35b0f4ad --- /dev/null +++ b/me.smartstore/exception/InputRangeException.java @@ -0,0 +1,14 @@ +package exception; + + +import util.Message; + +public class InputRangeException extends RuntimeException { + public InputRangeException() { + super(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + + public InputRangeException(String message) { + super(message); + } +} diff --git a/me.smartstore/exception/InputTypeException.java b/me.smartstore/exception/InputTypeException.java new file mode 100644 index 00000000..58b6a149 --- /dev/null +++ b/me.smartstore/exception/InputTypeException.java @@ -0,0 +1,14 @@ +package exception; + + +import util.Message; + +public class InputTypeException extends RuntimeException { + public InputTypeException() { + super(Message.ERR_MSG_INVALID_INPUT_TYPE); + } + + public InputTypeException(String message) { + super(message); + } +} diff --git a/me.smartstore/exception/NullArgumentException.java b/me.smartstore/exception/NullArgumentException.java new file mode 100644 index 00000000..14349091 --- /dev/null +++ b/me.smartstore/exception/NullArgumentException.java @@ -0,0 +1,22 @@ +package exception; + +public class NullArgumentException extends RuntimeException { + public NullArgumentException() { + } + + public NullArgumentException(String message) { + super(message); + } + + public NullArgumentException(String message, Throwable cause) { + super(message, cause); + } + + public NullArgumentException(Throwable cause) { + super(cause); + } + + public NullArgumentException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/me.smartstore/group/Group.java b/me.smartstore/group/Group.java new file mode 100644 index 00000000..c9b4b380 --- /dev/null +++ b/me.smartstore/group/Group.java @@ -0,0 +1,56 @@ +package group; + +import group.GroupType; +import group.Parameter; + +import java.util.Objects; + +public class Group { + private Parameter parameter; // 분류기준 + private GroupType groupType; // 그룹 타입 + + public Group() { + } + + public Group(Parameter parameter, GroupType groupType) { + this.parameter = parameter; + this.groupType = groupType; + } + + public Parameter getParameter() { + return parameter; + } + + public void setParameter(Parameter parameter) { + this.parameter = parameter; + } + + public GroupType getGroupType() { + return groupType; + } + + public void setGroupType(GroupType groupType) { + this.groupType = groupType; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Group group = (Group) o; + return Objects.equals(parameter, group.parameter) && groupType == group.groupType; + } + + @Override + public int hashCode() { + return Objects.hash(parameter, groupType); + } + + @Override + public String toString() { + return "Group{" + + "parameter=" + parameter + + ", groupType=" + groupType + + '}'; + } +} diff --git a/me.smartstore/group/GroupType.java b/me.smartstore/group/GroupType.java new file mode 100644 index 00000000..1637f363 --- /dev/null +++ b/me.smartstore/group/GroupType.java @@ -0,0 +1,21 @@ +package group; + +public enum GroupType { + N("해당없음"), G("일반고객"), V("우수고객"), VV("최우수고객"), + NONE("해당없음"), GENERAL("일반고객"), VIP("우수고객"), VVIP("최우수고객"); + + String groupType = ""; + + GroupType(String groupType) { + this.groupType = groupType; + } + + public GroupType replaceFullName() { + if (this == N) return NONE; + else if (this == G) return GENERAL; + else if (this == V) return VIP; + else if (this == VV) return VVIP; + return this; + } + +} diff --git a/me.smartstore/group/Groups.java b/me.smartstore/group/Groups.java new file mode 100644 index 00000000..436219ac --- /dev/null +++ b/me.smartstore/group/Groups.java @@ -0,0 +1,53 @@ +package group; + +import arrays.DArray; +import customer.Customers; + +public class Groups extends DArray { + // singleton + public static Groups allGroups; + + public static Groups getInstance() { + if (allGroups == null) { + allGroups = new Groups(); + } + return allGroups; + } + + public Groups() {} + + public Group find(GroupType groupType) { + for (int i = 0; i < allGroups.size; i++) { + if (allGroups.get(i).getGroupType() == groupType) { + return allGroups.get(i); + } + } + return null; + } + + public void grouping(Customers customers) { + } + + public void setParameter(GroupType groupType, Parameter parameter) { + Group group = find(groupType); + if (group != null) { + group.setParameter(parameter); + } + } + + public Parameter viewParameter(GroupType groupType) { + Group group = find(groupType); + if (group != null) { + return group.getParameter(); + } + return null; + } + + public void updateParameter(GroupType groupType, Integer minTime, Integer minPay) { + Group group = find(groupType); + if (group != null) { + Parameter parameter = new Parameter(minTime, minPay); + group.setParameter(parameter); + } + } +} diff --git a/me.smartstore/group/Parameter.java b/me.smartstore/group/Parameter.java new file mode 100644 index 00000000..9cec4994 --- /dev/null +++ b/me.smartstore/group/Parameter.java @@ -0,0 +1,59 @@ +package group; + +import java.util.Objects; + +public class Parameter { + private Integer minTime; + private Integer minPay; + + + public Parameter() { + } + + public Parameter(Integer minTime, Integer minPay) { + this.minTime = minTime; + this.minPay = minPay; + } + + public Integer getMinTime() { + return minTime; + } + + public void setMinTime(Integer minTime) { + this.minTime = minTime; + } + + public Integer getMinPay() { + return minPay; + } + + public void setMinPay(Integer minPay) { + this.minPay = minPay; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Parameter parameter = (Parameter) o; + return Objects.equals(minTime, parameter.minTime) && Objects.equals(minPay, parameter.minPay); + } + + @Override + public int hashCode() { + return Objects.hash(minTime, minPay); + } + + @Override + public String toString() { + return "Parameter{" + + "minTime=" + minTime + + ", minPay=" + minPay + + '}'; + } + public void viewParameter() { + System.out.println("Minimum Time: " + minTime); + System.out.println("Minimum Pay: " + minPay); + } + +} diff --git a/me.smartstore/menu/CustomerMenu.java b/me.smartstore/menu/CustomerMenu.java new file mode 100644 index 00000000..1c9641ed --- /dev/null +++ b/me.smartstore/menu/CustomerMenu.java @@ -0,0 +1,117 @@ +package menu; + +import customer.Customer; +import customer.Customers; +import exception.InputEndException; +import menu.Menu; +import util.Message; + +public class CustomerMenu implements Menu { + // singleton + private static CustomerMenu customerMenu; + private final Customers allCustomers = Customers.getInstance(); + + public static CustomerMenu getInstance() { + if (customerMenu == null) { + customerMenu = new CustomerMenu(); + } + return customerMenu; + } + + private CustomerMenu() {} + + @Override + public void manage() { + while (true) { // 서브 메뉴 페이지를 유지하기 위한 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; // choice == 5 + } + } + } + + private void addCustomer() { + System.out.print("Enter customer name: "); + String name; + try { + name = nextLine(); + } catch (InputEndException e) { + return; + } + System.out.print("Enter customer Id: "); + String Id; + try { + Id = nextLine(); + } catch (InputEndException e) { + return; + } + System.out.print("Enter cusTotalTime: "); + int cusTotalTime; + try { + cusTotalTime = Integer.parseInt(nextLine()); + } catch (InputEndException e) { + return; + } + + System.out.print("Enter cusTotalPay: "); + int cusTotalPay; + try { + cusTotalPay = Integer.parseInt(nextLine()); + } catch (InputEndException e) { + return; + } + + // add logic + + System.out.println(name + " has been added."); + } + + private void viewCustomer() { + allCustomers.printAll(); + } + + private void updateCustomer() { + System.out.print("Enter customer name to update: "); + String name = nextLine(Message.END_MSG); + if (name == null) return; // input end + + Customer customer = allCustomers.find(name); + if (customer == null) { + System.out.println("There is no customer named '" + name + "'"); + return; + } + + // update logic + + System.out.println(customer.getCusName() + " has been updated."); + } + + private void deleteCustomer() { + System.out.print("Enter customer name to delete: "); + String name = nextLine(Message.END_MSG); + if (name == null) return; // input end + + Customer customer = allCustomers.find(name); + if (customer == null) { + System.out.println("There is no customer named '" + name + "'"); + return; + } + + allCustomers.remove(customer); + System.out.println(customer.getCusName() + " has been deleted."); + } +} diff --git a/me.smartstore/menu/GroupMenu.java b/me.smartstore/menu/GroupMenu.java new file mode 100644 index 00000000..8f1a2b32 --- /dev/null +++ b/me.smartstore/menu/GroupMenu.java @@ -0,0 +1,158 @@ +package menu; + +import customer.Customers; +import exception.InputEndException; +import group.Group; +import group.GroupType; +import group.Groups; +import group.Parameter; +import util.Message; + +public class GroupMenu implements Menu { + private final group.Groups allGroups = Groups.getInstance(); + private final customer.Customers allCustomers = Customers.getInstance(); + // singleton + private static menu.GroupMenu groupMenu; + + public static GroupMenu getInstance() { + if (groupMenu == null) { + groupMenu = new menu.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; + + } + + } + + public group.GroupType chooseGroup() { + while ( true ) { + try { + System.out.print("Which group (GENERAL (G), VIP (V), VVIP (VV))? "); + String choice = nextLine(util.Message.END_MSG); + // group (str) -> GroupType (enum) + // "VIP" -> GroupType.VIP + + group.GroupType groupType = group.GroupType.valueOf(choice).replaceFullName(); + return groupType; + } catch (InputEndException e) { + System.out.println(util.Message.ERR_MSG_INPUT_END); + return null; + } catch (IllegalArgumentException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } + } + + public void setParameter() { // 초기화할 때만 호출 가능 + while ( true ) { + GroupType groupType = chooseGroup(); + if (groupType == null) { + break; // chooseGroup()에서 InputEndException 발생시 루프를 빠져나감 + } + + // 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 { + group.Parameter parameter = new Parameter(); + + // time, pay 사용자 입력받은 후, 설정 필요 + System.out.print("Enter minimum payment: "); + int minPayment = nextInt(Message.END_MSG); + parameter.setMinPay(minPayment); + + System.out.print("Enter minimum time: "); + int minTime = nextInt(Message.END_MSG); + parameter.setMinTime(minTime); + + group.setParameter(parameter); + allCustomers.refresh(allGroups); // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 + break; // 루프를 빠져나감 + } + } + } + public void viewParameter() { + GroupType groupType = chooseGroup(); + Group group = allGroups.find(groupType); + + if (group != null && group.getParameter() != null) { + System.out.println("\n" + group); + } else { + System.out.println("\n" + groupType + " group is not initialized yet."); + } + } + public void updateParameter() { + GroupType groupType = chooseGroup(); + Group group = allGroups.find(groupType); + + if (group != null && group.getParameter() != null) { + group.Parameter parameter = group.getParameter(); + + System.out.println("\nCurrent Parameter:"); + System.out.println(parameter); + + System.out.print("\nEnter the new values:\n- Minimum Payment: "); + int minPayment = nextInt(util.Message.END_MSG); + System.out.print("- Minimum Time: "); + int minTime = nextInt(util.Message.END_MSG); + + parameter.setMinPay(minPayment); + parameter.setMinTime(minTime); + + group.setParameter(parameter); + allCustomers.refresh(allGroups); + } else { + System.out.println("\n" + groupType + " group is not initialized yet."); + } + } + + private int nextInt(String endMsg) { + while (true) { + try { + System.out.print("\nEnter an integer value: "); + String input = nextLine(endMsg); + return Integer.parseInt(input); + } catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_TYPE); + } catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + return 0; + } + } + } + public static GroupType replaceFullName(String name) { + switch (name.toUpperCase()) { + case "G": + return GroupType.GENERAL; + case "V": + return GroupType.VIP; + case "VV": + return GroupType.VVIP; + default: + return null; + } + } + + + +} + diff --git a/me.smartstore/menu/MainMenu.java b/me.smartstore/menu/MainMenu.java new file mode 100644 index 00000000..3b57875c --- /dev/null +++ b/me.smartstore/menu/MainMenu.java @@ -0,0 +1,76 @@ +package menu; + +public class MainMenu implements Menu { + + private final CustomerMenu customerMenu = CustomerMenu.getInstance(); + private final GroupMenu groupMenu = GroupMenu.getInstance(); + private final SummaryMenu summaryMenu = SummaryMenu.getInstance(); + + // 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) { + editParameter(); + } + else if (choice == 2) { + customerMenu.manage(); + } + else if (choice == 3) { + summaryMenu.manage(); + } + else { // choice == 4 + System.out.println("Program Finished"); + // 데이터 저장 코드 추가 + // saveData()는 데이터를 파일에 저장하는 메서드로 가정 + saveData(); + break; + } + } + } + + public void editParameter() { + while ( true ) { + int choice = mainMenu.chooseMenu(new String[]{ + "Set Parameter", + "View Parameter", + "Update Parameter", + "Back"}); + + if (choice == 1) { + groupMenu.setParameter(); + } + else if (choice == 2) { + // 파라미터를 보여주는 메서드 호출 + } + else if (choice == 3) { + // 파라미터를 수정하는 메서드 호출 + } + else { // choice == 4 + break; + } + } + } + + public void saveData() { + // 데이터를 파일에 저장하는 코드 + System.out.println("Data Saved"); + } +} diff --git a/me.smartstore/menu/Menu.java b/me.smartstore/menu/Menu.java new file mode 100644 index 00000000..f9bc2603 --- /dev/null +++ b/me.smartstore/menu/Menu.java @@ -0,0 +1,48 @@ +package menu; + +import exception.InputRangeException; +import exception.InputEndException; +import util.Message; + +import java.util.InputMismatchException; +import java.util.Scanner; + +public interface Menu { + Scanner scanner = new Scanner(System.in); + + default String nextLine() { // 하나의 프로그램 상에서 nextLine() 함수를 통해서 사용자 입력을 받음 + return scanner.nextLine().toUpperCase(); + } + + default String nextLine(String end) { + System.out.println("** Press 'end', if you want to exit! **"); + String str = scanner.nextLine().toUpperCase(); + if (str.equals(end)) throw new InputEndException(); + return str; + } + + default int chooseMenu(String[] menus) { + while ( true ) { // 예외 복구 while + try { + System.out.println("==============================="); + for (int i = 0; i < menus.length; i++) { + System.out.printf(" %d. %s\n", i + 1, menus[i]); + } + System.out.println("==============================="); + System.out.print("Choose One: "); + int choice = Integer.parseInt(nextLine()); + if (choice >= 1 && choice <= menus.length) return choice; + throw new InputRangeException(); // choice 가 범위에 벗어남 + + } catch (InputMismatchException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + + } catch (InputRangeException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + + } + } + } + + void manage(); // 각 서브메뉴들을 관리하는 함수 (각 서브메뉴의 최상위 메뉴) +} diff --git a/me.smartstore/menu/SummaryMenu.java b/me.smartstore/menu/SummaryMenu.java new file mode 100644 index 00000000..3bd16276 --- /dev/null +++ b/me.smartstore/menu/SummaryMenu.java @@ -0,0 +1,44 @@ +package menu; + +public class SummaryMenu implements Menu { + // singleton + private static SummaryMenu summaryMenu; + + public static SummaryMenu getInstance() { + if (summaryMenu == null) { + summaryMenu = new SummaryMenu(); + } + return summaryMenu; + } + + private SummaryMenu() {} + + @Override + public void manage() { + while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while + int choice = chooseMenu(new String[]{ + "Summary", + "Summary (Sorted By Name)", + "Summary (Sorted By Time)", + "Summary (Sorted By Pay)", + "Back"}); + switch (choice) { + case 1: + // SummaryMenu에서 제공하는 "Summary" 기능 실행 + break; + case 2: + // SummaryMenu에서 제공하는 "Summary (Sorted By Name)" 기능 실행 + break; + case 3: + // SummaryMenu에서 제공하는 "Summary (Sorted By Time)" 기능 실행 + break; + case 4: + // SummaryMenu에서 제공하는 "Summary (Sorted By Pay)" 기능 실행 + break; + case 5: + // 이전 메뉴로 돌아가기 + return; + } + } + } +} \ No newline at end of file diff --git a/me.smartstore/util/Message.java b/me.smartstore/util/Message.java new file mode 100644 index 00000000..7d33cb17 --- /dev/null +++ b/me.smartstore/util/Message.java @@ -0,0 +1,13 @@ +package util; + +public interface Message { + String ERR_MSG_INVALID_ARR_EMPTY = "No Customers. Please input one first."; + String ERR_MSG_NULL_ARR_ELEMENT = "Elements in Array has null. Array can't be sorted."; + String ERR_MSG_INVALID_INPUT_NULL = "Null Input. Please input something."; + String ERR_MSG_INVALID_INPUT_EMPTY = "Empty Input. Please input something."; + String ERR_MSG_INVALID_INPUT_RANGE = "Invalid Input. Please try again."; + String ERR_MSG_INVALID_INPUT_TYPE = "Invalid Type for Input. Please try again."; + String ERR_MSG_INVALID_INPUT_FORMAT = "Invalid Format for Input. Please try again."; + String ERR_MSG_INPUT_END = "END is pressed. Exit this menu."; + String END_MSG = "END"; +} From e2269a05aec66a53ba84b74b7756c8f8ad623267 Mon Sep 17 00:00:00 2001 From: ParkSeongUk Date: Thu, 11 May 2023 15:45:43 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[1=EC=B0=A8=20VER1.2...]=20Java=20ToyProjec?= =?UTF-8?q?t=20upload=20by=20ParkSeongWook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- me.smartstore/customer/Customer.java | 2 -- me.smartstore/customer/Customers.java | 16 +++++++-- me.smartstore/group/Groups.java | 8 ++++- me.smartstore/menu/SummaryMenu.java | 49 +++++++++++++++++++++++++-- 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/me.smartstore/customer/Customer.java b/me.smartstore/customer/Customer.java index d8c17081..c8d512bd 100644 --- a/me.smartstore/customer/Customer.java +++ b/me.smartstore/customer/Customer.java @@ -100,6 +100,4 @@ public Customer(String cusName, String cusId, Integer cusTotalTime, Integer cusT this.cusTotalPay = cusTotalPay; this.group = group; } - - } diff --git a/me.smartstore/customer/Customers.java b/me.smartstore/customer/Customers.java index ab66ea75..10dfdf3f 100644 --- a/me.smartstore/customer/Customers.java +++ b/me.smartstore/customer/Customers.java @@ -3,13 +3,14 @@ import arrays.DArray; import group.Groups; +import java.util.ArrayList; import java.util.Iterator; - -import static group.Groups.allGroups; +import java.util.List; public class Customers extends DArray implements Iterable { private static Customers allCustomers; + private Groups allGroups; public static Customers getInstance() { if (allCustomers == null) { @@ -19,6 +20,7 @@ public static Customers getInstance() { } private Customers() { + allGroups = Groups.getInstance(); } // 분류 기준에 따라 모든 고객을 분류하고, 각 고객의 group 필드를 업데이트하는 함수 @@ -34,6 +36,15 @@ public void add(Customer customer) { refresh(allGroups); } + // 고객 목록을 반환하는 메서드 + public List getList() { + List customerList = new ArrayList<>(); + for (Customer customer : this) { + customerList.add(customer); + } + return customerList; + } + public Customer find(Object o) { return null; } @@ -69,4 +80,5 @@ public void printAll() { System.out.println(customer); } } + } diff --git a/me.smartstore/group/Groups.java b/me.smartstore/group/Groups.java index 436219ac..a38a8d6e 100644 --- a/me.smartstore/group/Groups.java +++ b/me.smartstore/group/Groups.java @@ -1,6 +1,7 @@ package group; import arrays.DArray; +import customer.Customer; import customer.Customers; public class Groups extends DArray { @@ -14,7 +15,8 @@ public static Groups getInstance() { return allGroups; } - public Groups() {} + public Groups() { + } public Group find(GroupType groupType) { for (int i = 0; i < allGroups.size; i++) { @@ -50,4 +52,8 @@ public void updateParameter(GroupType groupType, Integer minTime, Integer minPay group.setParameter(parameter); } } + + public Group getGroup(Customer customer) { + return null; + } } diff --git a/me.smartstore/menu/SummaryMenu.java b/me.smartstore/menu/SummaryMenu.java index 3bd16276..e3ae86ee 100644 --- a/me.smartstore/menu/SummaryMenu.java +++ b/me.smartstore/menu/SummaryMenu.java @@ -1,6 +1,14 @@ package menu; +import customer.Customer; +import customer.Customers; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + public class SummaryMenu implements Menu { + // singleton private static SummaryMenu summaryMenu; @@ -15,7 +23,9 @@ private SummaryMenu() {} @Override public void manage() { - while ( true ) { // 서브 메뉴 페이지를 유지하기 위한 while + Customers allCustomers = Customers.getInstance(); + + while (true) { // 서브 메뉴 페이지를 유지하기 위한 while int choice = chooseMenu(new String[]{ "Summary", "Summary (Sorted By Name)", @@ -25,15 +35,44 @@ public void manage() { switch (choice) { case 1: // SummaryMenu에서 제공하는 "Summary" 기능 실행 + System.out.println("========== Summary =========="); + printCustomers(allCustomers.getList()); break; case 2: // SummaryMenu에서 제공하는 "Summary (Sorted By Name)" 기능 실행 + System.out.println("========== Summary (Sorted By Name) =========="); + List customersSortedByName = allCustomers.getList(); + Collections.sort(customersSortedByName, new Comparator() { + @Override + public int compare(Customer o1, Customer o2) { + return o1.getCusName().compareTo(o2.getCusName()); + } + }); + printCustomers(customersSortedByName); break; case 3: // SummaryMenu에서 제공하는 "Summary (Sorted By Time)" 기능 실행 + System.out.println("========== Summary (Sorted By Time) =========="); + List customersSortedByTime = allCustomers.getList(); + Collections.sort(customersSortedByTime, new Comparator() { + @Override + public int compare(Customer o1, Customer o2) { + return Integer.compare(o2.getCusTotalTime(), o1.getCusTotalTime()); + } + }); + printCustomers(customersSortedByTime); break; case 4: // SummaryMenu에서 제공하는 "Summary (Sorted By Pay)" 기능 실행 + System.out.println("========== Summary (Sorted By Pay) =========="); + List customersSortedByPay = allCustomers.getList(); + Collections.sort(customersSortedByPay, new Comparator() { + @Override + public int compare(Customer o1, Customer o2) { + return Double.compare(o2.getCusTotalPay(), o1.getCusTotalPay()); + } + }); + printCustomers(customersSortedByPay); break; case 5: // 이전 메뉴로 돌아가기 @@ -41,4 +80,10 @@ public void manage() { } } } -} \ No newline at end of file + + private void printCustomers(List customers) { + for (Customer customer : customers) { + System.out.println(customer); + } + } +} From d21302c6e96170632f50147e03c414268b06cb8c Mon Sep 17 00:00:00 2001 From: ParkSeongUk Date: Fri, 12 May 2023 20:53:12 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[1=EC=B0=A8=20VER1.3...]=20Java=20ToyProjec?= =?UTF-8?q?t=20upload=20by=20ParkSeongWook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- me.smartstore/arrays/DArray.java | 4 +- me.smartstore/customer/Customer.java | 37 ++-- me.smartstore/customer/Customers.java | 118 +++++++------ me.smartstore/group/Group.java | 8 +- me.smartstore/group/Groups.java | 4 + me.smartstore/menu/CustomerMenu.java | 34 ++-- me.smartstore/menu/GroupMenu.java | 233 ++++++++++++++------------ me.smartstore/menu/MainMenu.java | 13 +- me.smartstore/menu/Menu.java | 8 +- me.smartstore/menu/SummaryMenu.java | 9 +- 10 files changed, 263 insertions(+), 205 deletions(-) diff --git a/me.smartstore/arrays/DArray.java b/me.smartstore/arrays/DArray.java index a768a9db..392fa8c0 100644 --- a/me.smartstore/arrays/DArray.java +++ b/me.smartstore/arrays/DArray.java @@ -106,7 +106,7 @@ public T pop(int index) throws IndexOutOfBoundsException { if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); T popElement = arrays[index]; - arrays[index] = null; // 삭제됨을 명시적으로 표현 + arrays[index] = null; for (int i = index+1; i < size; i++) { arrays[i-1] = arrays[i]; @@ -122,7 +122,7 @@ public T pop(T object) { } protected void grow() { - capacity *= 2; // doubling + capacity *= 2; arrays = java.util.Arrays.copyOf(arrays, capacity); } diff --git a/me.smartstore/customer/Customer.java b/me.smartstore/customer/Customer.java index c8d512bd..506da180 100644 --- a/me.smartstore/customer/Customer.java +++ b/me.smartstore/customer/Customer.java @@ -7,8 +7,8 @@ public class Customer { private String cusName; private String cusId; - private Integer cusTotalTime; - private Integer cusTotalPay; + private int cusTotalTime; + private int cusTotalPay; private Group group; public Customer() { @@ -23,13 +23,21 @@ public Customer(String cusName, String cusId) { this.cusId = cusId; } - public Customer(String cusName, String cusId, Integer cusTotalTime, Integer cusTotalPay) { + public Customer(String cusName, String cusId, int cusTotalTime, int cusTotalPay) { this.cusName = cusName; this.cusId = cusId; this.cusTotalTime = cusTotalTime; this.cusTotalPay = cusTotalPay; } + public Customer(String cusName, String cusId, int cusTotalTime, int cusTotalPay, Group group) { + this.cusName = cusName; + this.cusId = cusId; + this.cusTotalTime = cusTotalTime; + this.cusTotalPay = cusTotalPay; + this.group = group; + } + public String getCusName() { return cusName; } @@ -46,19 +54,19 @@ public void setCusId(String cusId) { this.cusId = cusId; } - public Integer getCusTotalTime() { + public int getCusTotalTime() { return cusTotalTime; } - public void setCusTotalTime(Integer cusTotalTime) { + public void setCusTotalTime(int cusTotalTime) { this.cusTotalTime = cusTotalTime; } - public Integer getCusTotalPay() { + public int getCusTotalPay() { return cusTotalPay; } - public void setCusTotalPay(Integer cusTotalPay) { + public void setCusTotalPay(int cusTotalPay) { this.cusTotalPay = cusTotalPay; } @@ -70,6 +78,14 @@ public void setGroup(Group group) { this.group = group; } + public void addPurchase(int pay) { + cusTotalPay += pay; + } + + public void addTime(int time) { + cusTotalTime += time; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -93,11 +109,4 @@ public String toString() { ", group=" + group + '}'; } - 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; - } } diff --git a/me.smartstore/customer/Customers.java b/me.smartstore/customer/Customers.java index 10dfdf3f..0d8cb5c9 100644 --- a/me.smartstore/customer/Customers.java +++ b/me.smartstore/customer/Customers.java @@ -1,84 +1,108 @@ package customer; -import arrays.DArray; import group.Groups; import java.util.ArrayList; -import java.util.Iterator; +import java.util.HashMap; import java.util.List; +import java.util.Map; -public class Customers extends DArray implements Iterable { +public class Customers { + private static Customers instance; + private final List customers; + private int minTotalTime; + private int minTotalPay; + private final Map customerGroup; // 추가된 필드 - private static Customers allCustomers; - private Groups allGroups; + private Customers() { + customers = new ArrayList<>(); + customerGroup = new HashMap<>(); // 초기화 + } public static Customers getInstance() { - if (allCustomers == null) { - allCustomers = new Customers(); + if (instance == null) { + instance = new Customers(); } - return allCustomers; + return instance; } - private Customers() { - allGroups = Groups.getInstance(); + public void add(Customer customer) { + customers.add(customer); } - // 분류 기준에 따라 모든 고객을 분류하고, 각 고객의 group 필드를 업데이트하는 함수 - public void refresh(Groups allGroups) { - Groups groups = new Groups(); - groups.grouping(this); + public boolean remove(Customer customer) { + return customers.remove(customer); } - // 새로운 고객을 추가하고, refresh() 함수를 호출하는 함수 - @Override - public void add(Customer customer) { - super.add(customer); - refresh(allGroups); - } - - // 고객 목록을 반환하는 메서드 public List getList() { - List customerList = new ArrayList<>(); - for (Customer customer : this) { - customerList.add(customer); - } - return customerList; + return customers; } - public Customer find(Object o) { - return null; + public void setMinTotalTime(int minTotalTime) { + this.minTotalTime = minTotalTime; } - @Override - public Iterator iterator() { - return new CustomerIterator(); + public void setMinTotalPay(int minTotalPay) { + this.minTotalPay = minTotalPay; } - private class CustomerIterator implements Iterator { - private int index; + public void groupCustomers() { + customerGroup.clear(); // 기존 분류 정보 초기화 + for (Customer customer : customers) { + if (customer.getCusTotalTime() >= minTotalTime && customer.getCusTotalPay() >= minTotalPay) { + customerGroup.put(customer, "VVIP"); + } else if (customer.getCusTotalTime() >= minTotalTime) { + customerGroup.put(customer, "VIP"); + } else { + customerGroup.put(customer, "General"); + } + } + } - public CustomerIterator() { - index = 0; + public void printGroupedCustomers() { + groupCustomers(); + for (String group : new String[]{"General", "VIP", "VVIP"}) { + System.out.println(group + " Customers:"); + for (Customer customer : customerGroup.keySet()) { + if (customerGroup.get(customer).equals(group)) { + System.out.println(customer); + } + } + System.out.println(); } + } - @Override - public boolean hasNext() { - return index < size(); + public void addPurchase(String name, int pay) { + for (Customer customer : customers) { + if (customer.getCusName().equals(name)) { + customer.addPurchase(pay); + return; + } } + System.out.println("No such customer exists."); + } - @Override - public Customer next() { - if (!hasNext()) { - throw new IllegalStateException("No more elements"); + public void addTime(String name, int time) { + for (Customer customer : customers) { + if (customer.getCusName().equals(name)) { + customer.addTime(time); + return; } - return get(index++); } + System.out.println("No such customer exists."); } public void printAll() { - for (Customer customer : this) { - System.out.println(customer); - } } + public Customer find(String toLowerCase) { + return null; + } + + public void refresh(Groups allGroups) { + } + + public boolean isEmpty() { + return false; + } } diff --git a/me.smartstore/group/Group.java b/me.smartstore/group/Group.java index c9b4b380..35881bb9 100644 --- a/me.smartstore/group/Group.java +++ b/me.smartstore/group/Group.java @@ -1,13 +1,9 @@ package group; - -import group.GroupType; -import group.Parameter; - import java.util.Objects; public class Group { - private Parameter parameter; // 분류기준 - private GroupType groupType; // 그룹 타입 + private Parameter parameter; + private GroupType groupType; public Group() { } diff --git a/me.smartstore/group/Groups.java b/me.smartstore/group/Groups.java index a38a8d6e..84d4606c 100644 --- a/me.smartstore/group/Groups.java +++ b/me.smartstore/group/Groups.java @@ -56,4 +56,8 @@ public void updateParameter(GroupType groupType, Integer minTime, Integer minPay public Group getGroup(Customer customer) { return null; } + + public Group assign(Customer customer) { + return null; + } } diff --git a/me.smartstore/menu/CustomerMenu.java b/me.smartstore/menu/CustomerMenu.java index 1c9641ed..2893db76 100644 --- a/me.smartstore/menu/CustomerMenu.java +++ b/me.smartstore/menu/CustomerMenu.java @@ -3,11 +3,9 @@ import customer.Customer; import customer.Customers; import exception.InputEndException; -import menu.Menu; import util.Message; public class CustomerMenu implements Menu { - // singleton private static CustomerMenu customerMenu; private final Customers allCustomers = Customers.getInstance(); @@ -22,7 +20,7 @@ private CustomerMenu() {} @Override public void manage() { - while (true) { // 서브 메뉴 페이지를 유지하기 위한 while + while (true) { int choice = chooseMenu(new String[]{ "Add Customer", "View Customer", @@ -39,7 +37,7 @@ public void manage() { } else if (choice == 4) { deleteCustomer(); } else { - break; // choice == 5 + break; } } } @@ -75,28 +73,40 @@ private void addCustomer() { return; } - // add logic System.out.println(name + " has been added."); } private void viewCustomer() { - allCustomers.printAll(); + if (allCustomers.isEmpty()) { + System.out.println("There are no customers."); + } else { + System.out.println("Customers:"); + for (Customer c : allCustomers.getList()) { + System.out.println("- " + c.getCusName() + " (ID: " + c.getCusId() + ")"+ " (TotalPay: " + c.getCusTotalPay() + ")"+ " (TotalTime: " + c.getCusTotalTime() + ")"); + } + } } + private void updateCustomer() { System.out.print("Enter customer name to update: "); String name = nextLine(Message.END_MSG); if (name == null) return; // input end - Customer customer = allCustomers.find(name); + Customer customer = null; + for (Customer c : allCustomers.getList()) { + if (c.getCusName().equalsIgnoreCase(name)) { + customer = c; + break; + } + } if (customer == null) { System.out.println("There is no customer named '" + name + "'"); return; } // update logic - System.out.println(customer.getCusName() + " has been updated."); } @@ -105,13 +115,15 @@ private void deleteCustomer() { String name = nextLine(Message.END_MSG); if (name == null) return; // input end - Customer customer = allCustomers.find(name); + Customer customer = allCustomers.find(name.toLowerCase()); // 소문자로 변환하여 검색 if (customer == null) { System.out.println("There is no customer named '" + name + "'"); return; } - allCustomers.remove(customer); - System.out.println(customer.getCusName() + " has been deleted."); + if (customer != null) { + allCustomers.remove(customer); + System.out.println(customer.getCusName() + " has been deleted."); + } } } diff --git a/me.smartstore/menu/GroupMenu.java b/me.smartstore/menu/GroupMenu.java index 8f1a2b32..3d877aab 100644 --- a/me.smartstore/menu/GroupMenu.java +++ b/me.smartstore/menu/GroupMenu.java @@ -1,58 +1,55 @@ package menu; +import group.Groups; import customer.Customers; import exception.InputEndException; +import exception.InputRangeException; import group.Group; import group.GroupType; -import group.Groups; import group.Parameter; import util.Message; - public class GroupMenu implements Menu { - private final group.Groups allGroups = Groups.getInstance(); - private final customer.Customers allCustomers = Customers.getInstance(); - // singleton - private static menu.GroupMenu groupMenu; + private final Groups allGroups = Groups.getInstance(); + private final Customers allCustomers = Customers.getInstance(); + private static GroupMenu groupMenu; public static GroupMenu getInstance() { if (groupMenu == null) { - groupMenu = new menu.GroupMenu(); + groupMenu = new GroupMenu(); } return groupMenu; } - private 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; - + while (true) { + int choice = chooseMenu(new String[]{"Set Parameter", "View Parameter", "Update Parameter", "Back"}); + + if (choice == 1) { + setParameter(); + } else if (choice == 2) { + viewParameter(); + } else if (choice == 3) { + updateParameter(); + } else { + break; + } } - } - public group.GroupType chooseGroup() { - while ( true ) { + public GroupType chooseGroup() { + while (true) { try { System.out.print("Which group (GENERAL (G), VIP (V), VVIP (VV))? "); - String choice = nextLine(util.Message.END_MSG); - // group (str) -> GroupType (enum) - // "VIP" -> GroupType.VIP + String choice = nextLine(Message.END_MSG); - group.GroupType groupType = group.GroupType.valueOf(choice).replaceFullName(); + GroupType groupType = GroupType.valueOf(choice).replaceFullName(); return groupType; } catch (InputEndException e) { - System.out.println(util.Message.ERR_MSG_INPUT_END); + System.out.println(Message.ERR_MSG_INPUT_END); return null; } catch (IllegalArgumentException e) { System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); @@ -60,99 +57,129 @@ public group.GroupType chooseGroup() { } } - public void setParameter() { // 초기화할 때만 호출 가능 - while ( true ) { + public void setParameter() { + while (true) { GroupType groupType = chooseGroup(); if (groupType == null) { - break; // chooseGroup()에서 InputEndException 발생시 루프를 빠져나감 + break; } - - // GroupType에 해당하는 group 객체를 찾아야 함 Group group = allGroups.find(groupType); - if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 + if (group != null && group.getParameter() != null) { System.out.println("\n" + group.getGroupType() + " group already exists."); System.out.println("\n" + group); } else { - group.Parameter parameter = new Parameter(); - - // time, pay 사용자 입력받은 후, 설정 필요 - System.out.print("Enter minimum payment: "); - int minPayment = nextInt(Message.END_MSG); - parameter.setMinPay(minPayment); - - System.out.print("Enter minimum time: "); - int minTime = nextInt(Message.END_MSG); - parameter.setMinTime(minTime); + Parameter parameter = new Parameter(); + System.out.println("Enter minimum usage time"); + int minUsageTime; + while (true) { + try { + minUsageTime = Integer.parseInt(nextLine()); + if (minUsageTime < 0) { + throw new InputRangeException(); + } + break; + } catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } catch (InputRangeException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } + parameter.setMinTime(minUsageTime); + + System.out.println("Enter minimum payment amount"); + int minPaymentAmount; + while (true) { + try { + minPaymentAmount = Integer.parseInt(nextLine()); + if (minPaymentAmount < 0) { + throw new InputRangeException(); + } + break; + } catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } catch (InputRangeException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } + parameter.setMinPay(minPaymentAmount); group.setParameter(parameter); - allCustomers.refresh(allGroups); // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 - break; // 루프를 빠져나감 + allCustomers.refresh(allGroups); } } } - public void viewParameter() { - GroupType groupType = chooseGroup(); - Group group = allGroups.find(groupType); - - if (group != null && group.getParameter() != null) { - System.out.println("\n" + group); - } else { - System.out.println("\n" + groupType + " group is not initialized yet."); - } - } - public void updateParameter() { - GroupType groupType = chooseGroup(); - Group group = allGroups.find(groupType); - - if (group != null && group.getParameter() != null) { - group.Parameter parameter = group.getParameter(); - - System.out.println("\nCurrent Parameter:"); - System.out.println(parameter); - - System.out.print("\nEnter the new values:\n- Minimum Payment: "); - int minPayment = nextInt(util.Message.END_MSG); - System.out.print("- Minimum Time: "); - int minTime = nextInt(util.Message.END_MSG); - - parameter.setMinPay(minPayment); - parameter.setMinTime(minTime); - group.setParameter(parameter); - allCustomers.refresh(allGroups); - } else { - System.out.println("\n" + groupType + " group is not initialized yet."); + public void viewParameter() { + while (true) { + GroupType groupType = chooseGroup(); + if (groupType == null) { + break; + } + Group group = allGroups.find(groupType); + if (group == null || group.getParameter() == null) { + System.out.println("\n" + groupType + " group does not exist."); + } else { + System.out.println("\n" + group.getParameter()); + } } } - private int nextInt(String endMsg) { + public void updateParameter() { while (true) { - try { - System.out.print("\nEnter an integer value: "); - String input = nextLine(endMsg); - return Integer.parseInt(input); - } catch (NumberFormatException e) { - System.out.println(Message.ERR_MSG_INVALID_INPUT_TYPE); - } catch (InputEndException e) { - System.out.println(Message.ERR_MSG_INPUT_END); - return 0; + GroupType groupType = chooseGroup(); + if (groupType == null) { + break; + } + Group group = allGroups.find(groupType); + if (group == null || group.getParameter() == null) { + System.out.println("\n" + groupType + " group does not exist."); + } else { + Parameter parameter = group.getParameter(); + System.out.println("\nCurrent parameter:"); + System.out.println(parameter); + + System.out.println("Enter new minimum usage time (current: " + parameter.getMinTime() + ")"); + int minUsageTime; + while (true) { + try { + minUsageTime = Integer.parseInt(nextLine()); + if (minUsageTime < 0) { + throw new InputRangeException(); + } + break; + } catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } catch (InputRangeException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } + parameter.setMinTime(minUsageTime); + + System.out.println("Enter new minimum payment amount (current: " + parameter.getMinPay() + ")"); + int minPaymentAmount; + while (true) { + try { + minPaymentAmount = Integer.parseInt(nextLine()); + if (minPaymentAmount < 0) { + throw new InputRangeException(); + } + break; + } catch (NumberFormatException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); + } catch (InputRangeException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } + parameter.setMinPay(minPaymentAmount); + + System.out.println("\nNew parameter:"); + System.out.println(parameter); + + allCustomers.refresh(allGroups); } } } - public static GroupType replaceFullName(String name) { - switch (name.toUpperCase()) { - case "G": - return GroupType.GENERAL; - case "V": - return GroupType.VIP; - case "VV": - return GroupType.VVIP; - default: - return null; - } + public interface Menu { + void manage(); } - - - -} - +} \ No newline at end of file diff --git a/me.smartstore/menu/MainMenu.java b/me.smartstore/menu/MainMenu.java index 3b57875c..228aca4a 100644 --- a/me.smartstore/menu/MainMenu.java +++ b/me.smartstore/menu/MainMenu.java @@ -5,8 +5,6 @@ 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() { @@ -20,7 +18,7 @@ private MainMenu() {} @Override public void manage() { - while ( true ) { // 프로그램 실행 while + while ( true ) { int choice = mainMenu.chooseMenu(new String[] { "Parameter", "Customer", @@ -36,10 +34,8 @@ else if (choice == 2) { else if (choice == 3) { summaryMenu.manage(); } - else { // choice == 4 + else { System.out.println("Program Finished"); - // 데이터 저장 코드 추가 - // saveData()는 데이터를 파일에 저장하는 메서드로 가정 saveData(); break; } @@ -58,19 +54,16 @@ public void editParameter() { groupMenu.setParameter(); } else if (choice == 2) { - // 파라미터를 보여주는 메서드 호출 } else if (choice == 3) { - // 파라미터를 수정하는 메서드 호출 } - else { // choice == 4 + else { break; } } } public void saveData() { - // 데이터를 파일에 저장하는 코드 System.out.println("Data Saved"); } } diff --git a/me.smartstore/menu/Menu.java b/me.smartstore/menu/Menu.java index f9bc2603..e518901f 100644 --- a/me.smartstore/menu/Menu.java +++ b/me.smartstore/menu/Menu.java @@ -10,7 +10,7 @@ public interface Menu { Scanner scanner = new Scanner(System.in); - default String nextLine() { // 하나의 프로그램 상에서 nextLine() 함수를 통해서 사용자 입력을 받음 + default String nextLine() { return scanner.nextLine().toUpperCase(); } @@ -22,7 +22,7 @@ default String nextLine(String end) { } default int chooseMenu(String[] menus) { - while ( true ) { // 예외 복구 while + while ( true ) { try { System.out.println("==============================="); for (int i = 0; i < menus.length; i++) { @@ -32,7 +32,7 @@ default int chooseMenu(String[] menus) { System.out.print("Choose One: "); int choice = Integer.parseInt(nextLine()); if (choice >= 1 && choice <= menus.length) return choice; - throw new InputRangeException(); // choice 가 범위에 벗어남 + throw new InputRangeException(); } catch (InputMismatchException e) { System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT); @@ -44,5 +44,5 @@ default int chooseMenu(String[] menus) { } } - void manage(); // 각 서브메뉴들을 관리하는 함수 (각 서브메뉴의 최상위 메뉴) + void manage(); } diff --git a/me.smartstore/menu/SummaryMenu.java b/me.smartstore/menu/SummaryMenu.java index e3ae86ee..2ea3f69c 100644 --- a/me.smartstore/menu/SummaryMenu.java +++ b/me.smartstore/menu/SummaryMenu.java @@ -8,8 +8,6 @@ import java.util.List; public class SummaryMenu implements Menu { - - // singleton private static SummaryMenu summaryMenu; public static SummaryMenu getInstance() { @@ -25,7 +23,7 @@ private SummaryMenu() {} public void manage() { Customers allCustomers = Customers.getInstance(); - while (true) { // 서브 메뉴 페이지를 유지하기 위한 while + while (true) { int choice = chooseMenu(new String[]{ "Summary", "Summary (Sorted By Name)", @@ -34,12 +32,10 @@ public void manage() { "Back"}); switch (choice) { case 1: - // SummaryMenu에서 제공하는 "Summary" 기능 실행 System.out.println("========== Summary =========="); printCustomers(allCustomers.getList()); break; case 2: - // SummaryMenu에서 제공하는 "Summary (Sorted By Name)" 기능 실행 System.out.println("========== Summary (Sorted By Name) =========="); List customersSortedByName = allCustomers.getList(); Collections.sort(customersSortedByName, new Comparator() { @@ -51,7 +47,6 @@ public int compare(Customer o1, Customer o2) { printCustomers(customersSortedByName); break; case 3: - // SummaryMenu에서 제공하는 "Summary (Sorted By Time)" 기능 실행 System.out.println("========== Summary (Sorted By Time) =========="); List customersSortedByTime = allCustomers.getList(); Collections.sort(customersSortedByTime, new Comparator() { @@ -63,7 +58,6 @@ public int compare(Customer o1, Customer o2) { printCustomers(customersSortedByTime); break; case 4: - // SummaryMenu에서 제공하는 "Summary (Sorted By Pay)" 기능 실행 System.out.println("========== Summary (Sorted By Pay) =========="); List customersSortedByPay = allCustomers.getList(); Collections.sort(customersSortedByPay, new Comparator() { @@ -75,7 +69,6 @@ public int compare(Customer o1, Customer o2) { printCustomers(customersSortedByPay); break; case 5: - // 이전 메뉴로 돌아가기 return; } }