Skip to content

[1차 VER1.0...] Java ToyProject upload by SeongminLee #41

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
7 changes: 7 additions & 0 deletions 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) {
SmartStoreApplication.getInstance().test().run();
}
}
81 changes: 81 additions & 0 deletions me/smartstore/SmartStoreApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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.CustomerMenu;
import me.smartstore.menu.GroupMenu;
import me.smartstore.menu.Menu;
import me.smartstore.menu.SummarizedMenu;

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 Menu menu = Menu.getInstance();
private final CustomerMenu customerMenu = CustomerMenu.getInstance();
private final GroupMenu groupMenu = GroupMenu.getInstance();
private final SummarizedMenu classifiedMenu = SummarizedMenu.getInstance();

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

for (int i = 0; i < 20; i++) {
allCustomers.add(new Customer(
Character.toString((char) (97 + i)),
"" + (char) (97 + i) + "123",
((int) (Math.random() * 5.0D) + 1) * 10,
((int) (Math.random() * 5.0D) + 1) * 100000));
}
allCustomers.refresh(allGroups);

return this;
}

private void details() {
System.out.println("\n\n===========================================");
System.out.println(" 스마트스토어_구조화");
System.out.println(" @MebukiYamashi/Fastcampus_1st_ToyProject");
System.out.println("===========================================\n");
}

public void run() {
details();

while (true) {
int choice = menu.displayMenus(new String[]{"매개변수 설정", "고객 데이터 관리", "데이터 분류/요약", "종료"});

if (choice == 1) {
groupMenu.manageParameterMenu();
continue;
}

if (choice == 2) {
customerMenu.manageCustomerMenu();
continue;
}

if (choice == 3) {
classifiedMenu.manageSummaryMenu();
continue;
}

if (choice == 4) {
System.out.println("\n프로그램을 종료합니다.");
return;
}
}
}
}
48 changes: 48 additions & 0 deletions me/smartstore/customers/ClassifiedCustomers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package me.smartstore.customers;

import java.util.Arrays;
import java.util.Objects;
import me.smartstore.groups.Group;

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

import java.util.Arrays;
import java.util.Comparator;
import me.smartstore.groups.GroupType;
import me.smartstore.groups.Parameter;

public class ClassifiedCustomersGroup {
private static ClassifiedCustomersGroup classifiedCustomersGroup;

private ClassifiedCustomers[] classifiedCustomers;

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

public ClassifiedCustomersGroup() {
this.classifiedCustomers = new ClassifiedCustomers[GroupType.size()];
for (int i = 0; i < GroupType.size(); i++)
this.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("그룹: %s (시간: %d, 금액: %d)\n", groupType,
(parameter != null) ? parameter.getMinimumSpentTime() : null,
(parameter != null) ? parameter.getMinimumTotalPay() : null);
System.out.println("==============================");
if (classifiedCustomers[i].isEmpty()) {
System.out.println("빈 값");
} else {
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("빈 배열은 정렬할 수 없습니다.");
}
}
}

@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/customers/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package me.smartstore.customers;

import java.util.Objects;
import me.smartstore.groups.Group;

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) {
int nameComparison = this.name.compareTo(o.name);
if (nameComparison != 0)
return nameComparison;
return this.userId.compareTo(o.userId);
}

@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