-
Notifications
You must be signed in to change notification settings - Fork 1
[1차] Java ToyProject upload by TaeHyoungSong #23
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
Ussu1112
wants to merge
14
commits into
FastCampusKDTBackend:main
Choose a base branch
from
Ussu1112:TaeHyoungSong
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 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d9e6386
create package, 동적배열, 예외처리 설정
Ussu1112 69c9e73
클래스 구현 및 강의 복습 후 소스 작성
Ussu1112 36d342e
feat: implement menus
Ussu1112 4f35821
feat: Set Parameter, View Parameter
Ussu1112 1f582e5
feat: implement updateParameter
Ussu1112 e9e807c
feat: implement customerMenu( addCustomer, updateCustomer, deleteCust…
Ussu1112 36ec32e
fix: refresh() 누락, updateParameter시 setParameter와 동일하게 작동 하는 error
Ussu1112 38f46dd
feat: implement SummaryMenu
Ussu1112 d783128
refactor: 예외처리 출력문 수정, 개행, 주석, 출력문 삭제
Ussu1112 35d53a8
fix: SetParameter end 기능 수정
Ussu1112 b59ddd0
fix: updateParameter GroupType.NONE 인 경우 예외 추가
Ussu1112 eb1837d
fix: delete Customer시 IndexOutOfBoundsException error 수정
Ussu1112 b5e80d6
refactor: 싱글톤 객체 생성자 주입으로 변경, Customer 초기 값 설정 변경
Ussu1112 c5e7bf9
refactor: 주석 삭제, Parameter 클래스 이름 변경
Ussu1112 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,8 @@ | ||
| package me.smartstore; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| SmartStoreApp.getInstance().test().run(); // function chaining | ||
| // SmartStoreApp.getInstance().run(); | ||
| } | ||
| } |
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,57 @@ | ||
| 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; | ||
|
|
||
| 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 taeHyoung 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() * 10) + 1) * 5, | ||
| ((int) (Math.random() * 5) + 1) * 100000)); | ||
| } | ||
| allCustomers.refresh(allGroups); | ||
|
|
||
| return this; // smartStoreApp | ||
| } | ||
|
|
||
| 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,13 @@ | ||
| 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); | ||
| } |
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,143 @@ | ||
| package me.smartstore.arrays; | ||
|
|
||
| import me.smartstore.exception.ElementNotFoundException; | ||
| import me.smartstore.exception.EmptyArrayException; | ||
| import me.smartstore.exception.NullArgumentException; | ||
|
|
||
| public class DArray<T> implements Collections<T> { | ||
| protected static final int DEFAULT = 10; | ||
|
|
||
| protected T[] arrays; | ||
| protected int size; | ||
| protected int capacity; | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public DArray() throws ClassCastException { | ||
| arrays = (T[]) new Object[DEFAULT]; | ||
| capacity = DEFAULT; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public DArray(int initial) throws ClassCastException { | ||
| 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; | ||
| } | ||
|
|
||
| // 배열에 얼마나 capacity 남아있는지 외부에 알려줄 필요가 없기 때문에 <protected>으로 정의 | ||
| protected int capacity() { | ||
| return capacity; | ||
| } | ||
|
|
||
| @Override | ||
| public T get(int index) throws IndexOutOfBoundsException { | ||
| if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); | ||
| return arrays[index]; | ||
| } | ||
|
|
||
| /** | ||
| * @param: ... | ||
| * @return: ... | ||
| * @throws: IndexOutOfBoundsException | ||
| * @throws: NullArgumentException | ||
| * */ | ||
| @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 | ||
| } | ||
|
|
||
| // 배열의 cap이 부족한 경우 | ||
| @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; | ||
| } | ||
| } |
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,117 @@ | ||
| package me.smartstore.customer; | ||
|
|
||
| import me.smartstore.group.GroupType; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class Customer implements Comparable<Customer> { | ||
| private int cusNo; | ||
| private String cusId; | ||
| private String cusName; | ||
| private Integer cusTotalTime; | ||
| private Integer cusTotalPay; | ||
| private GroupType group; // 현재 분류 기준에 의해 각 고객을 분류된 결과 | ||
|
|
||
| private static int seqNum = 1; | ||
|
|
||
| public Customer() { | ||
| //초기 값 설정 | ||
| cusNo = seqNum; | ||
| group = GroupType.NONE; | ||
| seqNum++; | ||
| } | ||
|
|
||
| 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(); | ||
| this.cusName = cusName; | ||
| this.cusId = cusId; | ||
| this.cusTotalTime = cusTotalTime; | ||
| this.cusTotalPay = cusTotalPay; | ||
| } | ||
|
|
||
| public int getCusNo() { | ||
| return cusNo; | ||
| } | ||
|
|
||
| public void setCusNo(int cusNo) { | ||
| this.cusNo = cusNo; | ||
| } | ||
|
|
||
| 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 GroupType getGroup() { | ||
| return group; | ||
| } | ||
|
|
||
| public void setGroup(GroupType 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 + | ||
| '}'; | ||
| } | ||
|
|
||
| @Override | ||
| public int compareTo(Customer o) { | ||
| return o.getCusNo(); | ||
| } | ||
| } |
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.
의존성 주입부분은 저도 어떻게 해야될 지 잘 모르겠는데
같이 고민해볼까요?
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.
싱글톤 객체를 주입받는 방식에 대해 찾아봤습니다...🤔
생성자 주입방식과 setter 주입방식를 자주 쓰지만
setter 주입방식은 코드의 유연성에 초점이 맞춰져 있는듯 하고,
생성자 주입방식은 객체의 불변성이나 코드의 가독성에 더 좋은듯합니다.
토이프로젝트에서는 생성자 주입방식이 더 낫지 않을까요?