-
Notifications
You must be signed in to change notification settings - Fork 0
Java Assignment3 upload by WooSeokLee #14
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
8b68783
1de6550
0209777
33f9948
379895a
48ef167
1ca39db
cdad27b
6eaa189
ace625c
90859e5
0e945f8
e248a49
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,30 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/java | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=java | ||
|
||
### Java ### | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
replay_pid* | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/java |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 { | ||
SAMSUNG, LG, APPLE | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package me.day05.practice.practice01; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
public class Electronic { | ||
|
||
private static int objectNo = 0; //등록된제품순서. | ||
private String productNo; //제품일련번호 | ||
private String modelName; //전자기기 모델명 | ||
|
||
private Company companyName; //제조회사명 | ||
private String dateOfMade; //생산일자 | ||
|
||
private AuthMethod[] authMethods; //본인인증방법 , 배열로정의 | ||
|
||
|
||
|
||
public Electronic() { | ||
WooSeok77 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
objectNo++; | ||
} | ||
// 기본생성자 | ||
|
||
|
||
public Electronic( String modelName, Company companyName, String dateOfMade, AuthMethod[] authMethods) { | ||
objectNo++; | ||
//this.productNo = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd")) + String.format("%04d", objectNo) ; | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
sb.append(LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd"))); | ||
sb.append(String.format("%04d", objectNo)); | ||
|
||
// 날짜 형식 검증 | ||
if (!isValidDateFormat(dateOfMade)) { | ||
dateOfMade = "20000101"; // 기본값으로 지정 | ||
} | ||
|
||
this.productNo = sb.toString(); | ||
this.modelName = modelName; | ||
this.companyName = companyName; | ||
this.dateOfMade = dateOfMade; | ||
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.authMethods = authMethods; | ||
|
||
|
||
} | ||
//5개의 인자를 가지는 생성자 | ||
|
||
private boolean isValidDateFormat(String date) { | ||
// 문자열 길이와 숫자 형식 검증 | ||
if (date.length() != 8 || !date.matches("\\d{8}")) { | ||
return false; | ||
} | ||
|
||
// 날짜 형식 검증 | ||
try { | ||
LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyyMMdd")); | ||
return true; | ||
} catch (DateTimeParseException e) { | ||
return false; | ||
} | ||
} | ||
|
||
|
||
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 authMethods; | ||
} | ||
|
||
public void setAuthMethod(AuthMethod[] authMethods) { | ||
this.authMethods = authMethods; | ||
} | ||
|
||
public static int getObjectNo() { | ||
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 objectNo; | ||
} | ||
|
||
public static void setObjectNo(int objectNo) { | ||
Electronic.objectNo = objectNo; | ||
} | ||
|
||
@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(authMethods, that.authMethods); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hash(productNo, modelName, companyName, dateOfMade); | ||
result = 31 * result + Arrays.hashCode(authMethods); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{" + | ||
"productNo='" + productNo + '\'' + | ||
", modelName='" + modelName + '\'' + | ||
", companyName=" + companyName + | ||
", dateOfMade='" + dateOfMade + '\'' + | ||
", authMethod=" + Arrays.toString(authMethods) + | ||
'}'; | ||
} | ||
} |
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.
private 사용 좋아요~ 굿