-
Notifications
You must be signed in to change notification settings - Fork 0
Java Assignment3 upload by Son young jun #25
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 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 me.day05.practice.Practice01; | ||
|
||
public enum AuthMethod { | ||
FINGERPRINT, PATTERN, PIN, FACE | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package me.day05.practice.Practice01; | ||
|
||
public enum Company { | ||
SAMSUMG, LG, APPLE | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package me.day05.practice.Practice01; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
public class Electronic { | ||
private static int sequence = 0; | ||
private static final int DEFAULT_CAPACITY = 10; | ||
private String productNo; | ||
private String modelName; | ||
private Company companyName; | ||
private String dateOfMade; | ||
private AuthMethod[] authMethod; | ||
|
||
Electronic() { | ||
productNo = Integer.toString(++sequence); | ||
LocalDateTime localDateTime = LocalDateTime.now(); | ||
dateOfMade = localDateTime.format(DateTimeFormatter.ofPattern("yy-MM-dd HH:mm")); | ||
authMethod = new AuthMethod[DEFAULT_CAPACITY]; | ||
} | ||
|
||
public Electronic(String modelName, Company companyName, AuthMethod[] authMethod) { | ||
this(); | ||
this.modelName = modelName; | ||
this.companyName = companyName; | ||
this.authMethod = authMethod; | ||
} | ||
|
||
public String getProductNo() { | ||
return productNo; | ||
} | ||
|
||
public void setProductNo(String productNo) { | ||
this.productNo = 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 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) && Objects.equals(modelName, that.modelName) && companyName == that.companyName && Objects.equals(dateOfMade, that.dateOfMade) && Arrays.equals(authMethod, that.authMethod); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hash(productNo, modelName, companyName, dateOfMade); | ||
result = 31 * result + Arrays.hashCode(authMethod); | ||
return result; | ||
} | ||
|
||
@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,118 @@ | ||
package me.day05.practice.Practice01; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
public class User { | ||
private static int sequence = 0; | ||
private static final int DEFAULT_CAPACITY = 10; | ||
private String userId; | ||
private String userPassword; | ||
private String userPhoneNumber; | ||
private String userEmail; | ||
private String userBirthDate; | ||
private Electronic[] electronicDevices; | ||
private String registerTime; | ||
|
||
public User() { | ||
LocalDateTime localDateTime = LocalDateTime.now(); | ||
registerTime = localDateTime.format(DateTimeFormatter.ofPattern("yy-MM-dd HH:mm")); | ||
electronicDevices = new Electronic[DEFAULT_CAPACITY]; | ||
} | ||
|
||
public User(String userId, String userPassword, String userPhoneNumber, String userEmail, String userBirthDate, Electronic[] electronicDevices) { | ||
this(); | ||
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()로 생성자 로직 중복을 막은 첫 코드네요. |
||
this.userId = userId; | ||
this.userPassword = userPassword; | ||
this.userPhoneNumber = userPhoneNumber; | ||
this.userEmail = userEmail; | ||
this.userBirthDate = userBirthDate; | ||
this.electronicDevices = electronicDevices; | ||
} | ||
|
||
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() { | ||
return electronicDevices; | ||
} | ||
|
||
public void setElectronicDevices(Electronic[] electronicDevices) { | ||
this.electronicDevices = electronicDevices; | ||
} | ||
|
||
public String getRegisterTime() { | ||
return registerTime; | ||
} | ||
|
||
public void setRegisterTime(String registerTime) { | ||
this.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(userPhoneNumber, user.userPhoneNumber) && 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, userPhoneNumber, userEmail, userBirthDate, registerTime); | ||
result = 31 * result + Arrays.hashCode(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. 오오 result에 31을 곱한 이유가 뭐예요? |
||
return result; | ||
} | ||
|
||
@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,68 @@ | ||
package me.day05.practice.Practice02; | ||
|
||
import me.day05.practice.Practice01.User; | ||
|
||
import java.util.Arrays; | ||
|
||
public class Users { | ||
private User[] userList; | ||
private static Users instance = null; | ||
|
||
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 findByUserId(String userId) { | ||
for(User user : userList) { | ||
if(userId.equals(user.getUserId())) { | ||
return user; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public User copy(User user) { | ||
User copyUser = new User(); | ||
copyUser.setUserId(user.getUserId()); | ||
copyUser.setUserPassword(user.getUserPassword()); | ||
copyUser.setUserPhoneNumber(user.getUserPhoneNumber()); | ||
copyUser.setUserEmail(user.getUserEmail()); | ||
copyUser.setUserBirthDate(user.getUserBirthDate()); | ||
copyUser.setElectronicDevices(Arrays.copyOf(user.getElectronicDevices(), user.getElectronicDevices().length)); | ||
return copyUser; | ||
} | ||
|
||
public User[] getUserList() { | ||
return userList; | ||
} | ||
|
||
public void setUserList(User[] userList) { | ||
this.userList = userList; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Users users = (Users) o; | ||
return Arrays.equals(userList, users.userList); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.hashCode(userList); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Users{" + | ||
"userList=" + Arrays.toString(userList) + | ||
'}'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package me.day05.practice.Practice03; | ||
|
||
import me.day05.practice.Practice01.AuthMethod; | ||
import me.day05.practice.Practice01.Company; | ||
import me.day05.practice.Practice01.Electronic; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class Electronics { | ||
private Electronic[] electronicList; | ||
private static Electronics instance; | ||
|
||
private Electronics() { | ||
} | ||
|
||
public static Electronics getInstance() { | ||
if(instance == null) | ||
instance = new Electronics(); | ||
return instance; | ||
} | ||
|
||
public Electronic[] getElectronicList() { | ||
return electronicList; | ||
} | ||
|
||
public void setElectronicList(Electronic[] electronicList) { | ||
this.electronicList = electronicList; | ||
} | ||
|
||
public Electronic findByProductNo(String productNo) { | ||
for(Electronic electronic : electronicList) { | ||
if(productNo.equals(electronic.getProductNo())) | ||
return electronic; | ||
} | ||
return null; | ||
} | ||
|
||
public Electronic[] groupByCompanyName(Company company) { | ||
Electronic[] electronics = Arrays.stream(electronicList).filter(list -> list.getCompanyName().equals(company)).toArray(Electronic[]::new); | ||
return electronics; | ||
} | ||
|
||
public Electronic[] groupByAuthMethod(AuthMethod authMethod) { | ||
List<Electronic> arr = new ArrayList<>(); | ||
for(Electronic electronic : electronicList) { | ||
for(AuthMethod auth : electronic.getAuthMethod()) { | ||
if(auth == authMethod) | ||
arr.add(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. 이미 추가된 electronic의 경우 그 다음 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 arr.toArray(new Electronic[arr.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.
접근 제한자를 default로 한 이유가 있을까요?
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.
이건 제가 깜빡하고 접근 제어자를 지정하지 않은 것 같습니다.