-
Notifications
You must be signed in to change notification settings - Fork 0
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
practice03 #15
base: main
Are you sure you want to change the base?
practice03 #15
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package KDTBE5_Java_Assignment3.me.practice.Practice01; | ||
|
||
public enum AuthMethod { | ||
지문인증, 패턴인증, 핀인증,얼굴인증 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package KDTBE5_Java_Assignment3.me.practice.Practice01; | ||
|
||
public enum Company { | ||
SAMSUNG,LG,APPLE; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package KDTBE5_Java_Assignment3.me.practice.Practice01; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
import static java.time.LocalDate.now; | ||
|
||
public class Electronic { | ||
public static int registerNumber = 0; | ||
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. 오~ 일반 변수보다 |
||
private String productNo; | ||
private Company companyName; | ||
private String modelName; | ||
private String dateOfMade; | ||
private AuthMethod[] authMethod; | ||
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. 사소하지만 배열의 형태이니 authMethods로 변경해 보는 건 어떨까요? |
||
|
||
public Electronic(Company companyName, String modelName, String dateOfMade, AuthMethod[] authMethod) { | ||
this.productNo = setProductNo(); | ||
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. 함수로 빼서 정의하신 부분 너무 칭찬해 드리고 싶습니다! 좋아요 👍 |
||
this.companyName = companyName; | ||
this.modelName = modelName; | ||
this.dateOfMade = dateOfMade; | ||
this.authMethod = authMethod; | ||
} | ||
|
||
private String setProductNo() { | ||
String productNo = now().format(DateTimeFormatter.ofPattern("yyMMdd"))+String.format("%04d",++Electronic.registerNumber); | ||
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. 정규식을 써서 간단하게 표현해 주신 부분 너무 잘하셨습니다! 다만, String 연산에서 + 는 속도 측면에서 좋은 연산은 아니예요! 다른 연산을 한번 찾아보는 건 어떨까요? |
||
return productNo; | ||
} | ||
|
||
|
||
public String getProductNo() { | ||
return productNo; | ||
} | ||
|
||
public void setProductNo(String productNo) { | ||
this.productNo = productNo; | ||
} | ||
|
||
public Company getCompany() { | ||
return companyName; | ||
} | ||
|
||
public void setCompany(Company companyName) { | ||
this.companyName = companyName; | ||
} | ||
|
||
public String getModelName() { | ||
return modelName; | ||
} | ||
|
||
public void setModelName(String modelName) { | ||
this.modelName = modelName; | ||
} | ||
|
||
public String getDateOfMade() { | ||
return dateOfMade; | ||
} | ||
|
||
public void setDateOfMade(String dateOfMade) { | ||
this.dateOfMade = dateOfMade; | ||
} | ||
|
||
public AuthMethod[] getAuthMethod() { | ||
return authMethod; | ||
} | ||
|
||
public void setAuthMethod(AuthMethod[] authMethod) { | ||
this.authMethod = authMethod; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Electronic that = (Electronic) o; | ||
return Objects.equals(productNo, that.productNo) && companyName == that.companyName && Objects.equals(modelName, that.modelName) && Objects.equals(dateOfMade, that.dateOfMade) && Arrays.equals(authMethod, that.authMethod); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hash(productNo, companyName, modelName, dateOfMade); | ||
result = 31 * result + Arrays.hashCode(authMethod); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Electronic{" + | ||
"productNo='" + productNo + '\'' + | ||
", companyName=" + companyName + | ||
", modelName='" + modelName + '\'' + | ||
", dateOfMade='" + dateOfMade + '\'' + | ||
", authMethod=" + Arrays.toString(authMethod) + | ||
'}'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,110 @@ | ||||||
package KDTBE5_Java_Assignment3.me.practice.Practice01; | ||||||
|
||||||
import java.time.chrono.ChronoLocalDateTime; | ||||||
import java.time.format.DateTimeFormatter; | ||||||
import java.util.Arrays; | ||||||
import java.util.Formatter; | ||||||
import java.util.Objects; | ||||||
|
||||||
import static java.time.LocalDateTime.now; | ||||||
|
||||||
public class User { | ||||||
private String userId; | ||||||
private String userPassword; | ||||||
private String userEmail; | ||||||
private String userBirthDate; | ||||||
private Electronic [] electronicDevices; | ||||||
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. 이 부분도 사소하지만, 하나의 Code Convention으로 볼 수도 있는 부분이기 때문에 띄어쓰기를 제거하는 게 좋아보입니다. 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.
Suggested change
|
||||||
private String 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. 이 부분은 String 보다 더 적절한 자료형이 있을 것 같아요! ㅎㅎ 한번 찾아보세요 |
||||||
|
||||||
public User() { | ||||||
|
||||||
} | ||||||
|
||||||
public User(String userId, String userPassword, String userEmail, String userBirthDate, Electronic[] electronicDevices) { | ||||||
this.userId = userId; | ||||||
this.userPassword = userPassword; | ||||||
this.userEmail = userEmail; | ||||||
this.userBirthDate = userBirthDate; | ||||||
this.electronicDevices = electronicDevices; | ||||||
this.registerTime = now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); | ||||||
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. 값을 자동으로 계산해 주는 부분은 너무 잘하셨는데, Time이라는 변수명과 어울리는 자료형을 선택하면 더 좋을 것 같아요~ |
||||||
} | ||||||
// public User(String userId, String userPassword, String userEmail, String userBirthDate, Electronic[] electronicDevices,String registerTime) { | ||||||
// this.userId = userId; | ||||||
// this.userPassword = userPassword; | ||||||
// this.userEmail = userEmail; | ||||||
// this.userBirthDate = userBirthDate; | ||||||
// this.electronicDevices = electronicDevices; | ||||||
// this.registerTime = registerTime; | ||||||
// } | ||||||
|
||||||
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 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 Electronic[] getElectronicDevices() { | ||||||
return electronicDevices; | ||||||
} | ||||||
|
||||||
public void setElectronicDevices(Electronic[] electronicDevices) { | ||||||
this.electronicDevices = electronicDevices; | ||||||
} | ||||||
|
||||||
public String getRegisterTime() { | ||||||
return registerTime; | ||||||
} | ||||||
|
||||||
// @Override | ||||||
// public String toString() { | ||||||
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. 왜 주석 처리했는지 알 수 있을까요~? |
||||||
// return "User{" + | ||||||
// "userId='" + userId + '\'' + | ||||||
// ", userPassword='" + userPassword + '\'' + | ||||||
// ", userEmail='" + userEmail + '\'' + | ||||||
// ", userBirthDate='" + userBirthDate + '\'' + | ||||||
// ", electronicDevices=" + Arrays.toString(electronicDevices) + | ||||||
// ", registerTime='" + registerTime + '\'' + | ||||||
// '}'; | ||||||
// } | ||||||
|
||||||
@Override | ||||||
public boolean equals(Object o) { | ||||||
if (this == o) return true; | ||||||
if (o == null || getClass() != o.getClass()) return false; | ||||||
User user = (User) o; | ||||||
return Objects.equals(userId, user.userId) && Objects.equals(userPassword, user.userPassword) && Objects.equals(userEmail, user.userEmail) && Objects.equals(userBirthDate, user.userBirthDate) && Arrays.equals(electronicDevices, user.electronicDevices) && Objects.equals(registerTime, user.registerTime); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public int hashCode() { | ||||||
int result = Objects.hash(userId, userPassword, userEmail, userBirthDate, registerTime); | ||||||
result = 31 * result + Arrays.hashCode(electronicDevices); | ||||||
return result; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package KDTBE5_Java_Assignment3.me.practice.Practice02; | ||
|
||
import KDTBE5_Java_Assignment3.me.practice.Practice01.User; | ||
|
||
import java.util.Arrays; | ||
|
||
public class Users { | ||
private static final Users INSTANCE = new Users(); | ||
public Users() { | ||
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 Users getINSTANCE() { | ||
return INSTANCE; | ||
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. 이것도 하나의 방법이 될 수 있는데, 보통 싱글톤 패턴을 사용할 때 null 인지 체크하고 null 이라면 인스턴스를 생성하여 반환하는 것이 일반적입니다 😃 |
||
} | ||
|
||
private User[] users; | ||
|
||
|
||
public User[] getUsers() { | ||
return users; | ||
} | ||
|
||
public void setUsers(User[] users) { | ||
this.users = users; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Users users1 = (Users) o; | ||
return Arrays.equals(users, users1.users); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.hashCode(users); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Users{" + | ||
"users=" + Arrays.toString(users) + | ||
'}'; | ||
} | ||
|
||
public User findUserId(String userId) throws Exception { | ||
for (User user: this.users) { | ||
if(user.getUserId().equals(userId))return user; | ||
} | ||
throw new Exception("해당 유저 아이디를 가진 유저는 존재하지 않습니다."); | ||
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 copy(User user){ | ||
User clone = new User(); | ||
String userId = new String(user.getUserId()); | ||
clone.setUserId(userId); | ||
clone.setUserPassword(user.getUserPassword()); | ||
clone.setUserEmail(user.getUserEmail()); | ||
clone.setUserBirthDate(user.getUserBirthDate()); | ||
clone.setElectronicDevices(user.getElectronicDevices()); | ||
return clone; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package KDTBE5_Java_Assignment3.me.practice.Practice03; | ||
|
||
import KDTBE5_Java_Assignment3.me.practice.Practice01.AuthMethod; | ||
import KDTBE5_Java_Assignment3.me.practice.Practice01.Company; | ||
import KDTBE5_Java_Assignment3.me.practice.Practice01.Electronic; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class Electronics { | ||
private static final Electronics INSTANCE = new Electronics(); | ||
|
||
public Electronics() { | ||
} | ||
|
||
public static Electronics getINSTANCE() { | ||
return INSTANCE; | ||
} | ||
|
||
private Electronic[] electronicList; | ||
|
||
public Electronic[] getElectronicList() { | ||
return electronicList; | ||
} | ||
|
||
public void setElectronicList(Electronic[] electronicList) { | ||
this.electronicList = electronicList; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Electronics that = (Electronics) o; | ||
return Objects.equals(INSTANCE, that.INSTANCE) && Arrays.equals(electronicList, that.electronicList); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hash(INSTANCE); | ||
result = 31 * result + Arrays.hashCode(electronicList); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Electronics{" + | ||
"INSTANCE=" + INSTANCE + | ||
", electronicList=" + Arrays.toString(electronicList) + | ||
'}'; | ||
} | ||
|
||
public Electronic findByProductNo(String productNo) throws Exception { | ||
for (Electronic electronic:this.electronicList | ||
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. Code Convention이 많이 깨져있네요! IDE의 기능을 이용해서 보기 좋게 수정해 주세용~ |
||
) { | ||
if(electronic.getProductNo().equals(productNo))return electronic; | ||
} | ||
throw new Exception("해당 생산번호를 가지는 기기는 없습니다."); | ||
}; | ||
|
||
public Electronic[] groupByCompanyName(Company company){ | ||
List<Electronic> electronics = new ArrayList<Electronic>(); | ||
for (Electronic electronic:this.electronicList | ||
) { | ||
if(electronic.getCompany() == company){ | ||
electronics.add(electronic); | ||
} | ||
} | ||
return electronics.toArray(new Electronic[electronics.size()]); | ||
}; | ||
|
||
public Electronic[] groupByAuthMethod(AuthMethod authMethod){ | ||
List<Electronic> electronics = new ArrayList<Electronic>(); | ||
for (Electronic electronic:this.electronicList | ||
) { | ||
if(Arrays.asList(electronic.getAuthMethod()).indexOf(authMethod)>-1){ | ||
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. 좋은 아이디어네요! 활용을 잘하셨어요 👋 |
||
electronics.add(electronic); | ||
} | ||
} | ||
return electronics.toArray(new Electronic[electronics.size()]); | ||
}; | ||
} |
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.
한글보다는 영어로 정의하는 게 더 좋을 것 같아요!
FINGERPRINT
,PATTERN
,PIN
,FACE
등으로 정의해 보는 건 어떨까요?