-
Notifications
You must be signed in to change notification settings - Fork 1
[1차 VER1.0] Java ToyProject upload by JeonghoSong #26
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
Open
sdfgx123
wants to merge
5
commits into
FastCampusKDTBackend:main
Choose a base branch
from
sdfgx123:jeongho
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ecb10bb
20230510 02:30 현재 기준 작업 완료 내용 commit
sdfgx123 7bea6fa
[20230510] SummaryMenu 구현
sdfgx123 600dba4
style(CusomterMenu): fix println to printf for not getting new line
sdfgx123 6c45f0a
refactor(CustomerMenu): allGroups initiation error solved and others
sdfgx123 a55bc7c
refactor: edit allGroups getInstance method and constructor
sdfgx123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package me.smartstore; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
SmartStoreApp.getInstance().run(); // function chaining | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package me.smartstore; | ||
|
||
import me.smartstore.customer.Customer; | ||
import me.smartstore.customer.Customers; | ||
import me.smartstore.group.Group; | ||
import me.smartstore.group.GroupType; | ||
import me.smartstore.group.Groups; | ||
import me.smartstore.group.Parameter; | ||
import me.smartstore.menu.MainMenu; | ||
|
||
public class SmartStoreApp { | ||
|
||
private final Groups allGroups = Groups.getInstance(); | ||
private final Customers allCustomers = Customers.getInstance(); | ||
private final MainMenu mainMenu = MainMenu.getInstance(); | ||
|
||
private static SmartStoreApp smartStoreApp; | ||
|
||
// singletone pattern | ||
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.00"); | ||
System.out.println(" Copyright 2023 JeonghoSong All rights reserved."); | ||
System.out.println("===========================================\n"); | ||
} | ||
|
||
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++) { | ||
int spentTime = ((int) (Math.random() * 5) + 1) * 10; | ||
int totalPay = ((int) (Math.random() * 5) + 1) * 100000; | ||
|
||
// Group customerGroup = allGroups.getGroupByParameter(spentTime, totalPay); | ||
|
||
// 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)); | ||
|
||
// allCustomers.add(new Customer( | ||
// Character.toString( | ||
// (char) ('a' + i) + "123", | ||
// spentTime, | ||
// totalPay, | ||
// customerGroup | ||
// ) | ||
// )); | ||
|
||
// // 마지막 사용하던 코드 | ||
// allCustomers.add(new Customer( | ||
// Character.toString( | ||
// (char) ('a' + i)), | ||
// (char) ('a' + i) + "123", | ||
// spentTime, | ||
// totalPay, | ||
// customerGroup)); | ||
} | ||
|
||
System.out.println("allCustomers = " + allCustomers); | ||
System.out.println("allGroups = " + allGroups); | ||
|
||
return this; | ||
} | ||
|
||
public void run() { | ||
details(); | ||
mainMenu.manage(); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package me.smartstore.arrays; | ||
|
||
public interface Collections<T> { | ||
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); | ||
void extend(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package me.smartstore.arrays; | ||
|
||
import me.smartstore.exception.EmptyArrayException; | ||
import me.smartstore.group.Group; | ||
import me.smartstore.util.Message; | ||
|
||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
import java.util.Objects; | ||
import java.util.stream.IntStream; | ||
|
||
import static java.util.Arrays.copyOf; | ||
|
||
public class DArray<T> implements Collections<T> { | ||
|
||
protected static final int DEFAULT = 10; | ||
|
||
protected T[] arrays; | ||
protected int size; | ||
protected int capacity; | ||
|
||
/** | ||
* ClassCastException 예외 던지는 이유 | ||
* DArray Constructor에서 T타입이 Object 타입으로 캐스팅되는 과정에서 발생 가능 | ||
* | ||
* 즉, T타입이 Object 타입과 호환되지 않아서 ClassCastException 예외 발생 가능 | ||
*/ | ||
public DArray() throws ClassCastException { | ||
arrays = (T[]) new Object[DEFAULT]; | ||
capacity = DEFAULT; | ||
} | ||
|
||
public DArray(int initial) throws ClassCastException { | ||
arrays = (T[]) new Object[initial]; | ||
capacity = initial; | ||
} | ||
|
||
/** | ||
* ClassCastException 안 던지는 이유 | ||
* T[] 배열을 이미 파라미터로 직접 전달 받음 > 예외 발생 가능성 없음 | ||
*/ | ||
public DArray(T[] arrays) { | ||
this.arrays = arrays; | ||
capacity = arrays.length; | ||
size = arrays.length; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return size; | ||
} | ||
|
||
/** | ||
* | ||
* @param index | ||
* @return | ||
* @throws IndexOutOfBoundsException | ||
* | ||
* 예외 처리를 두 번 해주는 이유 | ||
* 메서드 호출자가 index value를 잘못 전달할 경우 걸러지지 않음. | ||
* if문 안에서는 인덱스 값이 유효하지 않은 경우에 대한 예외 처리 담당 | ||
*/ | ||
@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) { | ||
|
||
} | ||
|
||
@Override | ||
public int indexOf(T object) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void add(T object) { | ||
// if (object == null) { | ||
// throw new | ||
// } | ||
if (size < capacity) { | ||
arrays[size] = object; | ||
size++; | ||
} else { | ||
extend(); | ||
add(object); | ||
} | ||
} | ||
|
||
@Override | ||
public void add(int index, T object) { | ||
|
||
} | ||
|
||
@Override | ||
public T pop() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public T pop(int index) throws EmptyArrayException, IndexOutOfBoundsException { | ||
if (size==0) throw new EmptyArrayException(Message.ERR_MSG_ARR_EMPTY); | ||
if (index < 0 || index > size) throw new IndexOutOfBoundsException(Message.ERR_MSG_ARR_OUT_OF_BOUNDARY); | ||
T item = arrays[index]; | ||
for (int i = index; i < size; i++) { | ||
arrays[i] = arrays[i+1]; | ||
} | ||
size--; | ||
return item; | ||
} | ||
|
||
// public boolean isEmpty() { | ||
// | ||
// } | ||
|
||
@Override | ||
public T pop(T object) throws EmptyArrayException { | ||
return pop(size-1); | ||
} | ||
|
||
/** | ||
* 목적 : 리스트의 capacity가 모자랄 경우, *2만큼 증분하여 리스트 길이를 증가 | ||
*/ | ||
@Override | ||
public void extend() { | ||
capacity *= 2; | ||
arrays = copyOf(arrays, capacity); | ||
} | ||
|
||
|
||
// @Override | ||
// public Iterator<T> iterator() { | ||
// return IntStream.range(0, size) | ||
// .mapToObj(i -> arrays[i]) | ||
// .iterator(); | ||
// } | ||
|
||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package me.smartstore.customer; | ||
|
||
import me.smartstore.group.Group; | ||
import me.smartstore.group.Groups; | ||
|
||
public class Customer { | ||
private String customerName; | ||
private String customerId; | ||
private Integer customerTotalTime; | ||
private Integer customerTotalPay; | ||
private Group group; // 분류 기준에 따라 고객을 분류한 결과 | ||
|
||
public Customer() { | ||
} | ||
|
||
public Customer(String customerId) { | ||
this.customerId = customerId; | ||
} | ||
|
||
public Customer(String customerName, String customerId) { | ||
this.customerName = customerName; | ||
this.customerId = customerId; | ||
} | ||
|
||
public Customer(String customerName, String customerId, Integer customerTotalTime, Integer customerTotalPay) { | ||
this.customerName = customerName; | ||
this.customerId = customerId; | ||
this.customerTotalTime = customerTotalTime; | ||
this.customerTotalPay = customerTotalPay; | ||
} | ||
|
||
public Customer(String customerName, String customerId, Integer customerTotalTime, Integer customerTotalPay, Group group) { | ||
this.customerName = customerName; | ||
this.customerId = customerId; | ||
this.customerTotalTime = customerTotalTime; | ||
this.customerTotalPay = customerTotalPay; | ||
} | ||
|
||
public void getCustomerInfo() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오잉? |
||
|
||
} | ||
|
||
public String getCustomerName() { | ||
return customerName; | ||
} | ||
|
||
public void setCustomerName(String customerName) { | ||
this.customerName = customerName; | ||
} | ||
|
||
public String getCustomerId() { | ||
return customerId; | ||
} | ||
|
||
public void setCustomerId(String customerId) { | ||
this.customerId = customerId; | ||
} | ||
|
||
public Integer getCustomerTotalTime() { | ||
return customerTotalTime; | ||
} | ||
|
||
public void setCustomerTotalTime(Integer customerTotalTime) { | ||
this.customerTotalTime = customerTotalTime; | ||
} | ||
|
||
public Integer getCustomerTotalPay() { | ||
return customerTotalPay; | ||
} | ||
|
||
public void setCustomerTotalPay(Integer customerTotalPay) { | ||
this.customerTotalPay = customerTotalPay; | ||
} | ||
|
||
public Group getGroup() { | ||
return group; | ||
} | ||
|
||
public void setGroup(Group group) { | ||
this.group = group; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Customer{" + | ||
"customerName='" + customerName + '\'' + | ||
", customerId='" + customerId + '\'' + | ||
", customerTotalTime=" + customerTotalTime + | ||
", customerTotalPay=" + customerTotalPay + | ||
", group=" + group + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
꼼꼼한 예외처리 좋습니다!!!
어떤 경우 throw로 터트리는게 좋고, 또 어떤 경우 throws로 넘길까 고민해보는거 되게 좋은 것 같아요 👍