Skip to content

Commit d8d99ab

Browse files
committed
Java Assignment3 upload by HoonSubKim
1 parent ca7f7c8 commit d8d99ab

File tree

18 files changed

+477
-0
lines changed

18 files changed

+477
-0
lines changed

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/KDTBE5_Java_Assignment3.iml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/discord.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

day05assignment/day05assignment.iml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package me.day05.practice.practice01;
2+
3+
import me.day05.practice.practice01.constant.AuthMethod;
4+
import me.day05.practice.practice01.constant.Company;
5+
6+
import java.time.LocalDate;
7+
import java.util.ArrayList;
8+
import java.util.Arrays;
9+
import java.util.List;
10+
import java.util.Objects;
11+
12+
public class Electronic {
13+
private static int autoIncrementNumber = 0;
14+
private String productNo;
15+
private String modelName;
16+
private Company companyName;
17+
private String dateOfDate;
18+
private AuthMethod[] authMethod;
19+
20+
public Electronic(String productNo,
21+
String modelName,
22+
Company companyName,
23+
String dateOfDate
24+
) {
25+
this.productNo = this.generateProductNo();
26+
this.modelName = modelName;
27+
this.companyName = companyName;
28+
this.dateOfDate = dateOfDate;
29+
this.authMethod = new AuthMethod[10];
30+
}
31+
32+
private String generateProductNo() {
33+
String id = String.format("%04d", ++autoIncrementNumber);
34+
String generatedDate = LocalDate.now().toString().replace("-", "").substring(2);
35+
return generatedDate + id;
36+
}
37+
38+
public String getProductNo() {
39+
return productNo;
40+
}
41+
42+
public String getModelName() {
43+
return modelName;
44+
}
45+
46+
public void setModelName(String modelName) {
47+
this.modelName = modelName;
48+
}
49+
50+
public Company getCompanyName() {
51+
return companyName;
52+
}
53+
54+
public void setCompanyName(Company companyName) {
55+
this.companyName = companyName;
56+
}
57+
58+
public String getDateOfDate() {
59+
return dateOfDate;
60+
}
61+
62+
public void setDateOfDate(String dateOfDate) {
63+
this.dateOfDate = dateOfDate;
64+
}
65+
66+
public AuthMethod[] getAuthMethod() {
67+
return authMethod;
68+
}
69+
public void setAuthMethod(AuthMethod[] authMethod) {
70+
this.authMethod = authMethod;
71+
}
72+
73+
@Override
74+
public boolean equals(Object obj) {
75+
if (this == obj) return true;
76+
if (obj == null || this.getClass() != obj.getClass()) return false;
77+
78+
Electronic that = (Electronic) obj;
79+
return Objects.equals(this.productNo, that.productNo); // Unique한 id 값을 가지고 있기 때문에 이렇게 작성
80+
}
81+
82+
@Override
83+
public int hashCode() {
84+
return Objects.hash(productNo,
85+
modelName,
86+
companyName,
87+
dateOfDate
88+
);
89+
}
90+
91+
@Override
92+
public String toString() {
93+
return "Electronic{" +
94+
"productNo='" + productNo + "'" +
95+
", modelName='" + modelName + "'" +
96+
", companyName=" + companyName +
97+
", dateOfDate='" + dateOfDate + "'" +
98+
", authMethod=" + Arrays.toString(authMethod) +
99+
'}';
100+
}
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package me.day05.practice.practice01;
2+
3+
import java.time.LocalDateTime;
4+
import java.util.Arrays;
5+
import java.util.Objects;
6+
7+
public class User {
8+
private String userId;
9+
private String userPassword;
10+
private String userPhoneNumber;
11+
private String userEmail;
12+
private String userBirthDate;
13+
private Electronic[] electronicDevices;
14+
private LocalDateTime registerTime;
15+
16+
public User() {
17+
this.electronicDevices = new Electronic[10];
18+
this.registerTime = LocalDateTime.now();
19+
}
20+
public User(String userId,
21+
String userPassword,
22+
String userPhoneNumber,
23+
String userEmail,
24+
String userBirthDate
25+
) {
26+
this();
27+
this.userId = userId;
28+
this.userPassword = userPassword;
29+
this.userPhoneNumber = userPhoneNumber;
30+
this.userEmail = userEmail;
31+
this.userBirthDate = userBirthDate;
32+
}
33+
34+
public String getUserId() {
35+
return userId;
36+
}
37+
38+
public void setUserId(String userId) {
39+
this.userId = userId;
40+
}
41+
42+
public String getUserPassword() {
43+
return userPassword;
44+
}
45+
46+
public void setUserPassword(String userPassword) {
47+
this.userPassword = userPassword;
48+
}
49+
50+
public String getUserPhoneNumber() {
51+
return userPhoneNumber;
52+
}
53+
54+
public void setUserPhoneNumber(String userPhoneNumber) {
55+
this.userPhoneNumber = userPhoneNumber;
56+
}
57+
58+
public String getUserEmail() {
59+
return userEmail;
60+
}
61+
62+
public void setUserEmail(String userEmail) {
63+
this.userEmail = userEmail;
64+
}
65+
66+
public String getUserBirthDate() {
67+
return userBirthDate;
68+
}
69+
70+
public void setUserBirthDate(String userBirthDate) {
71+
this.userBirthDate = userBirthDate;
72+
}
73+
74+
public LocalDateTime getRegisterTime() {
75+
return registerTime;
76+
}
77+
78+
public void setRegisterTime(LocalDateTime registerTime) {
79+
this.registerTime = registerTime;
80+
}
81+
82+
public Electronic[] getElectronicDevices() {
83+
return electronicDevices;
84+
}
85+
86+
public void setElectronicDevices(Electronic[] electronicDevices) {
87+
this.electronicDevices = electronicDevices;
88+
}
89+
90+
@Override
91+
public boolean equals(Object obj) {
92+
if (this == obj) return true;
93+
if (obj == null || this.getClass() != obj.getClass()) return false;
94+
95+
User user = (User) obj;
96+
97+
if (!Objects.equals(userId, user.userId)) return false;
98+
if (!Objects.equals(userPassword, user.userPassword)) return false;
99+
if (!Objects.equals(userPhoneNumber, user.userPhoneNumber)) return false;
100+
if (!Objects.equals(userEmail, user.userEmail)) return false;
101+
if (!Objects.equals(userBirthDate, user.userBirthDate)) return false;
102+
return Objects.equals(registerTime, user.registerTime);
103+
}
104+
105+
@Override
106+
public int hashCode() {
107+
return Objects.hash(userId,
108+
userPassword,
109+
userPhoneNumber,
110+
userEmail,
111+
userBirthDate,
112+
registerTime
113+
);
114+
}
115+
116+
@Override
117+
public String toString() {
118+
return "User{" +
119+
"userId='" + userId + "'" +
120+
", userPassword='" + userPassword + "'" +
121+
", userPhoneNumber='" + userPhoneNumber + "'" +
122+
", userEmail='" + userEmail + "'" +
123+
", userBirthDate='" + userBirthDate + "'" +
124+
", electronicDevices=" + Arrays.toString(electronicDevices) +
125+
", registerTime=" + registerTime +
126+
'}';
127+
}
128+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package me.day05.practice.practice01.constant;
2+
3+
public enum AuthMethod {
4+
FINGER_PRINT, PATTERN, PIN, FACE;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package me.day05.practice.practice01.constant;
2+
3+
public enum Company {
4+
SAMSUNG, LG, APPLE;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package me.day05.practice.practice02;
2+
3+
import me.day05.practice.practice01.User;
4+
5+
import java.util.Arrays;
6+
7+
public class Users {
8+
private static Users instance;
9+
private User[] userList;
10+
private static final int DEFAULT_SIZE = 50;
11+
12+
private Users() {
13+
userList = new User[DEFAULT_SIZE];
14+
}
15+
16+
public static Users getInstance() {
17+
if (instance == null) {
18+
instance = new Users();
19+
}
20+
return instance;
21+
}
22+
23+
public User[] getUserList() {
24+
return userList;
25+
}
26+
27+
public void setUserList(User[] userList) {
28+
this.userList = userList;
29+
}
30+
31+
public User findByUserId(String userId) {
32+
for (User user : userList) {
33+
if (user.getUserId().equals(userId)) {
34+
return user;
35+
}
36+
}
37+
throw new IllegalArgumentException("찾는 " + userId + "는 존재하지 않습니다.");
38+
}
39+
40+
public static User copy(User original) {
41+
User user = new User(
42+
original.getUserId(),
43+
original.getUserPassword(),
44+
original.getUserPhoneNumber(),
45+
original.getUserEmail(),
46+
original.getUserBirthDate()
47+
);
48+
user.setElectronicDevices(original.getElectronicDevices().clone());
49+
user.setRegisterTime(original.getRegisterTime());
50+
return user;
51+
}
52+
53+
@Override
54+
public boolean equals(Object obj) {
55+
if (this == obj) return true;
56+
if (obj == null || getClass() != obj.getClass()) return false;
57+
58+
Users users = (Users) obj;
59+
60+
if (userList.length != users.userList.length) return false;
61+
for (int i = 0; i < users.userList.length; i++) {
62+
if (!userList[i].equals(users.userList[i])) {
63+
return false;
64+
}
65+
}
66+
return true;
67+
}
68+
69+
@Override
70+
public int hashCode() {
71+
return Arrays.hashCode(userList);
72+
}
73+
74+
@Override
75+
public String toString() {
76+
return "Users{" +
77+
"userList=" + Arrays.toString(userList) +
78+
'}';
79+
}
80+
}

0 commit comments

Comments
 (0)