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

public class SmartStoreApp {

private Groups allGroups;
private Customers allCustomers;
private MainMenu mainMenu;
private static SmartStoreApp smartStoreApp;

public static SmartStoreApp getInstance() {
if (smartStoreApp == null) {
smartStoreApp = new SmartStoreApp();
}
return smartStoreApp;
}

private SmartStoreApp() {
this.allCustomers = Customers.getInstance();
this.allGroups = Groups.getInstance();
this.mainMenu = MainMenu.getInstance();
}

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 GroupConditions(10, 100000), GroupType.GENERAL));
allGroups.add(new Group(new GroupConditions(20, 200000), GroupType.VIP));
allGroups.add(new Group(new GroupConditions(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;
}

public void run() {
details();
mainMenu.manage();
}
}
13 changes: 13 additions & 0 deletions src/me/smartstore/arrays/Collections.java
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);
}
141 changes: 141 additions & 0 deletions src/me/smartstore/arrays/DArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
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;
}

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();

for (int i = 0; i < size; i++) {
if (arrays[i] == null) continue;
if (arrays[i].equals(object)) return i;
}
throw new ElementNotFoundException();
}

@Override
public void add(T object) throws NullArgumentException {
if (object == null) throw new NullArgumentException();

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;
}
}
111 changes: 111 additions & 0 deletions src/me/smartstore/customer/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
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;
cusId = null;
cusName = null;
cusTotalTime = 0;
cusTotalPay = 0;
group = GroupType.NONE;
seqNum++;
}

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();
}
}
Loading