diff --git a/Main.class b/Main.class new file mode 100644 index 00000000..85cce4d3 Binary files /dev/null and b/Main.class differ diff --git a/Main.java b/Main.java new file mode 100644 index 00000000..537b661a --- /dev/null +++ b/Main.java @@ -0,0 +1,19 @@ +package me.smartstore; + +public class Main { + public static void main(String[] args) { + // SmartStoreApp.getInstance().test().run(); // function chaining + // // SmartStoreApp.getInstance().run(); + Customer customerLee = new Customer(); + customerLee.setCustomerName("이순신"); + customerLee.setCustomerID(10010); + customerLee.bonusPoint = 1000; + System.out.println(customerLee.showCustomerInfo()); + + VIPCustomer customerKim = new VIPCustomer(); + customerKim.setCustomerName("김유신"); + customerKim.setCustomerID(10020); + customerKim.bonusPoint = 10000; + System.out.println(customerKim.showCustomerInfo()); + } +} \ No newline at end of file diff --git a/SmartStoreApp.java b/SmartStoreApp.java new file mode 100644 index 00000000..d37ca9dd --- /dev/null +++ b/SmartStoreApp.java @@ -0,0 +1,66 @@ +package me.smartstore; +import me.smartstore.customers.Customer; +import me.smartstore.customers.Customers; +import me.smartstore.groups.Group; +import me.smartstore.groups.GroupType; +import me.smartstore.groups.Groups; +import me.smartstore.groups.Parameter; +import me.smartstore.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.04.27"); + System.out.println(" Copyright 2023 Eunbin All rights reserved."); + System.out.println("===========================================\n"); + } + + /** + * @return + */ + 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); + + // @TODO: refresh do not implemented yet. + allCustomers.refresh(allGroups); + + return this; // smartStoreApp + } + + public void run() { + details(); + mainMenu.manage(); + + } +} \ No newline at end of file diff --git a/SmartStoreApplication.class b/SmartStoreApplication.class new file mode 100644 index 00000000..116b2f94 Binary files /dev/null and b/SmartStoreApplication.class differ diff --git a/arrays/Collections.java b/arrays/Collections.java new file mode 100644 index 00000000..77b6adda --- /dev/null +++ b/arrays/Collections.java @@ -0,0 +1,14 @@ +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/arrays/DArray.java b/arrays/DArray.java new file mode 100644 index 00000000..f3e59412 --- /dev/null +++ b/arrays/DArray.java @@ -0,0 +1,163 @@ +package me.smartstore.arrays; + +import me.smartstore.exception.ElementNotFoundException; +import me.smartstore.exception.NullArgumentException; +import java.util.EmptyStackException; + +public class DArray implements Collections { + + protected static final int DEFAULT = 10; + + protected T[] arrays; + protected int size; + protected int capacity; + + public static int getDefault() { + return DEFAULT; + } + + public T[] getArrays() { + return arrays; + } + + public void setArrays(T[] arrays) { + this.arrays = arrays; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public int getCapacity() { + return capacity; + } + + public void setCapacity(int capacity) { + this.capacity = 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(); + + for(int i=0; i=size) throw new IndexOutOfBoundsException(); + if(object == null) throw new NullArgumentException(); + if(size=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 EmptyStackException(); + if(index<0 || index>=size) throw new IndexOutOfBoundsException(); + + T popElement = arrays[index]; + arrays[index] = null; + + for(int i=index+1; i { + // singleton + private static Groups allGroups; + + public static Groups getInstance() { + if (allGroups == null) { + allGroups = new Groups(); + } + return allGroups; + } + + private Groups() {} + + public Group find(GroupType groupType) { + // NOTE: 오류나는 코드 + // arrays.length: capacity + // arrays.size: 실제 객체가 들어가있는 수 +// System.out.println(size); +// for (int i = 0; i < size; i++) { +// if (arrays[i].getGroupType() == groupType) { +// return arrays[i]; +// } +// } +// return null; + + + for (int i = 0; i < allGroups.size; i++) { + if (allGroups.get(i).getGroupType() == groupType) { + return allGroups.get(i); + } + } + return null; + +// for (int i = 0; i < this.size; i++) { +// if (this.get(i).getGroupType() == groupType) { +// return this.get(i); +// } +// } +// +// return null; + } +} \ No newline at end of file diff --git a/groups/Parameter.class b/groups/Parameter.class new file mode 100644 index 00000000..16a9c8a9 Binary files /dev/null and b/groups/Parameter.class differ diff --git a/groups/Parameter.java b/groups/Parameter.java new file mode 100644 index 00000000..1e550859 --- /dev/null +++ b/groups/Parameter.java @@ -0,0 +1,53 @@ +package me.smartstore.groups; +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 + + '}'; + } +} \ No newline at end of file diff --git a/menu/CustomerMenu.class b/menu/CustomerMenu.class new file mode 100644 index 00000000..15fd658f Binary files /dev/null and b/menu/CustomerMenu.class differ diff --git a/menu/CustomerMenu.java b/menu/CustomerMenu.java new file mode 100644 index 00000000..35234000 --- /dev/null +++ b/menu/CustomerMenu.java @@ -0,0 +1,29 @@ +package me.smartstore.menu; + +public class CustomerMenu implements Menu { + // singleton + 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"}); + + } + + } +} \ No newline at end of file diff --git a/menu/GroupMenu.class b/menu/GroupMenu.class new file mode 100644 index 00000000..4ee0ceb3 Binary files /dev/null and b/menu/GroupMenu.class differ diff --git a/menu/GroupMenu.java b/menu/GroupMenu.java new file mode 100644 index 00000000..31ebd96d --- /dev/null +++ b/menu/GroupMenu.java @@ -0,0 +1,79 @@ +package me.smartstore.menu; +import me.smartstore.customers.Customers; +import me.smartstore.exception.InputEndException; +import me.smartstore.groups.Group; +import me.smartstore.groups.GroupType; +import me.smartstore.groups.Groups; +import me.smartstore.groups.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 GroupType chooseGroup() { + while ( true ) { + try { + System.out.print("Which group (GENERAL (G), VIP (V), VVIP (VV))? "); + String choice = nextLine(Message.END_MSG); + // group (str) -> GroupType (enum) + // "VIP" -> GroupType.VIP + + GroupType groupType = GroupType.valueOf(choice).replaceFullName(); + return groupType; + } catch (InputEndException e) { + System.out.println(Message.ERR_MSG_INPUT_END); + return null; + } catch (IllegalArgumentException e) { + System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE); + } + } + } + + public void setParameter() { // 초기화할 때만 호출 가능 + while ( true ) { + GroupType groupType = chooseGroup(); + + // GroupType에 해당하는 group 객체를 찾아야 함 + Group group = allGroups.find(groupType); + if (group != null && group.getParameter() != null) { // group.getParameter()이 null이 아니면 이미 초기화됨 + System.out.println("\n" + group.getGroupType() + " group already exists."); + System.out.println("\n" + group); + } else { + Parameter parameter = new Parameter(); + // time, pay 사용자 입력받은 후, 설정 필요 + + group.setParameter(parameter); + allCustomers.refresh(allGroups); // 파라미터가 변경되었거나 추가되는 경우, 고객 분류를 다시 해야함 + } + } + } +} \ No newline at end of file diff --git a/menu/MainMenu.java b/menu/MainMenu.java new file mode 100644 index 00000000..7ba85d92 --- /dev/null +++ b/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; + } + } + } +} \ No newline at end of file diff --git a/menu/Menu.class b/menu/Menu.class new file mode 100644 index 00000000..e789a30f Binary files /dev/null and b/menu/Menu.class differ diff --git a/menu/Menu.java b/menu/Menu.java new file mode 100644 index 00000000..a2332ffb --- /dev/null +++ b/menu/Menu.java @@ -0,0 +1,46 @@ +package me.smartstore.menu; +import me.smartstore.exception.InputRangeException; +import me.smartstore.exception.InputEndException; +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! **"); + 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(); // 각 서브메뉴들을 관리하는 함수 (각 서브메뉴의 최상위 메뉴) +} \ No newline at end of file diff --git a/menu/OrderType.class b/menu/OrderType.class new file mode 100644 index 00000000..b22deef4 Binary files /dev/null and b/menu/OrderType.class differ diff --git a/menu/SummarizedMenu.class b/menu/SummarizedMenu.class new file mode 100644 index 00000000..332f3bbd Binary files /dev/null and b/menu/SummarizedMenu.class differ diff --git a/menu/SummaryMenu.java b/menu/SummaryMenu.java new file mode 100644 index 00000000..b37bb7c5 --- /dev/null +++ b/menu/SummaryMenu.java @@ -0,0 +1,27 @@ +package me.smartstore.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"}); + } + } +} \ No newline at end of file diff --git a/util/Message.class b/util/Message.class new file mode 100644 index 00000000..8e8789db Binary files /dev/null and b/util/Message.class differ diff --git a/util/Message.java b/util/Message.java new file mode 100644 index 00000000..a3f73c1f --- /dev/null +++ b/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"; +} \ No newline at end of file diff --git a/util/UtilMethod.class b/util/UtilMethod.class new file mode 100644 index 00000000..24bd7273 Binary files /dev/null and b/util/UtilMethod.class differ