-
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 SeongminLee #39
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package Practice_03; | ||
|
||
import java.util.*; | ||
import java.time.*; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class Electronic { | ||
|
||
public enum Company { SAMSUNG, LG, APPLE } | ||
public enum AuthMethod { FINGERPRINT, PIN, PATTERN, FACE } | ||
|
||
private static int registrationNo; | ||
private String productNo; | ||
private String modelName; | ||
private Company company; | ||
private LocalDate dateOfMade; | ||
private AuthMethod[] authMethods; | ||
|
||
public Electronic(String modelName, Company company, AuthMethod[] authMethods) { | ||
this.modelName = modelName; | ||
this.company = company; | ||
this.authMethods = authMethods; | ||
this.productNo = generateProductNo(); | ||
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 generateProductNo() { | ||
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(DateTimeFormatter.ofPattern("yyMMdd")); | ||
registrationNo++; | ||
registrationNo %= 100000; | ||
String registrationNoStr = String.format("%04d", registrationNo); | ||
return date + registrationNoStr; | ||
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 boolean containsAuthMethod(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. 👍🏻 너무 좋은데요? |
||
return Arrays.asList(authMethods).contains(authMethod); | ||
} | ||
|
||
public String getProductNo() { | ||
return productNo; | ||
} | ||
|
||
public String getModelName() { | ||
return modelName; | ||
} | ||
|
||
public void setModelName(String modelName) { | ||
this.modelName = modelName; | ||
} | ||
|
||
public Company getCompany() { | ||
return company; | ||
} | ||
|
||
public void setCompany(Company company) { | ||
this.company = company; | ||
} | ||
|
||
public LocalDate getDateOfMade() { | ||
return dateOfMade; | ||
} | ||
|
||
public AuthMethod[] getAuthMethods() { | ||
return authMethods; | ||
} | ||
|
||
public void setAuthMethods(AuthMethod[] authMethods) { | ||
this.authMethods = authMethods; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(productNo, modelName, company, authMethods); | ||
} | ||
|
||
@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(this.productNo, that.productNo); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("Electronic { productNo=%s, modelName=%s, company=%s, authMethods=%s }", | ||
productNo, modelName, company, Arrays.toString(authMethods)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package Practice_03; | ||
|
||
import java.util.*; | ||
import Practice_03.Electronic.*; | ||
|
||
public class Electronics { | ||
private static Electronics instance; | ||
private static Electronic[] electronicList; | ||
|
||
private Electronics() { | ||
} | ||
|
||
public static Electronics getInstance() { | ||
if (instance == null) { | ||
instance = new Electronics(); | ||
} | ||
return instance; | ||
} | ||
|
||
public Electronic findByProductNo(String productNo) { | ||
for (Electronic electronic : electronicList) { | ||
if (electronic.getProductNo().equals(productNo)) { | ||
return electronic; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public Electronic[] groupByCompanyName(Company company) { | ||
List<Electronic> electronics = new ArrayList<>(); | ||
for (Electronic electronic : electronicList) { | ||
if (electronic.getCompany() == company) { | ||
electronics.add(electronic); | ||
} | ||
} | ||
return electronics.toArray(new Electronic[electronics.size()]); | ||
} | ||
|
||
public Electronic[] groupByAuthMethod(AuthMethod authMethod) { | ||
List<Electronic> groupAuthList = new ArrayList<>(); | ||
for (Electronic electronic : electronicList) { | ||
if (Arrays.equals(electronic.getAuthMethods(), new AuthMethod[] {authMethod})) { | ||
groupAuthList.add(electronic); | ||
} | ||
} | ||
return groupAuthList.toArray(new Electronic[groupAuthList.size()]); | ||
} | ||
|
||
public static Electronic[] getElectronicList() { | ||
return electronicList; | ||
} | ||
|
||
public static void setElectronicList(Electronic[] electronicList) { | ||
Electronics.electronicList = electronicList; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return super.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
return super.equals(obj); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Electronics{}"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package Practice_03; | ||
|
||
import java.time.*; | ||
import java.util.*; | ||
|
||
public class User { | ||
private String userId; | ||
private String userPassword; | ||
private String userPhoneNumber; | ||
private String userEmail; | ||
private String userBirthDate; | ||
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 Electronic[] electronicDevices; | ||
private LocalDateTime 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.electronicDevices = new Electronic[10]; | ||
this.registerTime = LocalDateTime.now(); | ||
} | ||
|
||
public User(String userId, String userPassword, String userPhoneNumber, String userEmail, String userBirthDate) { | ||
this.userId = userId; | ||
this.userPassword = userPassword; | ||
this.userPhoneNumber = userPhoneNumber; | ||
this.userEmail = userEmail; | ||
this.userBirthDate = userBirthDate; | ||
this.electronicDevices = new Electronic[10]; | ||
this.registerTime = LocalDateTime.now(); | ||
} | ||
|
||
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 Electronic[] 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 electronicDevices; | ||
} | ||
|
||
public void setElectronicDevices(Electronic[] electronicDevices) { | ||
this.electronicDevices = electronicDevices; | ||
} | ||
|
||
public LocalDateTime getRegisterTime() { | ||
return registerTime; | ||
} | ||
|
||
public void setRegisterTime(LocalDateTime registerTime) { | ||
this.registerTime = registerTime; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (this == object) return true; | ||
if (object == null || this.getClass() != object.getClass()) return false; | ||
|
||
User user = (User) object; | ||
|
||
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); | ||
} | ||
|
||
@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,69 @@ | ||||||||
package Practice_03; | ||||||||
|
||||||||
import java.util.*; | ||||||||
|
||||||||
public class Users { | ||||||||
private static Users 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.
Suggested change
줄바꿈을 추가해주면 좋을 것 같습니다~ |
||||||||
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. 👍🏻 |
||||||||
} | ||||||||
|
||||||||
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) { | ||||||||
if (userList == null) { | ||||||||
return null; | ||||||||
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. 꼼꼼하게 널 체크를 해주는 습관은 좋습니다. |
||||||||
} | ||||||||
for (User userInfo : 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 (userInfo.getUserId().equals(userId)) { | ||||||||
return userInfo; | ||||||||
} | ||||||||
} | ||||||||
return null; | ||||||||
} | ||||||||
|
||||||||
public User copy(User user) { | ||||||||
User copiedUser = new User(); | ||||||||
copiedUser.setUserId(user.getUserId()); | ||||||||
copiedUser.setUserEmail(user.getUserEmail()); | ||||||||
copiedUser.setUserPassword(user.getUserPassword()); | ||||||||
copiedUser.setUserBirthDate(user.getUserBirthDate()); | ||||||||
copiedUser.setUserPhoneNumber(user.getUserPhoneNumber()); | ||||||||
copiedUser.setElectronicDevices(Arrays.copyOf(user.getElectronicDevices(), user.getElectronicDevices().length)); | ||||||||
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.
현재 상황에서는 |
||||||||
return copiedUser; | ||||||||
} | ||||||||
|
||||||||
@Override | ||||||||
public boolean equals(Object object) { | ||||||||
if (this == object) return true; | ||||||||
if (object == null || getClass() != object.getClass()) return false; | ||||||||
Users users = (Users) object; | ||||||||
return Arrays.equals(userList, users.userList); | ||||||||
} | ||||||||
|
||||||||
@Override | ||||||||
public int hashCode() { | ||||||||
return Arrays.hashCode(userList); | ||||||||
} | ||||||||
|
||||||||
@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.
Enum
클래스도 분리하여 별도로 관리되면 좋을 것 같네요~