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 JongminJung #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions src/me/smartstore/Main.java
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();
}
}
39 changes: 39 additions & 0 deletions src/me/smartstore/SmartStoreApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package me.smartstore;

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 MainMenu mainMenu = MainMenu.getInstance();


// singleton
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 Jongmin No rights reserved.");
System.out.println("===========================================\n");
}

public void run() {
details();
allGroups.add(new Group(new Parameter(0, 0), GroupType.NONE));
mainMenu.manage();
}
}
14 changes: 14 additions & 0 deletions src/me/smartstore/arrays/Collections.java
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);
}
137 changes: 137 additions & 0 deletions src/me/smartstore/arrays/DArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package me.smartstore.arrays;


import me.smartstore.arrays.exception.ElementNotFoundException;
import me.smartstore.arrays.exception.EmptyArrayException;
import me.smartstore.arrays.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;

@SuppressWarnings("unchecked")
public DArray() {
arrays = (T[]) new Object[DEFAULT];
capacity = DEFAULT;
}

@SuppressWarnings("unchecked")
public DArray(int initial) {
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;
}

protected int capacity() {
return capacity;
}

@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) 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
}

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

public class ElementNotFoundException extends RuntimeException {
public ElementNotFoundException() {
}

public ElementNotFoundException(String message) {
super(message);
}

public ElementNotFoundException(String message, Throwable cause) {
super(message, cause);
}

public ElementNotFoundException(Throwable cause) {
super(cause);
}

public ElementNotFoundException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
22 changes: 22 additions & 0 deletions src/me/smartstore/arrays/exception/EmptyArrayException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.smartstore.arrays.exception;

public class EmptyArrayException extends RuntimeException {
public EmptyArrayException() {
}

public EmptyArrayException(String message) {
super(message);
}

public EmptyArrayException(String message, Throwable cause) {
super(message, cause);
}

public EmptyArrayException(Throwable cause) {
super(cause);
}

public EmptyArrayException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
22 changes: 22 additions & 0 deletions src/me/smartstore/arrays/exception/NullArgumentException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.smartstore.arrays.exception;

public class NullArgumentException extends RuntimeException {
public NullArgumentException() {
}

public NullArgumentException(String message) {
super(message);
}

public NullArgumentException(String message, Throwable cause) {
super(message, cause);
}

public NullArgumentException(Throwable cause) {
super(cause);
}

public NullArgumentException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
101 changes: 101 additions & 0 deletions src/me/smartstore/customer/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package me.smartstore.customer;

import me.smartstore.group.Group;

import java.util.Objects;

public class Customer implements Comparable<Customer> {
private String customerName;
private String customerId;
private Integer totalTime;
private Integer totalPay;
private Group group; // 현재 분류 기준에 의해 각 고객을 분류된 결과

public Group getGroup() {
return group;
}

public void setGroup(Group group) {
this.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 totalTime, Integer totalPay) {
this.customerName = customerName;
this.customerId = customerId;
this.totalTime = totalTime;
this.totalPay = totalPay;
}

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 getTotalTime() {
return totalTime;
}

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

public Integer getTotalPay() {
return totalPay;
}

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

@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(customerId, customer.customerId);
}

@Override
public int hashCode() {
return Objects.hash(customerId);
}

@Override
public String toString() {
return "Customer{" +
"userId='" + customerId + '\'' +
", name='" + customerName + '\'' +
", spentTime=" + totalTime +
", totalPay=" + totalPay +
group.toStringForCustomer() + '}';
}
@Override
public int compareTo(Customer o) {
return 0;
}


}
Loading