Skip to content

[1차 VER1.0...] Java ToyProject upload by HeehyunKim #39

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
8 changes: 8 additions & 0 deletions me.smartstore/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class Main {
public static void main(String[] args) {

SmartStoreApplication.getInstance().test().run();
//SmartStoreApplication.getInstance().run();

}
}
52 changes: 52 additions & 0 deletions me.smartstore/src/SmartStoreApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import customers.Customer;
import customers.Customers;
import groups.*;
import menu.*;

public class SmartStoreApplication {

private static SmartStoreApplication smartStoreApp;

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

private final Groups allGroups = Groups.getInstance();
private final Customers allCustomers = Customers.getInstance();
private final MainMenu mainMenu = MainMenu.getInstance();


public SmartStoreApplication test() {
allGroups.add(new Group( GroupType.GENERAL, new Parameter(10, 100000)) );
allGroups.add(new Group( GroupType.VIP, new Parameter(20, 200000)) );
allGroups.add(new Group( GroupType.VVIP, new Parameter(30, 300000)) );

for (int i = 0; i < 20; ++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));
}

allCustomers.refresh(allGroups);
return this;
}

private void details() {
System.out.println("\n===========================================");
System.out.println(" Title : SmartStore Customer Segmentation");
System.out.println(" Refer to EunBinChoi's GitHub.");
System.out.println("===========================================\n");
}

public void run() {
details();

mainMenu.manage();
}
}
48 changes: 48 additions & 0 deletions me.smartstore/src/customers/ClassifiedCustomers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package customers;

import groups.Group;

import java.util.Arrays;
import java.util.Objects;

public class ClassifiedCustomers extends Customers {
private Group group;

public ClassifiedCustomers() {}

public ClassifiedCustomers(Group group) {
this.group = group;
}


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;}
ClassifiedCustomers that = (ClassifiedCustomers) o;
return Objects.equals(group, that.group);
}

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

@Override
public String toString() {
return "ClassifiedCustomers{" +
"group=" + group +
", size=" + size +
", customers=" + Arrays.toString(customers) +
'}';
}
}
106 changes: 106 additions & 0 deletions me.smartstore/src/customers/ClassifiedCustomersGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package customers;

import groups.GroupType;
import groups.Parameter;
import util.Message;

import java.util.Arrays;
import java.util.Comparator;

public class ClassifiedCustomersGroup {

private static ClassifiedCustomersGroup classifiedCustomersGroup;

public static ClassifiedCustomersGroup getInstance() {
if (classifiedCustomersGroup == null) {
classifiedCustomersGroup = new ClassifiedCustomersGroup();
}
return classifiedCustomersGroup;
}

private ClassifiedCustomers[] classifiedCustomers;

public ClassifiedCustomersGroup() {
classifiedCustomers = new ClassifiedCustomers[GroupType.size()];

for (int i = 0; i < GroupType.size(); i++) {
classifiedCustomers[i] = new ClassifiedCustomers();
}
}


public ClassifiedCustomers get(int i) {
return classifiedCustomers[i];
}

public void set(int i, ClassifiedCustomers customers) {
classifiedCustomers[i] = customers;
}

public int size() {
return GroupType.size();
}

public void print() {
for (int i = 0; i < classifiedCustomers.length; i++) {
System.out.println("\n==============================");

if (classifiedCustomers[i] == null) return;

GroupType groupType = classifiedCustomers[i].getGroup().getType();
Parameter parameter = classifiedCustomers[i].getGroup().getParam();

System.out.printf("Group : %s ( Time : %d, Pay : %d )\n",
groupType,
parameter != null ? parameter.getMinimumSpentTime() : null,
parameter != null ? parameter.getMinimumTotalPay() : null);
System.out.println("==============================");

if (classifiedCustomers[i] == null || classifiedCustomers[i].isEmpty()) {
System.out.println("Null.");
continue;
}
classifiedCustomers[i].print();
System.out.println("==============================\n");
}

}

public void sort(Comparator<Customer> comparator) {

for (int i = 0; i < classifiedCustomersGroup.size(); i++) {
Customer[] customers = classifiedCustomersGroup.get(i).getCustomers();

try {
if (comparator == null) {Arrays.sort(customers);}
else {Arrays.sort(customers, comparator);}

classifiedCustomersGroup.get(i).setCustomers(customers);
}
catch (NullPointerException e) {
System.out.println(Message.ERR_MSG_NULL_ARR_ELEMENT);
}
}
}

@Override
public boolean equals(Object o) {
if (this == o) {return true;}
if (o == null || getClass() != o.getClass()) {return false;}
ClassifiedCustomersGroup that = (ClassifiedCustomersGroup) o;
return Arrays.equals(classifiedCustomers, that.classifiedCustomers);
}

@Override
public int hashCode() {
return Arrays.hashCode(classifiedCustomers);
}

@Override
public String toString() {
return "ClassifiedCustomersGroup{" +
"classifiedCustomers=" +
Arrays.toString(classifiedCustomers) +
'}';
}
}
96 changes: 96 additions & 0 deletions me.smartstore/src/customers/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package customers;

import groups.Group;

import java.util.Objects;

public class Customer implements Comparable<Customer> {

private String userId;
private String name;
private Integer spentTime;
private Integer totalPay;
private Group group;

public Customer() {
}

public Customer(String name, String userId, int spentTime, int totalPay) {
this.name = name;
this.userId = userId;
this.spentTime = spentTime;
this.totalPay = totalPay;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}

public Integer getSpentTime() {
return spentTime;
}

public void setSpentTime(Integer spentTime) {
this.spentTime = spentTime;
}

public Integer getTotalPay() {
return totalPay;
}

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

public Group getGroup() {
return group;
}

public void setGroup(Group group) {
this.group = group;
}

@Override
public int compareTo(Customer o) {
if (name.compareTo(o.name) < 0) {return -1;}
else if (name.compareTo(o.name) == 0) {return userId.compareTo(o.userId);}
else return 1;

}

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

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

@Override
public String toString() {
return "Customer{" +
"userId='" + userId + '\'' +
", name='" + name + '\'' +
", spentTime=" + spentTime +
", totalPay=" + totalPay +
", group=" + group +
'}';
}
}
Loading