Skip to content
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 JunHoMun #34

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Day05/.gitignore
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions Day05/Day05.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="17" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
122 changes: 122 additions & 0 deletions Day05/src/me/day05/practice/Practice01/Electronic.java
Original file line number Diff line number Diff line change
@@ -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}

Choose a reason for hiding this comment

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

Enum도 별도의 클래스로 분리시켜주시면 좋을 것 같습니다~

Choose a reason for hiding this comment

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

Suggested change
public enum companyName {SAMSUNG,LG,APPLE}
public enum CompanyName {SAMSUNG,LG,APPLE}

public enum authMethod {FINGERPRINT, PATTERN, PIN, FACE}

Choose a reason for hiding this comment

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

Suggested change
public enum authMethod {FINGERPRINT, PATTERN, PIN, FACE}
public enum AuthMethod {FINGERPRINT, PATTERN, PIN, FACE}

private authMethod[] authMethods;
private companyName company;
private String productNo;
private static int productionCount=1;

Choose a reason for hiding this comment

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

static 변수는 일반 멤버 변수보다 위로 위치시켜주는 것이 관례입니다😀

Choose a reason for hiding this comment

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

Suggested change
private static int productionCount=1;
private static int productionCount = 1;

사소한거지만 코드 스타일도 맞춰주시면 좋을 것 같아요!! 인텔리제이의 자동정렬 기능을 활용해보시죠~


private String modelName;
private LocalDateTime dateOfMade;

public Electronic(companyName companyName, authMethod []authMehods, String modelName){

StringBuffer generateProductNo;

Choose a reason for hiding this comment

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

제품 일련번호를 생성하는 함수를 private 하게 분리하는 것도 괜찮을 것 같아요!

generateProductNo = new StringBuffer(LocalDate.now().getYear()%100);

Choose a reason for hiding this comment

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

LocalDate.now()가 한 메서드안에서 여러번 반복되고 있어요!~

위에서 미리 꺼내놓는다면 불필요한 함수 콜을 줄일 수 있을 것 같습니다!

generateProductNo.append(String.format("%02",LocalDate.now().getDayOfMonth()));

Choose a reason for hiding this comment

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

월이니까 getMonthValue을 사용해야하지 않을까요?

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

}
105 changes: 105 additions & 0 deletions Day05/src/me/day05/practice/Practice01/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package me.day05.practice.Practice01;

import java.util.Arrays;
import java.util.Objects;

public class User {

Choose a reason for hiding this comment

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

요구사항을 꼼꼼히 확인해주시면 좋을 것 같네요~😀

registerTime가 빠진거 같아요!


private String userId;
private String userPassword;
private int userPhoneNumber;

Choose a reason for hiding this comment

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

휴대폰 번호를 담는 변수형이 int??🤔

private String userEmail;
private int userBirthDate;

Choose a reason for hiding this comment

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

생년월일이 int??🤔

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;

Choose a reason for hiding this comment

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

여기서 문제!

이렇게 반환된 배열을 외부에서 수정하면 원본 배열에 영향이 있을까요 없을까요?

}

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