-
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 JeonghoSong #26
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 CompanyName { | ||
SAMSUNG, LG, APPLE; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package me.day05.practice.practice01; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.Objects; | ||
|
||
public class Electronic { | ||
private static int sequence; | ||
private String productNo; | ||
private String modelName; | ||
private CompanyName companyName; | ||
private LocalDate dateOfMade; | ||
private AuthMethod[] authMethods; | ||
|
||
public Electronic(String modelName, CompanyName companyName, AuthMethod[] authMethods) { | ||
this.productNo = String.format("%s%04d", LocalDate.now().toString().replaceAll("-", ""), ++sequence); | ||
this.modelName = modelName; | ||
this.companyName = companyName; | ||
this.dateOfMade = LocalDate.now(); | ||
this.authMethods = authMethods; | ||
} | ||
|
||
public static int getSequence() { | ||
return sequence; | ||
} | ||
|
||
public static void setSequence(int sequence) { | ||
Electronic.sequence = sequence; | ||
} | ||
|
||
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 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[] getAuthMethods() { | ||
return authMethods; | ||
} | ||
|
||
public void setAuthMethods(AuthMethod[] authMethods) { | ||
this.authMethods = authMethods; | ||
} | ||
|
||
|
||
|
||
public static void main(String[] args) { | ||
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 class에서 하시면 안될 것 같아요! |
||
Electronic e1 = new Electronic("test01", CompanyName.SAMSUNG, new AuthMethod[] {AuthMethod.PATTERN, AuthMethod.FINGERPRINT}); | ||
Electronic e2 = new Electronic("test01", CompanyName.SAMSUNG, new AuthMethod[] {AuthMethod.PATTERN, AuthMethod.FINGERPRINT}); | ||
System.out.println(e1.productNo); | ||
System.out.println(e2.productNo); | ||
System.out.println(sequence); | ||
System.out.println("e1 hashCode : " + e1.hashCode()); | ||
System.out.println("e1 toString : " + e1.toString()); | ||
System.out.println("success"); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Electronic [productNo=" + productNo + ", modelName=" + modelName + ", companyName=" + companyName | ||
+ ", dateOfMade=" + dateOfMade + ", authMethods=" + Arrays.toString(authMethods) + "]"; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(productNo, modelName, companyName, dateOfMade, Arrays.hashCode(authMethods)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (!(obj instanceof Electronic)) { | ||
return false; | ||
} | ||
Electronic other = (Electronic) obj; | ||
return Objects.equals(productNo, other.productNo) && Objects.equals(modelName, other.modelName) | ||
&& companyName == other.companyName && Objects.equals(dateOfMade, other.dateOfMade) | ||
&& Arrays.equals(authMethods, other.authMethods); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package me.day05.practice.practice01; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
|
||
public class User { | ||
|
||
private String userId; | ||
private String userPassword; | ||
private int userPhoneNumber; | ||
private String userEmail; | ||
private int userBirthDate; | ||
private ArrayList<String> electronicDevices; | ||
private LocalDate registerTime; | ||
|
||
public User(String userId, String userPassword, int userPhoneNumber, String userEmail, int userBirthDate, ArrayList<String> electronicDevices) { | ||
this.userId = userId; | ||
this.userPassword = userPassword; | ||
this.userPhoneNumber = userPhoneNumber; | ||
this.userEmail = userEmail; | ||
this.userBirthDate = userBirthDate; | ||
this.electronicDevices = electronicDevices; | ||
this.registerTime = LocalDate.now(); | ||
} | ||
|
||
// toString | ||
@Override | ||
public String toString() { | ||
return "User{" + | ||
"userId='" + userId + '\'' + | ||
", userPassword='" + userPassword + '\'' + | ||
", userPhoneNumber=" + userPhoneNumber + | ||
", userEmail='" + userEmail + '\'' + | ||
", userBirthDate=" + userBirthDate + | ||
", electronicDevices=" + electronicDevices + | ||
", registerTime=" + registerTime + | ||
'}'; | ||
} | ||
|
||
// hashCode | ||
@Override | ||
public int hashCode() { | ||
int result = 17; | ||
result = 31 * result + userId.hashCode(); | ||
result = 31 * result + userPassword.hashCode(); | ||
result = 31 * result + Integer.hashCode(userPhoneNumber); | ||
result = 31 * result + userEmail.hashCode(); | ||
result = 31 * result + Integer.hashCode(userBirthDate); | ||
result = 31 * result + electronicDevices.hashCode(); | ||
result = 31 * result + registerTime.hashCode(); | ||
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. 오홍 여기선 위처럼 Objects.hash()를 사용하지 않은 이유가 있나요? |
||
return result; | ||
} | ||
|
||
// equals | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
User user = (User) o; | ||
|
||
if (userPhoneNumber != user.userPhoneNumber) return false; | ||
if (userBirthDate != user.userBirthDate) return false; | ||
if (!userId.equals(user.userId)) return false; | ||
if (!userPassword.equals(user.userPassword)) return false; | ||
if (!userEmail.equals(user.userEmail)) return false; | ||
if (!electronicDevices.equals(user.electronicDevices)) return false; | ||
return registerTime.equals(user.registerTime); | ||
} | ||
|
||
// getter & setter | ||
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 int getUserPhoneNumber() { | ||
return userPhoneNumber; | ||
} | ||
|
||
public void setUserPhoneNumber(int userPhoneNumber) { | ||
this.userPhoneNumber = userPhoneNumber; | ||
} | ||
|
||
public String getUserEmail() { | ||
return userEmail; | ||
} | ||
|
||
public void setUserEmail(String userEmail) { | ||
this.userEmail = userEmail; | ||
} | ||
|
||
public int getUserBirthDate() { | ||
return userBirthDate; | ||
} | ||
|
||
public void setUserBirthDate(int userBirthDate) { | ||
this.userBirthDate = userBirthDate; | ||
} | ||
|
||
public ArrayList<String> getElectronicDevices() { | ||
return electronicDevices; | ||
} | ||
|
||
public void setElectronicDevices(ArrayList<String> electronicDevices) { | ||
this.electronicDevices = electronicDevices; | ||
} | ||
|
||
public LocalDate getRegisterTime() { | ||
return registerTime; | ||
} | ||
|
||
public void setRegisterTime(LocalDate registerTime) { | ||
this.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.ArrayList; | ||
import java.util.Arrays; | ||
|
||
public class Users { | ||
private static Users instance = 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. 제 개인적으로 객체명으로 instance는 고치고 싶습니다. |
||
private User[] userList; | ||
|
||
private Users() { | ||
userList = new User[10]; | ||
} | ||
|
||
public static Users getInstance() { | ||
if (instance==null) { | ||
instance = new Users(); | ||
} | ||
return instance; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.hashCode(userList); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Users{" + | ||
"userList=" + Arrays.toString(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); | ||
} | ||
|
||
public User[] getUserList() { | ||
return userList; | ||
} | ||
|
||
public void setUserList(User[] userList) { | ||
this.userList = userList; | ||
} | ||
|
||
public User findByUserId(String userId) { | ||
for (User user : userList) { | ||
if (user.getUserId().equals(userId)) return user; | ||
} | ||
return null; | ||
} | ||
|
||
public User copy(User user) { | ||
String userId = user.getUserId(); | ||
String userPassword = user.getUserPassword(); | ||
int userPhoneNumber = user.getUserPhoneNumber(); | ||
String userEmail = user.getUserEmail(); | ||
int userBirthDate = user.getUserBirthDate(); | ||
ArrayList<String> electronicDevices = new ArrayList<>(user.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. 문제!!!
|
||
User dummyUser = new User(userId, userPassword, userPhoneNumber, userEmail, userBirthDate, electronicDevices); | ||
dummyUser.setRegisterTime(user.getRegisterTime()); | ||
return dummyUser; | ||
} | ||
} |
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.
여기 많이 띄어져 있네요 ㅎㅎ