-
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
Java Assignment3 upload by HaesolChoi #40
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. AuthMethod 클래스에 한국어보다는 영어로 상수 정의를 하는 게 좋지 않을까요? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package me.day05.practice.Practice01; | ||
|
||
//본인인증 방법 — Enum형으로 정의 | ||
public enum 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. 강사님 의견처럼 저도 영어로 상수를 정의하는게 좋을 것 같습니다 ㅋㅋ |
||
패턴인증, | ||
핀인증, | ||
얼굴인증 | ||
} |
EunBinChoi marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package me.day05.practice.Practice01; | ||
|
||
//제조회사명 — Enum형으로 정의 | ||
public enum CompanyName { | ||
SAMSUNG, | ||
LG, | ||
APPLE | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,104 @@ | ||||||
package me.day05.practice.Practice01; | ||||||
|
||||||
import java.time.LocalDate; | ||||||
import java.time.format.DateTimeFormatter; | ||||||
import java.util.Arrays; | ||||||
import java.util.Objects; | ||||||
|
||||||
public class Electronic { | ||||||
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 String modelName; | ||||||
private CompanyName companyName; | ||||||
private LocalDate 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. 사소한거지만 여러개를 담을 수 있으니 변수명에 복수를 사용하는게 어떨까요?
Suggested change
|
||||||
|
||||||
private static int orderNum = 0; | ||||||
|
||||||
public Electronic(String modelName, CompanyName companyName, LocalDate dateOfMade, AuthMethod[] authMethod) { | ||||||
orderNum++; | ||||||
this.productNo = orderProductNo(); | ||||||
this.modelName = modelName; | ||||||
this.companyName = companyName; | ||||||
this.dateOfMade = dateOfMade; | ||||||
this.authMethod = authMethod; | ||||||
} | ||||||
|
||||||
|
||||||
//ex. if 2023/03/30(now) then 230330 + 0001 (4자리 등록 순서) ⇒ 2303300001 | ||||||
private String orderProductNo() { | ||||||
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. 오! 메서드 분리를 해주셨네요.💯 |
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMdd"); | ||||||
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 date = LocalDate.now().format(formatter); | ||||||
String order_cnt = String.format("%04d", orderNum); | ||||||
return date + order_cnt; | ||||||
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 String getProductNo() { | ||||||
return productNo; | ||||||
} | ||||||
|
||||||
public String getModelName() { | ||||||
return modelName; | ||||||
} | ||||||
|
||||||
public void setModelName(String modelName) { | ||||||
this.modelName = modelName; | ||||||
} | ||||||
|
||||||
public CompanyName getCompanyName() { | ||||||
return companyName; | ||||||
} | ||||||
|
||||||
public void setCompanyName(CompanyName companyName) { | ||||||
this.companyName = companyName; | ||||||
} | ||||||
|
||||||
public LocalDate getDateOfMade() { | ||||||
return dateOfMade; | ||||||
} | ||||||
|
||||||
public void setDateOfMade(LocalDate dateOfMade) { | ||||||
this.dateOfMade = dateOfMade; | ||||||
} | ||||||
|
||||||
public AuthMethod[] getAuthMethod() { | ||||||
return authMethod; | ||||||
} | ||||||
|
||||||
public void setAuthMethod(AuthMethod[] authMethod) { | ||||||
this.authMethod = authMethod; | ||||||
} | ||||||
|
||||||
public static void setOrderNum(int orderNum) { | ||||||
Electronic.orderNum = orderNum; | ||||||
} | ||||||
|
||||||
@Override | ||||||
public int hashCode() { | ||||||
return Objects.hash(productNo, modelName, companyName, dateOfMade, Arrays.hashCode(authMethod)); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public boolean equals(Object obj) { | ||||||
if (this == obj) return true; | ||||||
if (obj == null || getClass() != obj.getClass()) return false; | ||||||
Electronic that = (Electronic) obj; | ||||||
return Objects.equals(productNo, that.productNo) && | ||||||
Objects.equals(modelName, that.modelName) && | ||||||
companyName == that.companyName && | ||||||
Objects.equals(dateOfMade, that.dateOfMade) && | ||||||
Arrays.equals(authMethod, that.authMethod); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public String toString() { | ||||||
return "Electronic{" + | ||||||
"productNo='" + productNo + '\'' + | ||||||
", modelName='" + modelName + '\'' + | ||||||
", companyName=" + companyName + | ||||||
", dateOfMade=" + dateOfMade + | ||||||
", authMethod=" + Arrays.toString(authMethod) + | ||||||
'}'; | ||||||
} | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package me.day05.practice.Practice01; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class Test { | ||
public static void main(String[] args) { | ||
//checking electronic | ||
Electronic device1 = new Electronic("iphone13", CompanyName.APPLE, LocalDate.of(2021, 9, 1), new AuthMethod[] {AuthMethod.얼굴인증}); | ||
Electronic device2 = new Electronic("iphone8", CompanyName.APPLE, LocalDate.of(2017, 9, 1), new AuthMethod[] {AuthMethod.지문인증}); | ||
|
||
System.out.println(device1); | ||
System.out.println(device2); | ||
/* 출력 | ||
Electronic{productNo='2304180001', modelName='iphone13', companyName=APPLE, dateOfMade=2021-09-01, authMethods=[얼굴인증]} | ||
Electronic{productNo='2304180002', modelName='iphone8', companyName=APPLE, dateOfMade=2017-09-01, authMethods=[지문인증]} | ||
*/ | ||
|
||
User user1 = new User("abc", "1234", "010-1111-2222", "[email protected]", "010101", new String[] {"device2"}); | ||
System.out.println(user1); | ||
|
||
//출력 Users{userId='abc', userPassword='1234', userPhoneNumber='010-1111-2222', userEmail='[email protected]', userBirthDate='010101', electronicDevices=[device2], registerTime=2023-04-18} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package me.day05.practice.Practice01; | ||
|
||
import java.time.LocalDate; | ||
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 String[] 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. 요거는 |
||
private LocalDate registerTime; | ||
|
||
//객체 생성시 시스템 시간으로 자동 설정 | ||
public User() { | ||
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.registerTime = LocalDate.now(); | ||
} | ||
|
||
public User(String userId, String userPassword, String userPhoneNumber, String userEmail, String userBirthDate, String[] electronicDevices) { | ||
this.userId = userId; | ||
this.userPassword = userPassword; | ||
this.userPhoneNumber = userPhoneNumber; | ||
this.userEmail = userEmail; | ||
this.userBirthDate = userBirthDate; | ||
this.electronicDevices = electronicDevices; | ||
this.registerTime = LocalDate.now(); | ||
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. 👍🏻 |
||
|
||
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 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 String[] getElectronicDevices() { | ||
return electronicDevices; | ||
} | ||
|
||
public void setElectronicDevices(String[] electronicDevices) { | ||
this.electronicDevices = electronicDevices; | ||
} | ||
|
||
public LocalDate getRegisterTime() { | ||
return registerTime; | ||
} | ||
|
||
public void setRegisterTime(LocalDate registerTime) { | ||
this.registerTime = registerTime; | ||
} | ||
|
||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(userId, userPassword, userPhoneNumber, userEmail, userBirthDate, electronicDevices); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (obj == null || getClass() != obj.getClass()) return false; | ||
User user = (User) obj; | ||
return Objects.equals(userId, user.userId) && | ||
Objects.equals(userPassword, user.userPassword) && | ||
Objects.equals(userPhoneNumber, user.userPhoneNumber) && | ||
Objects.equals(userEmail, user.userEmail) && | ||
Objects.equals(userBirthDate, user.userBirthDate) && | ||
Arrays.equals(electronicDevices, user.electronicDevices); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Users{" + | ||
"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,69 @@ | ||
package me.day05.practice.Practice02; | ||
import me.day05.practice.Practice01.User; | ||
|
||
import java.util.Arrays; | ||
|
||
public class Users { | ||
private 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. 변수명에 |
||
private 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. 👍🏻 |
||
} | ||
|
||
private static Users instance = new 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. 마찬가지 |
||
|
||
//2-1 Users 클래스의 객체를 싱글톤으로 생성하는 함수를 작성 | ||
public static Users getInstance() { | ||
if (instance == null) { | ||
instance = new Users(); | ||
} | ||
return instance; | ||
} | ||
|
||
public User[] getUserList() { | ||
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 userList; | ||
} | ||
|
||
public void setUserList(User[] userList) { | ||
this.userList = userList; | ||
} | ||
|
||
//2-2 userId를 통해 인자로 주어진 회원번호에 해당하는 회원을 반환하는 함수를 작성 | ||
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. 동일한 동작을 |
||
if (user.getUserId().equals(userId)) { | ||
return user; | ||
} | ||
} | ||
throw new IllegalArgumentException("Not found"); | ||
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. 👍🏻 |
||
} | ||
|
||
//2-3 인자로 주어진 회원 정보를 깊은 복사 (deepCopy) 하는 함수를 작성 | ||
public User copy(User original) { | ||
User user_info = new User( | ||
original.getUserId(), | ||
original.getUserEmail(), | ||
original.getUserPassword(), | ||
original.getUserBirthDate(), | ||
original.getUserPhoneNumber(), | ||
original.getElectronicDevices() | ||
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_info; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (obj == null || getClass() != obj.getClass()) return false; | ||
Users users = (Users) obj; | ||
return Arrays.equals(userList, users.userList); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.hashCode(userList); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{" + "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.
AuthMethod 클래스에 한국어보다는 영어로 상수 정의를 하는 게 좋지 않을까요?