-
Notifications
You must be signed in to change notification settings - Fork 0
Java Assignment3 upload by HoyunJung #30
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
Open
ho30archive
wants to merge
1
commit into
FastCampusKDTBackend:main
Choose a base branch
from
ho30archive:HoyunJung
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package Practice01; | ||
|
||
public enum AuthMethod { | ||
FINGERPRINT, PATTERN, PIN, FACE | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package Practice01; | ||
|
||
public enum Company { | ||
SAMSUNG, LG, APPLE | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package Practice01; | ||
|
||
import java.security.spec.EllipticCurve; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
public class Electronic { | ||
private String productNo; | ||
private static int productNum = 1; | ||
private String modelName; | ||
private Company companyName; | ||
private String dateOfMade; | ||
private AuthMethod[] authMethod; | ||
|
||
private static LocalDateTime localDateTime = LocalDateTime.now(ZoneId.systemDefault());; | ||
|
||
private Electronic(){ | ||
this.productNo = localDateTime.format(DateTimeFormatter.ofPattern("yyMMdd")) + String.format("%04d",productNum); | ||
productNum++; | ||
} | ||
|
||
public Electronic(String modelName, Company companyName){ | ||
this(); | ||
this.modelName = modelName; | ||
this.companyName = companyName; | ||
} | ||
|
||
public Electronic(String modelName, Company companyName, String dateOfMade, AuthMethod[] authMethod){ | ||
this(); | ||
this.modelName = modelName; | ||
this.companyName = companyName; | ||
this.dateOfMade = dateOfMade; | ||
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) + | ||
'}'; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package Practice01; | ||
|
||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
public class Electronics { | ||
//////// | ||
// singleton | ||
private static Electronics allElectronics; | ||
|
||
public static Electronics getInstance(){ | ||
if(allElectronics == null){ | ||
allElectronics = new Electronics(); | ||
} | ||
return allElectronics; | ||
} | ||
//////// | ||
|
||
private Electronic[] electronicList; | ||
|
||
private static final int DEFAULT = 10; | ||
private int size; | ||
private int capacity; | ||
|
||
private Electronics(){ | ||
electronicList = new Electronic[DEFAULT]; | ||
capacity = DEFAULT; | ||
} | ||
|
||
public Electronics(int initial){ | ||
electronicList = new Electronic[initial]; | ||
capacity = initial; | ||
} | ||
|
||
public Electronics(Electronic[] electronicList){ | ||
this.electronicList = electronicList; | ||
capacity = electronicList.length; | ||
size = electronicList.length; | ||
} | ||
|
||
public Electronic[] getElectronicList(){return electronicList;} | ||
|
||
public int size() { | ||
return size; | ||
} | ||
private int capacity() { | ||
return capacity; | ||
} | ||
|
||
public Electronic get(int index){ | ||
if (index<0 || index >= size) return null; | ||
return electronicList[index]; | ||
} | ||
|
||
public void set(int index, Electronic electronic){ | ||
if(index<0 || index >=size) return; | ||
if(electronic == null) return; | ||
|
||
electronicList[index] = electronic; | ||
} | ||
|
||
public void add(Electronic electronic){ | ||
if(electronic == null) return; | ||
|
||
if(size<capacity){ | ||
electronicList[size] = electronic; | ||
size++; | ||
}else{ | ||
grow(); | ||
add(electronic); | ||
} | ||
} | ||
|
||
private void grow(){ | ||
capacity *= 2; | ||
electronicList = Arrays.copyOf(electronicList, capacity); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Electronics that = (Electronics) o; | ||
return size == that.size && capacity == that.capacity && Arrays.equals(electronicList, that.electronicList); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hash(size, capacity); | ||
result = 31 * result + Arrays.hashCode(electronicList); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Electronics{" + | ||
"electronicList=" + Arrays.toString(electronicList) + | ||
", size=" + size + | ||
", capacity=" + capacity + | ||
'}'; | ||
} | ||
|
||
public Electronic findByProductNo(String productNo){ | ||
if(productNo == null) return null; | ||
if(allElectronics == null) return null; | ||
|
||
for (int i = 0; i < allElectronics.size(); i++) { | ||
if(allElectronics.get(i).getProductNo() == productNo){ | ||
return allElectronics.get(i); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public Electronic[] groupByCompanyName(Company company){ | ||
if(company == null) return null; | ||
if(allElectronics == null) return null; | ||
|
||
Electronic[] groupByCN = new Electronic[allElectronics.size()]; | ||
int count = 0; | ||
for (int i = 0; i < allElectronics.size(); i++) { | ||
if(allElectronics.get(i).getCompanyName() == company){ | ||
groupByCN[count] = allElectronics.get(i); | ||
count++; | ||
} | ||
} | ||
return groupByCN; | ||
} | ||
|
||
|
||
|
||
public Electronic[] groupByAuthMethod(AuthMethod authMethod){ | ||
if(authMethod == null) return null; | ||
if(allElectronics == null) return null; | ||
|
||
Electronic[] groupByAM = new Electronic[allElectronics.size()]; | ||
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. 여기도 컬랙션 사용 후 배열로 바꿔주는게 나을것 같아요 |
||
int count = 0; | ||
for (int i = 0; i < allElectronics.size(); i++) { | ||
for (int j = 0; j < allElectronics.get(i).getAuthMethod().length; j++) { | ||
if(authMethod == allElectronics.get(i).getAuthMethod()[j]){ | ||
groupByAM[count] = allElectronics.get(i); | ||
count++; | ||
} | ||
} | ||
} | ||
return groupByAM; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package Practice01; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
public class User { | ||
private String userId; | ||
private String userPassword; | ||
private int userPhoneNumber; | ||
private String userEmail; | ||
private String userBirthDate; | ||
private Electronic[] electronicDevices; | ||
private LocalDateTime registerTime; | ||
|
||
private User(){ | ||
this.registerTime = LocalDateTime.now(ZoneId.systemDefault()); | ||
} | ||
|
||
public User(String userId){ | ||
this(); | ||
this.userId = userId; | ||
} | ||
|
||
public User(String userId, String userPassword){ | ||
this(); | ||
this.userId = userId; | ||
this.userPassword = userPassword; | ||
} | ||
|
||
|
||
public User(String userId, String userPassword, int userPhoneNumber, String userEmail, String userBirthDate, Electronic[] electronicDevices){ | ||
this(); | ||
this.userId = userId; | ||
this.userPassword = userPassword; | ||
this.userPhoneNumber = userPhoneNumber; | ||
this.userEmail = userEmail; | ||
this.userBirthDate = userBirthDate; | ||
this.electronicDevices = electronicDevices; | ||
this.registerTime = LocalDateTime.now(ZoneId.systemDefault()); | ||
|
||
} | ||
|
||
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 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 LocalDateTime getRegisterTime() { | ||
return registerTime; | ||
} | ||
|
||
public void setRegisterTime(LocalDateTime 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 userPhoneNumber == user.userPhoneNumber && Objects.equals(userId, user.userId) && Objects.equals(userPassword, user.userPassword) && 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); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "User{" + | ||
"userId='" + userId + '\'' + | ||
", userPassword='" + userPassword + '\'' + | ||
", userPhoneNumber=" + userPhoneNumber + | ||
", userEmail='" + userEmail + '\'' + | ||
", userBirthDate='" + userBirthDate + '\'' + | ||
", electronicDevices=" + Arrays.toString(electronicDevices) + | ||
", registerTime=" + registerTime + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
몇개인지 모르는 상황에서는 저라면 컬렉션(ArrayList)을 사용한 뒤 loop 후 반복문이 끝난 뒤 배열로 바꿔줄 것 같아요. 필터링된 리스틀만 리턴받는 메소드에서 리턴 받은 후 외부에서 해당 배열의 길이를 사용하는 로직이 있게되면 로직이 꼬이게 되거든요