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 HeehyunKim #33

Open
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions .idea/.gitignore

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.

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.

11 changes: 11 additions & 0 deletions KDTBE5_Java_Assignment3.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$/me.day05.practice/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
29 changes: 29 additions & 0 deletions me.day05.practice/.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
3 changes: 3 additions & 0 deletions me.day05.practice/.idea/.gitignore

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

6 changes: 6 additions & 0 deletions me.day05.practice/.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 me.day05.practice/.idea/modules.xml

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

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

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

11 changes: 11 additions & 0 deletions me.day05.practice/assignment3.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="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
103 changes: 103 additions & 0 deletions me.day05.practice/src/Practice01/Electronic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package Practice01;

import java.util.Objects;
import java.util.Arrays;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Electronic {
private String productNo;
private String modelName;
private CompanyName companyName;
private LocalDate dateOfMade;
private AuthMethod[] authMethods;
private static int numProducts = 0;

Choose a reason for hiding this comment

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

일반적으로 static 변수가 최상단에 위치합니다~


public Electronic(String modelName, CompanyName companyName, LocalDate dateOfMade, AuthMethod[] authMethods){
this.modelName = modelName;

Choose a reason for hiding this comment

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

사소하지만 필드 선언 순서와 생성자 순서를 맞춰주시면 좋겠네요~

this.companyName = companyName;
this.dateOfMade = dateOfMade;
this.authMethods = authMethods;
this.productNo = ProductNo();

Choose a reason for hiding this comment

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

메서드이기 때문에 카멜케이스를 적용시켜야할 것 같고, 좀 더 적절한 네이밍은 없을까요?

generateProductNo()?

numProducts++;
}

private String ProductNo(){

Choose a reason for hiding this comment

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

private 메서드로 분리해주셨네요 👍🏻

String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd"));
date += String.format("%04d", numProducts+1);

Choose a reason for hiding this comment

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

+1이 필요한가요??

return date;
}
public enum CompanyName{

Choose a reason for hiding this comment

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

Enum도 별도의 클래스로 관리되면 좋을 것 같습니다.

SAMSUNG , LG, APPLE
}
public enum AuthMethod{
FINGERPRINT, PATTERN, PIN, FACE
}

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 CompanyName getCompanyName() {
return companyName;
}

public void setCompanyName(CompanyName companyName) {
this.companyName = companyName;
}

public LocalDate getDateOfMade() {
return dateOfMade;
}

public void setDateOfMade(LocalDate dateOfMade) {
this.dateOfMade = dateOfMade;
}

public AuthMethod[] getAuthMethods() {
return authMethods;
}

public void setAuthMethods(AuthMethod[] authMethods) {
this.authMethods = authMethods;
}

@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 "Electronic{" +
"productNo='" + productNo + '\'' +
", modelName='" + modelName + '\'' +
", companyName=" + companyName +
", dateOfMade=" + dateOfMade +
", authMethods=" + Arrays.toString(authMethods) +
'}';
}

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

import java.util.Objects;
import java.util.Arrays;
import java.time.LocalDate;

public class User {
private String userId;
private String userPassword;
private String userPhoneNumber;
private String userEmail;
private String userBirthDate;

Choose a reason for hiding this comment

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

생년월일은 담는 자료형이 String은 조금 어색하지 않나요?

private Electronic[] electronicDevices;
private LocalDate registerTime;

public User(String userId, String userPassword, String userPhoneNumber, String userEmail, String userBirthDate){
this.userId = userId;
this.userPassword = userPassword;
this.userPhoneNumber = userPhoneNumber;
this.userEmail = userEmail;
this.userBirthDate = userBirthDate;
this.electronicDevices = new Electronic[0];

Choose a reason for hiding this comment

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

0으로 초기화하는 것보다는 적절한 디폴트 값으로 초기화되면 좋겠네요~

this.registerTime = LocalDate.now();

Choose a reason for hiding this comment

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

👍🏻

}
public User(){};

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 String getUserPhoneNumber() {
return userPhoneNumber;
}

public void setUserPhoneNumber(String 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;

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;
}

public LocalDate getRegisterTime() {
return registerTime;
}

public void setRegisterTime(LocalDate 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 Objects.equals(userId, user.userId) && Objects.equals(userPassword, user.userPassword) && Objects.equals(userPhoneNumber, user.userPhoneNumber) && 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 +
'}';
}
}
65 changes: 65 additions & 0 deletions me.day05.practice/src/Practice02/Users.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package Practice02;

import Practice01.Electronic;
import Practice01.User;
import java.util.Arrays;

public class Users {
private User[] userList;

Choose a reason for hiding this comment

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

List가 변수명에 포함될 필요는 없을 것 같습니다. 심지어 배열이네요~

private static Users instance = new Users();

Choose a reason for hiding this comment

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

static변수, 일반 변수, 생성자, public 메서드, private 메서드 순으로 코드를 작성해주세요.

사소하지만 정말 중요하답니다.

public static Users getInstance(){
if(instance == null){
instance = new Users();
}
return instance;
}

public User findByUserId(String userId){
for (User user : userList){

Choose a reason for hiding this comment

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

Stream으로 해당 동작을 수행하게 해볼까요?

if(user.getUserId().equals(userId)){
return user;
}
}
return null;
}

public User copy(User user){
User userCopy = new User();
userCopy.setUserId(user.getUserId());
userCopy.setUserEmail(user.getUserEmail());
userCopy.setUserPassword(user.getUserPassword());
userCopy.setUserBirthDate(user.getUserBirthDate());
userCopy.setUserPhoneNumber(user.getUserPhoneNumber());
userCopy.setRegisterTime(user.getRegisterTime());
userCopy.setElectronicDevices(user.getElectronicDevices());

Choose a reason for hiding this comment

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

제대로된 깊은 복사가 이루어졌을까요?

return userCopy;
}

public User[] getUserList() {
return userList;
}

public void setUserList(User[] userList) {
this.userList = userList;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Users users = (Users) o;
return Arrays.equals(userList, users.userList);
}

@Override
public int hashCode() {
return Arrays.hashCode(userList);
}

@Override
public String toString() {
return "Users{" +
"userList=" + Arrays.toString(userList) +
'}';
}
}
Loading