Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
### Java template
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

.idea
out
92 changes: 92 additions & 0 deletions src/READMD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# 프로젝트 요구사항

## Customer

### 명세서


고객 속성
- 고객 이름
- 고객 아이디
- 고객 스마트스토어를 이용시간
- 고객 스마트스토어에서 구매한 총 결제금액서
- Group 속성 추가

### 요구사항

- Customers - Refresh() 메서드 구현
- Customers - Summary sort 메서드 구현
- Customers - 정렬 로직 구현

### 해결책 및 코드 로직

1. 속성 만들기
2. Getter, Setter 구현

## Group

### 요구 사항

- Groups - find() 구현

### 명세서

- 분류 기준 : 시간 - 금액
- General
- VIP
- VVIP
- NONE

### 해결책 및 코드 로직


1. Parameter (minTime, minPay)

## Menu

### 요구 사항

분류기준
- 고객의 분류기준을 입력할 수 있다.
- 고객의 분류기준을 설정할 수 있다.
- 고객의 분류기준을 수정할 수 있다.


고객정보
- 고객의 정보를 입력할 수 있다.
- 고객의 정보를 추가할 수 있다.
- 고객의 정보를 삭제할 수 있다.


고객 분류기능
- 분류기준에 의해 고객을 분류할 수 있다.
- 분류기준에 의해 분류된 고객의 정보를 출력할 수 있다.
- 분류기준에 의해 분류된 고객의 정보를 이름순으로 정렬할 수 있다.
- 분류기준에 의해 분류된 고객의 정보를 총 이용시간 순으로 정렬할 수 있다.
- 분류기준에 의해 분류된 고객의 정보를 총 결제금액 순으로 정렬할 수 있다.

### 해결책 및 코드 로직

1. GroupMenu
- Set Parameter
- View Parameter
- Update Parameter

2. CustomerMenu
- Add Customer Data
- View Customer Data
- Update Customer Data
- Delete Customer Data

3. SummaryMenu
- Summary view
- By Name Sort
- By Time Sort
- By Pay Sort


## TODO - Refactoring

- [ ] Summary sort 반복적인 코드 일관성 있게 리펙토링 필요
- [ ] TEST코드 구현 필요
- [ ] 반복되는 코드 객체지향적으로 풀이 필요
9 changes: 9 additions & 0 deletions src/me/smartstore/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package me.smartstore;

public class Main {
public static void main(String[] args) {
SmartStoreApp.getInstance().test().run(); // function chaining
// SmartStoreApp.getInstance().run();

}
}
67 changes: 67 additions & 0 deletions src/me/smartstore/SmartStoreApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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.MainMenu;
import me.smartstore.menu.Menu;

public class SmartStoreApp {
private final Groups allGroups = Groups.getInstance();
private final Customers allCustomers = Customers.getInstance();
private final MainMenu mainMenu = MainMenu.getInstance();

// singleton
public 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");
}

// who type is SmartStoreApp
// 체이닝이 되어야 하니까. test().run()
public SmartStoreApp test() {
allGroups.add(new Group(new Parameter(0, 0), GroupType.NONE));
// 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
// allCustomers.refresh(allGroups);

return this;
}

public void run() {
details();
mainMenu.manage();
}
}
92 changes: 92 additions & 0 deletions src/me/smartstore/customers/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package me.smartstore.customers;

import me.smartstore.groups.Group;

import java.util.Objects;

public class Customer {
private String cName;
private String cId;
private Integer totalTime;
private Integer totalPay;
private Group group;

public Customer() {
}

public Customer(String cName, String cId) {
this.cName = cName;
this.cId = cId;
}

public Customer(String cName, String cId, Integer totalTime, Integer totalPay) {
this.cName = cName;
this.cId = cId;
this.totalTime = totalTime;
this.totalPay = totalPay;
}

public String getcName() {
return cName;
}

public void setcName(String cName) {
this.cName = cName;
}

public String getcId() {
return cId;
}

public void setcId(String cId) {
this.cId = cId;
}

public Integer getTotalTime() {
return totalTime;
}

public void setTotalTime(Integer totalTime) {
this.totalTime = totalTime;
}

public Integer getTotalPay() {
return totalPay;
}

public void setTotalPay(Integer totalPay) {
this.totalPay = totalPay;
}

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(cName, customer.cName) && Objects.equals(cId, customer.cId) && Objects.equals(totalTime, customer.totalTime) && Objects.equals(totalPay, customer.totalPay) && Objects.equals(group, customer.group);
}

@Override
public int hashCode() {
return Objects.hash(cName, cId, totalTime, totalPay, group);
}

@Override
public String toString() {
return "Customer{" +
"cName='" + cName + '\'' +
", cId='" + cId + '\'' +
", totalTime=" + totalTime +
", totalPay=" + totalPay +
", group=" + group +
'}';
}
}
71 changes: 71 additions & 0 deletions src/me/smartstore/customers/Customers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package me.smartstore.customers;

import me.smartstore.groups.Group;
import me.smartstore.groups.Groups;
import me.smartstore.util.arrays.Array;

import java.util.Arrays;
import java.util.Comparator;

public class Customers extends Array<Customer> {
private static Customers allCustomers;
private final Groups allGroups = Groups.getInstance();

public static Customers getInstance() {
if (allCustomers == null) {
allCustomers = new Customers();
}
return allCustomers;
}

private Customers() {};

public void refresh() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refresh 메서드를 오버로딩해서 한 고객에 대해서만 업데이트하는 메서드가 있으면 좋을 것 같습니다!
고객 한 명을 추가했는데 모든 고객을 refresh한다면 비효율적이니까요 😀

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그런 생각 안해봤는데, 참고해보겠습니다~

for (int i = 0; i < allCustomers.size(); i++) {
Customer customer = allCustomers.get(i);


for (int j = 0; j < allGroups.size(); j++) {
Group group = allGroups.get(j);

if (group.getParmeter().getMinTime() == null || group.getParmeter().getMinPayment() == null ||
customer.getTotalPay() == null || customer.getTotalTime() == null) {
continue;
}

if ((customer.getTotalTime() >= group.getParmeter().getMinTime()) && (customer.getTotalPay() >= group.getParmeter().getMinPayment())) {
customer.setGroup(group);
}
}
}
}


public Customer[] sortSummary(Comparator<Customer> comparator) {
Customer[] customerArr = initCustomers();
Arrays.sort(customerArr, comparator);
return customerArr;
}

public Customer[] initCustomers() {
Customer[] customerArrs = new Customer[allCustomers.size()];

for (int i = 0; i < allCustomers.size(); i++) {
customerArrs[i] = allCustomers.get(i);
}
return customerArrs;
}

public Comparator<Customer> sortName(int num) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

람다식으로 할 생각은 전혀 못했었는데 덕분에 하나 배워갑니다!👍

return (customer1, customer2) -> num * customer1.getcName().compareTo(customer2.getcName());
}

public Comparator<Customer> sortTime(int num) {
return (customer1, customer2) -> num * customer1.getTotalTime().compareTo(customer2.getTotalTime());
}

public Comparator<Customer> sortPay(int num) {
return (customer1, customer2) -> num * customer1.getTotalPay().compareTo(customer2.getTotalPay());
}

};
Loading