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 TaeIlKIm #13

Open
wants to merge 2 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
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.

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.

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.

108 changes: 108 additions & 0 deletions src/practice01/Electronic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package src.practice01;

import src.practice01.db.AuthMethod;
import src.practice01.db.Company;

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

public class Electronic {
private static int serialNumber = 0;

String productNo;
Copy link

Choose a reason for hiding this comment

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

접근제한자가 없는 이유가 있을까요?

String modelName;
Company companyName;
LocalDate dateOfMade;
ArrayList<AuthMethod> authMethods = new ArrayList<>();

public Electronic (
String productNo, String modelName,
Company companyName, LocalDate dateOfMade,
AuthMethod auth

) {
LocalDate today = LocalDate.now();


serialNumber++;
this.modelName = modelName;

this.productNo = today.format(DateTimeFormatter.ofPattern("yyMMdd"));
this.productNo += String.format("%04d", serialNumber);
this.companyName = companyName;
authMethods.add(auth);
Copy link

Choose a reason for hiding this comment

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

authMethods도 리스트로 받는것이 좋지 않을까요?

}

public static int getSerialNumber() {
return serialNumber;
}

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 LocalDate getDateOfMade() {
return dateOfMade;
}

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

public ArrayList<AuthMethod> getAuthMethods() {
return authMethods;
}

public void setAuthMethods(ArrayList<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) &&
Objects.equals(authMethods, that.authMethods);
}

@Override
public int hashCode() {
return Objects.hash(productNo, modelName, companyName, dateOfMade, authMethods);
}

@Override
public String toString() {
return "Electronic{" +
"productNo='" + productNo + '\'' +
", modelName='" + modelName + '\'' +
", companyName=" + companyName +
", dateOfMade=" + dateOfMade +
", authMethods=" + authMethods +
'}';
}
}
116 changes: 116 additions & 0 deletions src/practice01/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package src.practice01;

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

public class User {
private String userId;
private String userPassword;
private String userPhoneNumber;
private String userEmail;
private String userBirthDate;
private ArrayList<Electronic> electronicDevices = new ArrayList<>();
private LocalDate registerTime;

public User() {}

public User (
String userId,
String userPassword,
String userPhoneNumber,
String userEmail,
String userBirthDate

Copy link

Choose a reason for hiding this comment

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

electronicDevices 는 빠진 이유가 있을까요?

) {
this.userId = userId;
this.userPassword = userPassword;
this.userPhoneNumber = userPhoneNumber;
this.userEmail = userEmail;
this.userBirthDate = userBirthDate;
}
Copy link

Choose a reason for hiding this comment

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

registerTime 셋팅하는 부분이 빠졌네요.


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 ArrayList<Electronic> getElectronicDevices() {
return electronicDevices;
}

public void setElectronicDevices(ArrayList<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) &&
Objects.equals(userPassword, user.userPassword) &&
Objects.equals(userPhoneNumber, user.userPhoneNumber) &&
Objects.equals(userEmail, user.userEmail) &&
Objects.equals(userBirthDate, user.userBirthDate) &&
Objects.equals(electronicDevices, user.electronicDevices) &&
Objects.equals(registerTime, user.registerTime);
}

@Override
public int hashCode() {
return Objects.hash(userId, userPassword,
userPhoneNumber, userEmail, userBirthDate,
electronicDevices, registerTime);
}

@Override
public String toString() {
return "User{" +
"userId='" + userId + '\'' +
", userPassword='" + userPassword + '\'' +
", userPhoneNumber='" + userPhoneNumber + '\'' +
", userEmail='" + userEmail + '\'' +
", userBirthDate='" + userBirthDate + '\'' +
", electronicDevices=" + electronicDevices +
", registerTime=" + registerTime +
'}';
}
}
8 changes: 8 additions & 0 deletions src/practice01/db/AuthMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package src.practice01.db;

public enum AuthMethod {
FINGERPRINT,
PATTERN,
PIN,
FACE
}
8 changes: 8 additions & 0 deletions src/practice01/db/Company.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package src.practice01.db;

public enum Company {
SAMSUN,
LG,
APPLE

}
68 changes: 68 additions & 0 deletions src/practice02/Users.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package src.practice02;

import src.practice01.User;

import java.util.ArrayList;
import java.util.Objects;

public class Users {
private ArrayList<User> userList = new ArrayList<>();

// 싱글톤
private static Users instance;
public Users() {}
Copy link

Choose a reason for hiding this comment

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

public 으로 객체가 생성하면 싱글톤이 아니지 않을까요?

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

public ArrayList<User> getUserList() {
return userList;
}

public void setUserList(ArrayList<User> userList) {
this.userList = userList;
}

public User findByUserId(String userId) {
for (User user : userList) {
if (userId.equals(user.getUserId())) {
Copy link

Choose a reason for hiding this comment

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

equals 비교 👍

return user;
}
}
return null;
}

public User Copy(User user) {
User copyUser = new User();
copyUser.setUserId(user.getUserId());
copyUser.setUserPassword(user.getUserPassword());
copyUser.setUserEmail(user.getUserEmail());
copyUser.setUserPhoneNumber(user.getUserPhoneNumber());
copyUser.setUserBirthDate(user.getUserBirthDate());
copyUser.setElectronicDevices(user.getElectronicDevices());
Copy link

Choose a reason for hiding this comment

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

electronicDevices 는 깊은 복사가 되었을까요?

return copyUser;
}

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

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

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