Skip to content
Open
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/KDTBE5_Java_Assignment3.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions day05assignment/day05assignment.iml
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>
101 changes: 101 additions & 0 deletions day05assignment/src/me/day05/practice/practice01/Electronic.java
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static 변수를 가장 상위에 위치하도록 해주셨네요. 아주 굿!

private String productNo;
private String modelName;
private Company companyName;
private String dateOfDate;
private AuthMethod[] authMethod;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사소한 부분이지만, 배열의 형태이니 복수형을 의미하는 변수로 변경해 보는 건 어떨까요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수 이름도 신경쓰면서 작업해봐야겠네요. 감사합니다!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private AuthMethod[] authMethod;
private AuthMethod[] authMethods;


public Electronic(String productNo,
String modelName,
Company companyName,
String dateOfDate
) {
this.productNo = this.generateProductNo();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수로 분리하는 센스! 너무 좋습니다.

this.modelName = modelName;
this.companyName = companyName;
this.dateOfDate = dateOfDate;
this.authMethod = new AuthMethod[10];
}

private String generateProductNo() {
String id = String.format("%04d", ++autoIncrementNumber);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정규식 사용으로 코드가 한결 간단해 졌어요 아주 잘하셨습니다! 👍

String generatedDate = LocalDate.now().toString().replace("-", "").substring(2);
return generatedDate + id;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로직과 return 부분은 분리를 해주는 게 좋아요! 한 줄 띄어보는 건 어떨까요?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그리고 한 가지 추가로 말씀드리면, String 연산에서 + 는 성능 측면에서 불리해요! 더 좋은 연산이 있을 거예요! 한번 찾아볼까요?

}

public String getProductNo() {
return productNo;
}

public String getModelName() {
return modelName;
}

public void setModelName(String modelName) {
this.modelName = modelName;
}

public Company getCompanyName() {
return companyName;
}

public void setCompanyName(Company companyName) {
this.companyName = companyName;
}

public String getDateOfDate() {
return dateOfDate;
}

public void setDateOfDate(String dateOfDate) {
this.dateOfDate = dateOfDate;
}

public AuthMethod[] getAuthMethod() {
return authMethod;
}
public void setAuthMethod(AuthMethod[] authMethod) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한 줄 띄어쓰기~

this.authMethod = authMethod;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || this.getClass() != obj.getClass()) return false;

Electronic that = (Electronic) obj;
return Objects.equals(this.productNo, that.productNo); // Unique한 id 값을 가지고 있기 때문에 이렇게 작성

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

커스터 마이징하게 작업하신 거 잘하셨어요! 그런데, IDE의 자동 완성 기능을 활용하여 만들어진 equals() 보다는 조금미흡해 보입니다. 이런 경우에는 자동 완성 기능을 이용하는 게 더 나아보여요:)

}

@Override
public int hashCode() {
return Objects.hash(productNo,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hashCode()도 마찬가지로, 자동 완성 기능으로 만들어진 코드보다 덜 정교하네요! 어떤 걸 써야 더 정확할지 한번 고민해 보시죠!

modelName,
companyName,
dateOfDate
);
}

@Override
public String toString() {
return "Electronic{" +
"productNo='" + productNo + "'" +
", modelName='" + modelName + "'" +
", companyName=" + companyName +
", dateOfDate='" + dateOfDate + "'" +
", authMethod=" + Arrays.toString(authMethod) +
'}';
}
}
128 changes: 128 additions & 0 deletions day05assignment/src/me/day05/practice/practice01/User.java
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋아요:) 센스 있습니다.


public User() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기본 생성자를 이용할 거라면 다른 멤버 필드들도 기본 값을 지정해 주는 게 더 좋을 것 같습니다.

this.electronicDevices = new Electronic[10];
this.registerTime = LocalDateTime.now();
}
public User(String userId,
String userPassword,
String userPhoneNumber,
String userEmail,
String userBirthDate
) {
this();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굳이 기본 생성자를 이용할 필요가 있을까요~?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

접힌거 못 보면 후회할뻔했습니다. 사소한 건데 알려주셔서 감사합니다!

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

Choose a reason for hiding this comment

The 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;
}
80 changes: 80 additions & 0 deletions day05assignment/src/me/day05/practice/practice02/Users.java
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 필드는 조금 더 위로 올라가야 할 것 같아요! static 변수는 일반 변수보다 위에 위치시키는 것이 일반적이랍니다.


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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

너무 너무 잘해주셨는데, 우리 트렌드에 맞게 stream을 한번 활용해 보는 건 어떨까요?

if (user.getUserId().equals(userId)) {
return user;
}
}
throw new IllegalArgumentException("찾는 " + userId + "는 존재하지 않습니다.");

Choose a reason for hiding this comment

The 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++) {

Choose a reason for hiding this comment

The 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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자동 완성 기능을 한번 이용해 봅시다!

}

@Override
public String toString() {
return "Users{" +
"userList=" + Arrays.toString(userList) +
'}';
}
}
Loading