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 SeoYongHyun #11

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d062594
Feat: Collections ์ธํ„ฐํŽ˜์ด์Šค, DArray ์ถ”๊ฐ€
zjdtm May 3, 2023
358e961
Feat: Customer, Customers ์ถ”๊ฐ€
zjdtm May 3, 2023
a9736c8
Feat: ์‚ฌ์šฉ์ž ์ •์˜ Exception ํด๋ž˜์Šค๋“ค ์ถ”๊ฐ€
zjdtm May 3, 2023
caa8d74
Feat: GroupType, Group, Parameter ์ถ”๊ฐ€
zjdtm May 3, 2023
9fdf64b
Feat: Groups ์ถ”๊ฐ€
zjdtm May 3, 2023
7f95b33
Feat: Main, SmartStoreApp ์ถ”๊ฐ€
zjdtm May 3, 2023
d6d5544
Feat: Menu ์ธํ„ฐํŽ˜์ด์Šค ์ถ”๊ฐ€
zjdtm May 4, 2023
d0d116d
refactor: allGroups -> this ๋กœ ๋ฆฌํŽ™ํ„ฐ๋ง
zjdtm May 4, 2023
084fe20
refactor: refresh ํ•จ์ˆ˜ ๋ฆฌํŽ™ํ„ฐ๋ง
zjdtm May 5, 2023
fe33cab
style: ์ปค๋‹ค๋ž€ ์ฝ”๋“œ ์ˆ˜์ •์ด ์—†์Œ
zjdtm May 5, 2023
531c86f
feat: Message ์ธํ„ฐํŽ˜์ด์Šค ์ถ”๊ฐ€
zjdtm May 6, 2023
b88530f
feat: GroupMenu ์ถ”๊ฐ€
zjdtm May 6, 2023
71a24d3
feat: CustomerMenu ์ถ”๊ฐ€
zjdtm May 6, 2023
5f0175b
feat: SummaryMenu ์ถ”๊ฐ€
zjdtm May 6, 2023
a339717
feat: MainMenu ์ถ”๊ฐ€
zjdtm May 6, 2023
899c6bd
fix: setParameter ํ•จ์ˆ˜ ์ˆ˜์ •
zjdtm May 6, 2023
efd3cb0
fix: addCustomer, updateCustomer, viewCustomer ํ•จ์ˆ˜ ์ˆ˜์ •
zjdtm May 6, 2023
b923714
fix: addCustomer, updateCustomer, viewCustomer ํ•จ์ˆ˜ ์ˆ˜์ •
zjdtm May 6, 2023
f01356b
refactor: Customer ์ƒ์„ฑ์ž ํ•จ์ˆ˜ ๋ฆฌํŽ™ํ„ฐ๋ง
zjdtm May 6, 2023
c0756ad
feat: OrderType ์ถ”๊ฐ€
zjdtm May 8, 2023
4ff3512
refactor: ๊ณ ๊ฐ์ด ์—†์„ ๊ฒฝ์šฐ ์˜ˆ์™ธ์ฒ˜๋ฆฌ
zjdtm May 8, 2023
ea1306e
style: Group ์ด ์ž…๋ ฅ๋˜์—ˆ์„ ๋•Œ ์ถœ๋ ฅ๋ฌธ, Message ์ถœ๋ ฅ๋ฌธ ์ˆ˜์ •
zjdtm May 8, 2023
3565a27
fix: Customer ์ถ”๊ฐ€ ํ•  ์‹œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ
zjdtm May 8, 2023
d41f83d
refactor: null ์ฒ˜๋ฆฌ, Group ์ƒ์„ฑ์ž๋ฅผ ์ด์šฉํ•œ ๊ฐ์ฒด ์ƒ์„ฑ
zjdtm May 9, 2023
1dba2bf
fix: Enter ๋ฅผ ์ž…๋ ฅ ๋ฐ›์„ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ
zjdtm May 9, 2023
f5b2a33
style: ํ•„์š” ์—†๋Š” import ์‚ญ์ œ ๋ฐ
zjdtm May 9, 2023
b3c2299
refactor: Groups ํด๋ž˜์Šค์— findAllGroup ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€
zjdtm May 9, 2023
16668d6
refactor: addCustomer(), updateCustomer() ์ค‘๋ณต๋œ ์ฝ”๋“œ ๋ฆฌํŽ™ํ„ฐ๋ง
zjdtm May 15, 2023
b33d4b0
refactor: allGroups, allCustomers size ํ˜ธ์ถœ ๋ฆฌํŽ™ํ„ฐ๋ง
zjdtm May 15, 2023
936a72f
refactor: Customers ํด๋ž˜์Šค์— groupCount(), findCustomerByGroup ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€
zjdtm May 15, 2023
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
8 changes: 8 additions & 0 deletions me/smartstore/Main.java
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();
}
}
66 changes: 66 additions & 0 deletions me/smartstore/SmartStoreApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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" +
"โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ•šโ•โ•โ–ˆโ–ˆโ•”โ•โ•โ• โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ•šโ•โ•โ–ˆโ–ˆโ•”โ•โ•โ•โ–ˆโ–ˆโ•”โ•โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•\n" +
"โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ• โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— \n" +
"โ•šโ•โ•โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•‘ โ•šโ•โ•โ•โ•โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ• \n" +
"โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘ โ•šโ•โ• โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•‘ โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—\n" +
"โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ• โ•šโ•โ•โ•šโ•โ• โ•šโ•โ•โ•šโ•โ• โ•šโ•โ• โ•šโ•โ• โ•šโ•โ•โ•โ•โ•โ•โ• โ•šโ•โ• โ•šโ•โ•โ•โ•โ•โ• โ•šโ•โ• โ•šโ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•\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() * 5) + 1) * 10,
((int) (Math.random() * 5) + 1) * 100000,
null));
}

allCustomers.refresh(allGroups);

System.out.println("allCustomers = " + allCustomers);
System.out.println("allGroups = " + allGroups);

return this; // smartStoreApp
}

Choose a reason for hiding this comment

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

์—ฌ๊ธฐ์™€ Main ์˜ test๋Š” ๋น ์ ธ๋„ ๊ดœ์ฐฎ์„๊ฑฐ๊ฐ™์Šต๋‹ˆ๋‹ค :D

public void run() {
details();
mainMenu.manage();

}
}
16 changes: 16 additions & 0 deletions me/smartstore/arrays/Collections.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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);
}
145 changes: 145 additions & 0 deletions me/smartstore/arrays/DArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
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> { // Dynamic Array

protected static final int DEFAULT = 10;

protected T[] arrays;
protected int size;
protected int capacity;

public DArray() throws ClassCastException {
arrays = (T[]) new Object[DEFAULT];
capacity = DEFAULT;
}

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;
}

/////////////////////////////////////////
// add, set, get, pop, indexOf, size, capacity (for dynamic-sized array)

@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;
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;
}
}
121 changes: 121 additions & 0 deletions me/smartstore/customer/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package me.smartstore.customer;

import me.smartstore.exception.InputEmptyException;
import me.smartstore.group.Group;
import me.smartstore.group.GroupType;
import me.smartstore.group.Parameter;

public class Customer {
private String cusName;
private String cusId;
private Integer cusTotalTime;
private Integer cusTotalPay;
private Group group;

public Customer() {
this.group = new Group(new Parameter(0, 0), GroupType.NONE);
}

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, Group group) {
this.cusName = cusName;
this.cusId = cusId;
this.cusTotalTime = cusTotalTime;
this.cusTotalPay = cusTotalPay;
this.group = group;
}

public String getCusName() {
return cusName;
}

public void setCusName(String cusName) {
if(cusName.equals("")){
throw new InputEmptyException();
}else {
this.cusName = cusName;
}
}

public String getCusId() {
return cusId;
}

public void setCusId(String cusId) {
if(cusId.equals("")){
throw new InputEmptyException();
}else {
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 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;

if (getCusName() != null ? !getCusName().equals(customer.getCusName()) : customer.getCusName() != null)
return false;
if (getCusId() != null ? !getCusId().equals(customer.getCusId()) : customer.getCusId() != null) return false;
if (getCusTotalTime() != null ? !getCusTotalTime().equals(customer.getCusTotalTime()) : customer.getCusTotalTime() != null)
return false;
if (getCusTotalPay() != null ? !getCusTotalPay().equals(customer.getCusTotalPay()) : customer.getCusTotalPay() != null)
return false;
return getGroup() != null ? getGroup().equals(customer.getGroup()) : customer.getGroup() == null;
}

@Override
public int hashCode() {
int result = getCusName() != null ? getCusName().hashCode() : 0;
result = 31 * result + (getCusId() != null ? getCusId().hashCode() : 0);
result = 31 * result + (getCusTotalTime() != null ? getCusTotalTime().hashCode() : 0);
result = 31 * result + (getCusTotalPay() != null ? getCusTotalPay().hashCode() : 0);
result = 31 * result + (getGroup() != null ? getGroup().hashCode() : 0);
return result;
}

@Override
public String toString() {
return "Customer{" +
"cusName='" + cusName + '\'' +
", cusId='" + cusId + '\'' +
", cusTotalTime=" + cusTotalTime +
", cusTotalPay=" + cusTotalPay +
", group=" + group.getGroupType() +
'}';
}
}
Loading