-
Notifications
You must be signed in to change notification settings - Fork 0
Java Assignment3 upload by HoonSubKim #12
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
d8d99ab
98ba72c
fca92c3
3072627
68edb16
47183dc
9c64793
8e92789
b7334ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,101 @@ | ||||||
package me.day05.practice.practice01; | ||||||
|
||||||
import me.day05.practice.practice01.constant.AuthMethod; | ||||||
import me.day05.practice.practice01.constant.Company; | ||||||
|
||||||
import java.time.LocalDate; | ||||||
import java.util.ArrayList; | ||||||
import java.util.Arrays; | ||||||
import java.util.List; | ||||||
import java.util.Objects; | ||||||
|
||||||
public class Electronic { | ||||||
private static int autoIncrementNumber = 0; | ||||||
private String productNo; | ||||||
private String modelName; | ||||||
private Company companyName; | ||||||
private String dateOfDate; | ||||||
private AuthMethod[] authMethod; | ||||||
|
private AuthMethod[] authMethod; | |
private AuthMethod[] authMethods; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
함수로 분리하는 센스! 너무 좋습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정규식 사용으로 코드가 한결 간단해 졌어요 아주 잘하셨습니다! 👍
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
로직과 return 부분은 분리를 해주는 게 좋아요! 한 줄 띄어보는 건 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그리고 한 가지 추가로 말씀드리면, String 연산에서 + 는 성능 측면에서 불리해요! 더 좋은 연산이 있을 거예요! 한번 찾아볼까요?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
한 줄 띄어쓰기~
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
커스터 마이징하게 작업하신 거 잘하셨어요! 그런데, IDE의 자동 완성 기능을 활용하여 만들어진 equals() 보다는 조금미흡해 보입니다. 이런 경우에는 자동 완성 기능을 이용하는 게 더 나아보여요:)
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hashCode()도 마찬가지로, 자동 완성 기능으로 만들어진 코드보다 덜 정교하네요! 어떤 걸 써야 더 정확할지 한번 고민해 보시죠!
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package me.day05.practice.practice01; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
public class User { | ||
private String userId; | ||
private String userPassword; | ||
private String userPhoneNumber; | ||
private String userEmail; | ||
private String userBirthDate; | ||
private Electronic[] electronicDevices; | ||
private LocalDateTime registerTime; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋아요:) 센스 있습니다. |
||
|
||
public User() { | ||
|
||
this.electronicDevices = new Electronic[10]; | ||
this.registerTime = LocalDateTime.now(); | ||
} | ||
public User(String userId, | ||
String userPassword, | ||
String userPhoneNumber, | ||
String userEmail, | ||
String userBirthDate | ||
) { | ||
this(); | ||
|
||
this.userId = userId; | ||
this.userPassword = userPassword; | ||
this.userPhoneNumber = userPhoneNumber; | ||
this.userEmail = userEmail; | ||
this.userBirthDate = userBirthDate; | ||
} | ||
|
||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
public void setUserId(String userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public String getUserPassword() { | ||
return userPassword; | ||
} | ||
|
||
public void setUserPassword(String userPassword) { | ||
this.userPassword = userPassword; | ||
} | ||
|
||
public String getUserPhoneNumber() { | ||
return userPhoneNumber; | ||
} | ||
|
||
public void setUserPhoneNumber(String userPhoneNumber) { | ||
this.userPhoneNumber = userPhoneNumber; | ||
} | ||
|
||
public String getUserEmail() { | ||
return userEmail; | ||
} | ||
|
||
public void setUserEmail(String userEmail) { | ||
this.userEmail = userEmail; | ||
} | ||
|
||
public String getUserBirthDate() { | ||
return userBirthDate; | ||
} | ||
|
||
public void setUserBirthDate(String userBirthDate) { | ||
this.userBirthDate = userBirthDate; | ||
} | ||
|
||
public LocalDateTime getRegisterTime() { | ||
return registerTime; | ||
} | ||
|
||
public void setRegisterTime(LocalDateTime registerTime) { | ||
this.registerTime = registerTime; | ||
} | ||
|
||
public Electronic[] getElectronicDevices() { | ||
return electronicDevices; | ||
} | ||
|
||
public void setElectronicDevices(Electronic[] electronicDevices) { | ||
this.electronicDevices = electronicDevices; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (obj == null || this.getClass() != obj.getClass()) return false; | ||
|
||
User user = (User) obj; | ||
|
||
if (!Objects.equals(userId, user.userId)) return false; | ||
if (!Objects.equals(userPassword, user.userPassword)) return false; | ||
if (!Objects.equals(userPhoneNumber, user.userPhoneNumber)) return false; | ||
if (!Objects.equals(userEmail, user.userEmail)) return false; | ||
if (!Objects.equals(userBirthDate, user.userBirthDate)) return false; | ||
return Objects.equals(registerTime, user.registerTime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요 부분은 그래도 잘하셨네요! 그런데 이렇게 작성을 하게 되면 놓치는 부분이 생길 수도 있을 것 같아요! 물론 훈섭님은 꼼꼼하시니까 놓치지 않겠지만! 혹시 모르는 일이니까요~ㅎㅎ |
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(userId, | ||
userPassword, | ||
userPhoneNumber, | ||
userEmail, | ||
userBirthDate, | ||
registerTime | ||
); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "User{" + | ||
"userId='" + userId + "'" + | ||
", userPassword='" + userPassword + "'" + | ||
", userPhoneNumber='" + userPhoneNumber + "'" + | ||
", userEmail='" + userEmail + "'" + | ||
", userBirthDate='" + userBirthDate + "'" + | ||
", electronicDevices=" + Arrays.toString(electronicDevices) + | ||
", registerTime=" + registerTime + | ||
'}'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package me.day05.practice.practice01.constant; | ||
|
||
public enum AuthMethod { | ||
FINGER_PRINT, PATTERN, PIN, FACE; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package me.day05.practice.practice01.constant; | ||
|
||
public enum Company { | ||
SAMSUNG, LG, APPLE; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package me.day05.practice.practice02; | ||
|
||
import me.day05.practice.practice01.User; | ||
|
||
import java.util.Arrays; | ||
|
||
public class Users { | ||
private static Users instance; | ||
private User[] userList; | ||
private static final int DEFAULT_SIZE = 50; | ||
|
||
|
||
private Users() { | ||
userList = new User[DEFAULT_SIZE]; | ||
} | ||
|
||
public static Users getInstance() { | ||
if (instance == null) { | ||
instance = new Users(); | ||
} | ||
return instance; | ||
} | ||
|
||
public User[] getUserList() { | ||
return userList; | ||
} | ||
|
||
public void setUserList(User[] userList) { | ||
this.userList = userList; | ||
} | ||
|
||
public User findByUserId(String userId) { | ||
for (User user : userList) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 너무 너무 잘해주셨는데, 우리 트렌드에 맞게 stream을 한번 활용해 보는 건 어떨까요? |
||
if (user.getUserId().equals(userId)) { | ||
return user; | ||
} | ||
} | ||
throw new IllegalArgumentException("찾는 " + userId + "는 존재하지 않습니다."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이런 예외 처리 좋습니다 잘하셨어요 👍 |
||
} | ||
|
||
public static User copy(User original) { | ||
User user = new User( | ||
original.getUserId(), | ||
original.getUserPassword(), | ||
original.getUserPhoneNumber(), | ||
original.getUserEmail(), | ||
original.getUserBirthDate() | ||
); | ||
user.setElectronicDevices(original.getElectronicDevices().clone()); | ||
user.setRegisterTime(original.getRegisterTime()); | ||
return user; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (obj == null || getClass() != obj.getClass()) return false; | ||
|
||
Users users = (Users) obj; | ||
|
||
if (userList.length != users.userList.length) return false; | ||
for (int i = 0; i < users.userList.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 고민의 흔적이 보이네요. 리스트까지 비교하는 세심함! 좋아요 |
||
if (!userList[i].equals(users.userList[i])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.hashCode(userList); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 자동 완성 기능을 한번 이용해 봅시다! |
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Users{" + | ||
"userList=" + Arrays.toString(userList) + | ||
'}'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
변수를 가장 상위에 위치하도록 해주셨네요. 아주 굿!