diff --git a/Day05/.gitignore b/Day05/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Day05/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Day05/Day05.iml b/Day05/Day05.iml new file mode 100644 index 0000000..6db0c46 --- /dev/null +++ b/Day05/Day05.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Day05/src/me/day05/practice/Practice01/Electronic.java b/Day05/src/me/day05/practice/Practice01/Electronic.java new file mode 100644 index 0000000..e4c0a8e --- /dev/null +++ b/Day05/src/me/day05/practice/Practice01/Electronic.java @@ -0,0 +1,122 @@ +package me.day05.practice.Practice01; + + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Arrays; +import java.util.Objects; + +public class Electronic { + + public enum companyName {SAMSUNG,LG,APPLE} + public enum authMethod {FINGERPRINT, PATTERN, PIN, FACE} + private authMethod[] authMethods; + private companyName company; + private String productNo; + private static int productionCount=1; + + private String modelName; + private LocalDateTime dateOfMade; + + public Electronic(companyName companyName, authMethod []authMehods, String modelName){ + + StringBuffer generateProductNo; + generateProductNo = new StringBuffer(LocalDate.now().getYear()%100); + generateProductNo.append(String.format("%02",LocalDate.now().getDayOfMonth())); + generateProductNo.append(String.format("%02",LocalDate.now().getDayOfMonth())); + generateProductNo.append(String.format("%04",productionCount++ )); + this.productNo = String.valueOf(getProductNo()); + this.authMethods = authMehods; + this.company = companyName; + this.modelName = modelName; + this.dateOfMade = LocalDateTime.now(ZoneId.systemDefault()); + + } + + public authMethod[] getAuthMethods() { + return authMethods; + } + + public void setAuthMethods(authMethod[] authMethods) { + this.authMethods = authMethods; + } + + public companyName getCompany() { + return company; + } + + public void setCompany(companyName company) { + this.company = company; + } + + public String getProductNo() { + return productNo; + } + + public void setProductNo(String productNo) { + this.productNo = productNo; + } + + public static int getProductionCount() { + return productionCount; + } + + public static void setProductionCount(int productionCount) { + Electronic.productionCount = productionCount; + } + + public LocalDateTime getDateOfMade() { + return dateOfMade; + } + + public void setDateOfMade(LocalDateTime dateOfMade) { + this.dateOfMade = dateOfMade; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Electronic that = (Electronic) o; + + if (!Objects.equals(productNo, that.productNo)) return false; + if (!Objects.equals(dateOfMade, that.dateOfMade)) return false; + if (!Objects.equals(modelName, that.modelName)) return false; + if (company != that.company) return false; + // Probably incorrect - comparing Object[] arrays with Arrays.equals + return Arrays.equals(authMethods, that.authMethods); + } + + @Override + public int hashCode() { + int result = productNo != null ? productNo.hashCode() : 0; + result = 31 * result + (dateOfMade != null ? dateOfMade.hashCode() : 0); + result = 31 * result + (modelName != null ? modelName.hashCode() : 0); + result = 31 * result + (company != null ? company.hashCode() : 0); + result = 31 * result + Arrays.hashCode(authMethods); + return result; + } + + + @Override + public String toString() { + return "Electronic{" + + "productNo=" + productNo + + ", dateOfMade=" + dateOfMade + + ", modelName='" + modelName + '\'' + + ", company=" + company + + ", authMethods=" + Arrays.toString(authMethods) + + '}'; + } + +} diff --git a/Day05/src/me/day05/practice/Practice01/User.java b/Day05/src/me/day05/practice/Practice01/User.java new file mode 100644 index 0000000..31e9be6 --- /dev/null +++ b/Day05/src/me/day05/practice/Practice01/User.java @@ -0,0 +1,105 @@ +package me.day05.practice.Practice01; + +import java.util.Arrays; +import java.util.Objects; + +public class User { + + private String userId; + private String userPassword; + private int userPhoneNumber; + private String userEmail; + private int userBirthDate; + private Electronic[] electronicDevices; + + + public User(){}// default 생성자 + + public User(String userId){ + this.userId = userId; + } + + public User(String userId, String userPassword, int userPhoneNumber, String userEmail, int userBirthDate, Electronic[] electronicDevices) { + 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 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 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 Objects.equals(userId, user.userId); + } + + @Override + public int hashCode() { + return userId.hashCode(); + } + + @Override + public String toString() { + return "User{" + + "userId='" + userId + '\'' + + ", userPassword='" + userPassword + '\'' + + ", userPhoneNumber=" + userPhoneNumber + + ", userEmail='" + userEmail + '\'' + + ", userBirthDate=" + userBirthDate + + ", electronicDevices=" + Arrays.toString(electronicDevices) + + '}'; + } +} diff --git a/Day05/src/me/day05/practice/Practice02/Users.java b/Day05/src/me/day05/practice/Practice02/Users.java new file mode 100644 index 0000000..5146e4a --- /dev/null +++ b/Day05/src/me/day05/practice/Practice02/Users.java @@ -0,0 +1,212 @@ +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 allUsers; + // 싱글톤 + public Users getInstance() { + if (allUsers == null) { + allUsers = new Users(); + } + return allUsers; + } + private User[] userList; + private static final int DEFAULT = 10; + private int size; + private int capacity; + + private Users() { + allUsers.userList = new User[DEFAULT]; + this.capacity = DEFAULT; + this.size = 0; + } + + private Users(int initial){ + allUsers.userList = new User[initial]; + this.capacity = initial; + this.size =0; + } + + private Users(User[] userList){ + this.userList = userList; + this.capacity = userList.length; + this.size = userList.length; + } + + public User[] getUserList() { + return userList; + } + + public void setUserList(User[] userList) { + this.userList = userList; + } + + // add, set, get, pop, indexOf,size, capcity(for dynamic- size array) + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public int getCapacity() { + return capacity; + } + + public void setCapacity(int capacity) { + this.capacity = capacity; + } + + public User get(int index){ + if(index<0||index>=this.size){ + System.out.println("index의 범위가 올바르지 않습니다."); + return null; + } + return userList[index]; + } + + public void set(int index, User user){ + if(index<0||index>=this.size){ + System.out.println("index의 범위가 올바르지 않습니다."); + return; + } + if(user == null) { + System.out.println("저장이 불가합니다."); + return; + } + userList[index] = user; + } + + public int indexOf(User user){ + if(user == null) { + System.out.println("not found ."); + return -1; + } + + for(int i=0;i= size) return null; + + User popElement = userList[idx]; + userList[idx]= null; + + for(int i = idx+1;i