Skip to content
Open
30 changes: 30 additions & 0 deletions .gitignore
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
34 changes: 34 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/KDTBE5_Java_Assignment3.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions me/day05/practice/practice01/AuthMethod.java
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
}
5 changes: 5 additions & 0 deletions me/day05/practice/practice01/Company.java
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
}
140 changes: 140 additions & 0 deletions me/day05/practice/practice01/Electronic.java
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; //제품일련번호

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private 사용 좋아요~ 굿

private String modelName; //전자기기 모델명

private Company companyName; //제조회사명
private String dateOfMade; //생산일자

private AuthMethod[] authMethods; //본인인증방법 , 배열로정의



public Electronic() {
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;

Choose a reason for hiding this comment

The 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() {

Choose a reason for hiding this comment

The 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) +
'}';
}
}
Loading