-
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 GyeongminKang #23
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,110 @@ | ||
package Practice; | ||
|
||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
public class Electronic { | ||
private String productNo; | ||
private String modelName; | ||
public enum Company{ | ||
C1("SAMSUNG"), C2("APPLE"), C3("LG"); | ||
|
||
private String companyName = null; | ||
Company(String companyName){ | ||
this.companyName = companyName; | ||
} | ||
|
||
public String getCompanyName(){return companyName;} | ||
} | ||
private Company company; | ||
private String dateOfMade; | ||
public enum AuthMethod{ | ||
AuthMethod1("FINGERPRINT"), | ||
AuthMethod2("PATTERN"), | ||
AuthMethod3("PIN"), | ||
AuthMethod4("FACE"); | ||
|
||
private String authMethodName = null; | ||
AuthMethod(String authMethodName){ | ||
this.authMethodName = authMethodName; | ||
} | ||
public String getAuthMethodName() { | ||
return authMethodName; | ||
} | ||
} | ||
private AuthMethod[] authMethod; | ||
|
||
public Electronic(){} | ||
|
||
public Electronic(String productNo, String modelName, String dateOfMade, AuthMethod[] authMethod, Company company){ | ||
this.productNo = productNo; | ||
this.modelName = modelName; | ||
this.dateOfMade = dateOfMade; | ||
this.authMethod = authMethod; | ||
this.company = company; | ||
} | ||
|
||
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 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; | ||
} | ||
|
||
public Company getCompany() { | ||
return company; | ||
} | ||
public void setCompany(Company company) { | ||
this.company = company; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Electronic that = (Electronic) o; | ||
return productNo == that.productNo && Objects.equals(modelName, that.modelName) && Objects.equals(dateOfMade, that.dateOfMade) && Arrays.equals(authMethod, that.authMethod); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hash(productNo, modelName, dateOfMade); | ||
result = 31 * result + Arrays.hashCode(authMethod); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Electronic{" + | ||
"productNo=" + productNo + | ||
", modelName='" + modelName + '\'' + | ||
", dateOfMade='" + dateOfMade + '\'' + | ||
", authMethod=" + Arrays.toString(authMethod) + | ||
'}'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package Practice; | ||
|
||
import java.util.Arrays; | ||
|
||
public class Electronics { | ||
private Electronic[] electronicList; | ||
|
||
//싱글톤 | ||
private static Electronics electronics; | ||
public static Electronics getInstance(){ | ||
if(electronics == null){ | ||
electronics = new Electronics(); | ||
} | ||
return electronics; | ||
} | ||
|
||
//productNo으로 전자제품 찾기 | ||
public Electronic findByProductNo(String productNo){ | ||
for(int i = 0; i < electronicList.length; i++){ | ||
if(electronicList[i].getProductNo().equals(productNo)){ | ||
return electronicList[i]; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
//제조 회사로 찾아서 하나의 배열로 반환 | ||
public Electronic[] groupByCompanyName(Electronic.Company company){ | ||
Electronic[] ans = new Electronic[electronicList.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. 저라면 리턴되야할 배열의 크기를 모를 땐 컬랙션(ArrayList)를 사용할 것 같아요. loop 다 돌고 배열로 변환 후 리턴해주면 리턴타입 문제는 해결되니깐요. 그리고 electronicList.length 만큼의 배열에 필터된 값들이 들어간다고 하더라고 리턴되는 배열의 length 또한 필터링 되기 전 전체 배열의 사이즈와 같기 때문에 외부에서 필터링된 배열의 사이즈로 처리하는 로직이 들어간다면 의도한 대로 작동하지 않을거에요 |
||
for(int i = 0; i < electronicList.length; i++){ | ||
if(electronicList[i].getCompany().equals(company)){ | ||
ans[i] = electronicList[i]; | ||
} | ||
} | ||
return ans; | ||
} | ||
|
||
public Electronic[] groupByAutoMethod(Electronic.AuthMethod authMethod){ | ||
Electronic[] ans = new Electronic[electronicList.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. 여기도 컬랙션 쓰는게 나을것 같아요 |
||
for(int i = 0; i < electronicList.length; i++){ | ||
if(electronicList[i].getAuthMethod()[i].getAuthMethodName() == authMethod.getAuthMethodName()){ | ||
ans[i] = electronicList[i]; | ||
} | ||
} | ||
return ans; | ||
} | ||
|
||
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 Arrays.equals(electronicList, that.electronicList); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.hashCode(electronicList); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Electronics{" + | ||
"electronicList=" + Arrays.toString(electronicList) + | ||
'}'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package Practice; | ||
|
||
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 LocalDateTime registerTime; | ||
|
||
private Electronic[] electronicDevices; | ||
|
||
public User(){} | ||
|
||
public User(String userId, String userPassword, String userPhoneNumber, String userEmail, String userBirthDate, LocalDateTime registerTime, Electronic[] electronicDevices) { | ||
this.userId = userId; | ||
this.userPassword = userPassword; | ||
this.userPhoneNumber = userPhoneNumber; | ||
this.userEmail = userEmail; | ||
this.userBirthDate = userBirthDate; | ||
this.registerTime = registerTime; | ||
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 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 o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
User user = (User) o; | ||
return userPhoneNumber == user.userPhoneNumber && Objects.equals(userId, user.userId) && Objects.equals(userPassword, user.userPassword) && Objects.equals(userEmail, user.userEmail) && Objects.equals(userBirthDate, user.userBirthDate) && 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 + '\'' + | ||
", registerTime=" + registerTime + | ||
'}'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package Practice; | ||
|
||
import java.util.Arrays; | ||
|
||
public class Users { | ||
private User[] userList; | ||
private static Users users; | ||
|
||
private Users(){} | ||
|
||
private Users(User[] userList) { | ||
this.userList = userList; | ||
} | ||
|
||
//싱글톤 | ||
public static Users getInstance(){ | ||
if(users == null){ | ||
users = new Users(); | ||
} | ||
return users; | ||
} | ||
|
||
//userID로 회원 찾기 | ||
public User findByUserId(String userID){ | ||
for(int i = 0; i < userList.length; i++){ | ||
if(userList[i].getUserId().equals(userID)){ | ||
return userList[i]; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
//deepcopy | ||
public User copy(User user){ | ||
User copy = new User(); | ||
if(user == null){ | ||
return copy; | ||
} | ||
|
||
copy = 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. copy에 parameter로 넘어온 user를 할당하면 35번줄에서 메모리에 새로 띄운 User객체가 아닌 parameter로 넘어온 user의 값을 변경하게 되므로 아래에서 return되는 copy는 user 그자체를 넘기게 되는 형태가 됩니다. |
||
copy.setUserId(user.getUserId()); | ||
copy.setRegisterTime(user.getRegisterTime()); | ||
copy.setUserBirthDate(user.getUserBirthDate()); | ||
copy.setUserEmail(user.getUserEmail()); | ||
copy.setUserPassword(user.getUserPassword()); | ||
copy.setUserId(user.getUserId()); | ||
|
||
return copy; | ||
} | ||
|
||
public User[] getUserList() { | ||
return userList; | ||
} | ||
|
||
public void setUserList(User[] userList) { | ||
this.userList = userList; | ||
} | ||
|
||
public static Users getUsers() { | ||
return users; | ||
} | ||
|
||
public static void setUsers(Users users) { | ||
Users.users = users; | ||
} | ||
|
||
@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) + | ||
'}'; | ||
} | ||
} |
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은 서로 연관된 상수들의 집합이기 때문에 변수명을 의미있고 다른 상수들과 구분지을 수 있게 지어야 합니다. AuthMethod1~4 의 네이밍 같은 경우 해당 상수가 어떤 상수인지 의미를 알기 어렵기 때문에 개발 시 authMothodName에 접근을 해야 알게 되기 때문에 개발 편의성도 떨어지구요.