Skip to content

[1차 VER1.0] Java ToyProject upload by JinaKim upload #34

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
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
Binary file added Main.class
Binary file not shown.
19 changes: 19 additions & 0 deletions Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package me.smartstore;

public class Main {
public static void main(String[] args) {
// SmartStoreApp.getInstance().test().run(); // function chaining
// // SmartStoreApp.getInstance().run();
Customer customerLee = new Customer();
customerLee.setCustomerName("이순신");
customerLee.setCustomerID(10010);
customerLee.bonusPoint = 1000;
System.out.println(customerLee.showCustomerInfo());

VIPCustomer customerKim = new VIPCustomer();
customerKim.setCustomerName("김유신");
customerKim.setCustomerID(10020);
customerKim.bonusPoint = 10000;
System.out.println(customerKim.showCustomerInfo());
}
}
66 changes: 66 additions & 0 deletions SmartStoreApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package me.smartstore;
import me.smartstore.customers.Customer;
import me.smartstore.customers.Customers;
import me.smartstore.groups.Group;
import me.smartstore.groups.GroupType;
import me.smartstore.groups.Groups;
import me.smartstore.groups.Parameter;
import me.smartstore.menu.*;

public class SmartStoreApp {
private final Groups allGroups = Groups.getInstance();
private final Customers allCustomers = Customers.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.04.27");
System.out.println(" Copyright 2023 Eunbin All rights reserved.");
System.out.println("===========================================\n");
}

/**
* @return
*/
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));
}

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

// @TODO: refresh do not implemented yet.
allCustomers.refresh(allGroups);

return this; // smartStoreApp
}

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

}
}
Binary file added SmartStoreApplication.class
Binary file not shown.
14 changes: 14 additions & 0 deletions 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);
}
163 changes: 163 additions & 0 deletions arrays/DArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package me.smartstore.arrays;

import me.smartstore.exception.ElementNotFoundException;
import me.smartstore.exception.NullArgumentException;
import java.util.EmptyStackException;

public class DArray<T> implements Collections<T> {

protected static final int DEFAULT = 10;

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

public static int getDefault() {
return DEFAULT;
}

public T[] getArrays() {
return arrays;
}

public void setArrays(T[] arrays) {
this.arrays = arrays;
}

public int getSize() {
return size;
}

public void setSize(int size) {
this.size = size;
}

public int getCapacity() {
return capacity;
}

public void setCapacity(int capacity) {
this.capacity = 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();

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, NullPointerException {
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 EmptyStackException();
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;
}

}
Binary file added customers/ClassifiedCustomers.class
Binary file not shown.
Binary file added customers/ClassifiedCustomersGroup.class
Binary file not shown.
Binary file added customers/Customer.class
Binary file not shown.
90 changes: 90 additions & 0 deletions customers/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package me.smartstore.customers;

import java.util.Objects;

public class Customer {

private String cusName;
private String cusId;
private Integer cusTotalTime;
private Integer cusTotalPay;
public Customer() {}

public Customer(String cusId) {
this.cusId = cusId;
}

public Customer(String cusName, String cusId) {
this.cusName = cusName;
this.cusId = cusId;
}

/**
* @param string
* @param cusId
* @param cusTotalTime
* @param cusTotalPay
*/
public Customer(String string, String cusId, Integer cusTotalTime, Integer cusTotalPay) {
this.cusName = string;
this.cusId = cusId;
this.cusTotalTime = cusTotalTime;
this.cusTotalPay = cusTotalPay;
}

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

@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 +
'}';
}

}
Binary file added customers/Customers.class
Binary file not shown.
27 changes: 27 additions & 0 deletions customers/Customers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.smartstore.customers;

import me.smartstore.arrays.DArray;
import me.smartstore.groups.Groups;

public class Customers extends DArray<Customer> {

//singleton
private static Customers allCustomers;

public static Customers getInstance() {
if(allCustomers == null) {
allCustomers = new Customers();
}
return allCustomers;
}

private Customers() {}

//refresh 함수가 호출되는 경우
//1.분류기준 바뀔때
//2.새로운 고객이 들어올 때
public void refresh(Groups groups) {

}

}
Binary file added exception/ArrayEmptyException.class
Binary file not shown.
Loading