Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1차 VER1.0...] Java ToyProject upload by HoyunJung #33

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
feat : set CustomerMenu
기초적인 부분들 완성 AddCustomer은 내용이 길어져 클래스를 나누었음
Todo들 수정해야함
ho30archive committed May 10, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
MylesBorins Myles Borins
commit d743feb5f6b66c5db5b02026cf63716c418f3511
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/KDTBE5_Java_ToyProject/me/smartstore/menu/Menu.class
Binary file not shown.
2 changes: 1 addition & 1 deletion src/me/smartstore/customer/Customer.java
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ public String toString() {
", customerId='" + customerId + '\'' +
", customerTotalTime=" + customerTotalTime +
", customerTotalPay=" + customerTotalPay +
", group=" + group +
", group=GroupType: " + group +
'}';
}
}
29 changes: 0 additions & 29 deletions src/me/smartstore/menu/CustomerMenu.java

This file was deleted.

4 changes: 3 additions & 1 deletion src/me/smartstore/menu/GroupMenu.java
Original file line number Diff line number Diff line change
@@ -126,7 +126,8 @@ public void viewParameter() {
}

public void updateParameter(){
// todo : 파라미터가 하나도 없는 경우 설정하라는 문구가 떠야함
// todo : 파라미터가 하나도 없는 경우 설정하라는 문구가 떠야함, Try-catch로 end예외 잡아야할듯?
// todo : 파라미터값 업데이트 되면 고객재분류 해야됨
while( true ) {
GroupType groupType = chooseGroup();
if (groupType == null){ //chooseGroup에서 end입력되면 null리턴함
@@ -157,6 +158,7 @@ else if (choice == 2) {
else{
System.out.println("\nGroupType: " + group.getGroupType());
System.out.println("Parameter: " + group.getParameter());
allCustomers.refresh(allGroups);
break;
}
}
2 changes: 1 addition & 1 deletion src/me/smartstore/menu/MainMenu.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.smartstore.menu;

import me.smartstore.group.Groups;
import me.smartstore.menu.customer.CustomerMenu;

public class MainMenu implements Menu{
private final CustomerMenu customerMenu = CustomerMenu.getInstance();
7 changes: 7 additions & 0 deletions src/me/smartstore/menu/Menu.java
Original file line number Diff line number Diff line change
@@ -14,7 +14,14 @@ default String nextLine(){
return scanner.nextLine().toUpperCase();
}

// TODO: 2023/05/10 nextLine이 쫌 꼬였음 UpperCase가 되어야되는곳과 아닌곳이 구별되어야 함 ㅠㅠ
default String nextLine(String end){
System.out.println("** Press 'end', if you want to exit! **");
String str = scanner.nextLine().toUpperCase();
if (str.equals(end) || str.equals("END")) throw new InputEndException();
return str;
}
default String nextLineNotUpperCase(String end){
System.out.println("** Press 'end', if you want to exit! **");
String str = scanner.nextLine();
if (str.equals(end) || str.equals("END")) throw new InputEndException();
157 changes: 157 additions & 0 deletions src/me/smartstore/menu/customer/AddCustomer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package me.smartstore.menu.customer;

import me.smartstore.customer.Customer;
import me.smartstore.customer.Customers;
import me.smartstore.exception.InputEndException;
import me.smartstore.group.Groups;
import me.smartstore.menu.Menu;
import me.smartstore.util.Message;

import java.awt.*;

public class AddCustomer implements Menu {
private final Customers allCustomers = Customers.getInstance();
private final Groups allGroups = Groups.getInstance();

//singleton
private static AddCustomer addCustomer;

public static AddCustomer getInstance(){
if (addCustomer == null){
addCustomer = new AddCustomer();
}
return addCustomer;
}

private AddCustomer(){}

//-----

public void addCustomer(){ //Todo : update에서도 활용가능하게 함수화 하기, 이 함수 클래스화 가능한지 생각해보기
while(true){
try {
System.out.println("How many customer to input?");
int n = Integer.parseInt(nextLine(Message.END_MSG));

for (int i = 0; i < n; i++) {
System.out.println("====== Customer "+ (i+1) + " Info. ======");
allCustomers.add(inputCustomerInfo(null));
// 고객정보 입력받는 함수 추가됨
}
allCustomers.refresh(allGroups);
break;
}catch (InputEndException e){
System.out.println(Message.ERR_MSG_INPUT_END);
break;
}catch (IllegalArgumentException e){
System.out.println(Message.ERR_MSG_INVALID_INPUT_RANGE);
}
}
}

public Customer inputCustomerInfo(Customer customer){
//cusotmer이 null일 때 -> 새로운 고객객체를 생성할 때
//cusotmer이 null이 아닐때 -> 기존 고객정보를 수정할 때
String name = "";
String id = "";
Integer spentTime = 0;
Integer totalPay = 0;
if (customer != null){
name = customer.getCustomerName();
id = customer.getCustomerId();
spentTime = customer.getCustomerTotalTime();
totalPay = customer.getCustomerTotalPay();
}
while (true){
int choice = chooseMenu(new String[]{
"Customer Name",
"Customer ID",
"Customer Spent Time",
"Customer Total Pay",
"Back"});

if (choice == 1) {
name = inputCustomerName();
if(name == null) continue;
} else if (choice == 2) {
id = inputCustomerID();
if(id == null) continue;
} else if (choice == 3) {
try{
spentTime = inputSpentTime();
}catch (NullPointerException e){
continue;
}

} else if (choice == 4) {
try{
totalPay = inputTotalPay();
}catch (NullPointerException e){
continue;
}
} else {
return new Customer(name, id, spentTime, totalPay);
}

}

}

public String inputCustomerName(){
try {
System.out.println("\nInput Customer's Name: ");
String name = nextLineNotUpperCase(Message.END_MSG);

return name;
} catch (InputEndException e){
System.out.println(Message.ERR_MSG_INPUT_END);
return null;
}

}

public String inputCustomerID(){
try{
System.out.println("\nInput Customer's ID: ");
String id = nextLineNotUpperCase(Message.END_MSG);
return id;
} catch (InputEndException e){
System.out.println(Message.ERR_MSG_INPUT_END);
return null;
}
}

public Integer inputSpentTime(){
try{
System.out.println("\nInput Customer's Spent Time: ");
Integer spentTime = Integer.parseInt(nextLine(Message.END_MSG));
return spentTime;
} catch (InputEndException e){
System.out.println(Message.ERR_MSG_INPUT_END);
return null;
} catch (IllegalArgumentException e){
System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT);
return null;
}
}

public Integer inputTotalPay(){
try{
System.out.println("\nInput Customer's Total Payment: ");
Integer totalPay = Integer.parseInt(nextLine(Message.END_MSG));
return totalPay;
} catch (InputEndException e){
System.out.println(Message.ERR_MSG_INPUT_END);
return null;
} catch (IllegalArgumentException e){
System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT);
return null;
}
}


@Override
public void manage() {

}
}
104 changes: 104 additions & 0 deletions src/me/smartstore/menu/customer/CustomerMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package me.smartstore.menu.customer;

import me.smartstore.customer.Customer;
import me.smartstore.customer.Customers;
import me.smartstore.exception.InputEndException;
import me.smartstore.group.Groups;
import me.smartstore.menu.Menu;
import me.smartstore.util.Message;

import java.util.InputMismatchException;
import java.util.Scanner;

public class CustomerMenu implements Menu {
private final Customers allCustomers = Customers.getInstance();
private final AddCustomer addCustomer = AddCustomer.getInstance();
private final Groups allGroups = Groups.getInstance();
Scanner scanner = new Scanner(System.in);

// 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"});
if (choice == 1) addCustomer.addCustomer();
else if (choice == 2) viewCustomer();
else if (choice == 3) updateCustomer();
else if (choice == 4) deleteCustomer();
else break;
}
}


public void viewCustomer(){
System.out.println("======= Customer Info. =======");
for (int i = 0; i < allCustomers.size(); i++) {

System.out.printf("No. %d => Customer{userId='%s', name='%s', spentTime=%d, totalPay=%d, "
, i+1,allCustomers.get(i).getCustomerId(),allCustomers.get(i).getCustomerName(),allCustomers.get(i).getCustomerTotalTime(),allCustomers.get(i).getCustomerTotalPay());
if (allCustomers.get(i).getGroup() == null){
System.out.println("group=GroupType: null");
}
else {
System.out.println("group=GroupType: " + allCustomers.get(i).getGroup().getGroupType());
}
}
}

public void updateCustomer(){
// 고객객체를 업데이트 할 때 기존 정보를 불려와야함.
viewCustomer();
while (true){
System.out.printf("\nWhich customer (1 ~ %d) ?", allCustomers.size());
try {
int num = scanner.nextInt();
scanner.nextLine();
if (num > allCustomers.size()) throw new InputMismatchException();
allCustomers.set(num-1, addCustomer.inputCustomerInfo(allCustomers.get(num-1)));
allCustomers.refresh(allGroups);
break;
}catch (InputMismatchException e) {
System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT);
scanner.nextLine();
}
}


}

public void deleteCustomer(){
viewCustomer();
while (true){
System.out.printf("\nWhich customer (1 ~ %d)? ", allCustomers.size());
try {
int num = scanner.nextInt();
scanner.nextLine();
if (num > allCustomers.size()) throw new InputMismatchException();
allCustomers.pop(num-1);
break;
}catch (InputMismatchException e) {
System.out.println(Message.ERR_MSG_INVALID_INPUT_FORMAT);
scanner.nextLine();
}
}



}
}