Skip to content

Java Assignment3 upload by MiyeonLee #27

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

Open
wants to merge 5 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
10 changes: 10 additions & 0 deletions Assignment3/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-19">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions Assignment3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions Assignment3/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Assignment3</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
14 changes: 14 additions & 0 deletions Assignment3/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=19
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=19
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=19
3 changes: 3 additions & 0 deletions Assignment3/src/me/day05/practice/Practice01/AuthMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package me.day05.practice.Practice01;

public enum AuthMethod { FINGERPRINT, PATTERN, PIN, FACE } //제품 본인인증 방법
3 changes: 3 additions & 0 deletions Assignment3/src/me/day05/practice/Practice01/Company.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package me.day05.practice.Practice01;

public enum Company {SAMSUNG, LG, APPLE } //제조 회사명
91 changes: 91 additions & 0 deletions Assignment3/src/me/day05/practice/Practice01/Electronic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package me.day05.practice.Practice01;

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

public class Electronic {
private String productNo;
private static int serialNum = 0;
private String modelName;
private Company companyName;
private String dateOfMade;
private AuthMethod[] authMethod;


public Electronic(){
serialNum++;
productNo = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd")) + String.format("%04d",serialNum);
}

public Electronic(String modelName, Company companyName, String dateOfMade, AuthMethod[] authMethod) {
serialNum++;
Copy link

Choose a reason for hiding this comment

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

중복 코드를 줄여보세요.

this.productNo = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd")) + String.format("%04d", serialNum);
this.modelName = modelName;
this.companyName = companyName;
this.dateOfMade = dateOfMade;
this.authMethod = authMethod;

}

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

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Electronic)) return false;

Electronic electronic = (Electronic) obj;
return (this.productNo == electronic.productNo) || (this.modelName == electronic.modelName)
|| (this.dateOfMade == electronic.dateOfMade) || (this.companyName == electronic.companyName)
|| (this.authMethod.equals(electronic.authMethod));
}

@Override
public String toString() {
return "electronic{productNo:" + productNo +
", modelName:" + modelName +
", companyName:" + companyName +
", dateOfMade:" + dateOfMade +
", authMethod:" + Arrays.toString(authMethod) + "}";
}


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

public void setDateOfMade(String dateOfMade) {
this.dateOfMade = dateOfMade;
}
public void setCompanyName(Company companyName){
this.companyName = companyName;
}
public Company getCompanyName(){
return companyName;
}

public AuthMethod[] getAuthMethod() {
return authMethod;
}

public void setAuthMethod(AuthMethod[] authMethod) {
this.authMethod = authMethod;
}
}
115 changes: 115 additions & 0 deletions Assignment3/src/me/day05/practice/Practice01/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package me.day05.practice.Practice01;

import java.time.LocalTime;
import java.util.Objects;

public class User {

private String userId;
private String userPassword;
private int userPhoneNumber;
private String userEmail;
private int userBirthDate;
private String[] electronicDevices;
public LocalTime registerTime;
Copy link

Choose a reason for hiding this comment

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

과제는 LocalDate 를 사용하라고 나와있는데 LocalTime 를 사용하고 있네요.

Copy link
Author

@miyounlee miyounlee Apr 26, 2023

Choose a reason for hiding this comment

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

Electronic 클래스의 productNo은 LocalTime을 사용하라고 언급되어 있는데
User클래스의 registerTime에 대해선 언급이 없는 것 같습니다!

근데 멘토님 코멘트 보고 생각해보니, 회원정보 등록 시간에 대한 필드니까 날짜와 시간이 같이 출력되도록 하는 것이 좋을 것 같습니다. 참고해서 수정해보겠습니다.🤓



public User(){
registerTime = LocalTime.now();
}

public User(String userId, String userPassword, int userPhoneNumber, String userEmail, int userBirthDate,
String[] electronicDevices) {
this.userId = userId;
this.userPassword = userPassword;
this.userPhoneNumber = userPhoneNumber;
this.userEmail = userEmail;
this.userBirthDate = userBirthDate;
this.electronicDevices = electronicDevices;
this.registerTime = LocalTime.now();
}


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

@Override
public boolean equals(Object obj) {
if (!(obj instanceof User))
return false;

User user = (User) obj;
return (this.userId == user.userId) || (this.userPassword == user.userPassword)
|| (this.userPhoneNumber == user.userPhoneNumber) || (this.userEmail == user.userEmail)
|| (this.userBirthDate == user.userBirthDate) || (this.electronicDevices == user.electronicDevices)
|| (this.registerTime == user.registerTime);
}

@Override
public String toString() {
return "User{userId:" + userId +
", userPassword:" + userPassword +
", userPhonNumber:" + userPhoneNumber +
", userEmail:" + userEmail +
", userBirthDat:" + userBirthDate +
", electronicDevice:" + electronicDevices +
", registerTime:" + 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 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 String[] getElectronicDevices() {
return electronicDevices;
}

public void setElectronicDevices(String[] electronicDevices) {
this.electronicDevices = electronicDevices;
}

public LocalTime getTime() {
return this.registerTime;
}
}
60 changes: 60 additions & 0 deletions Assignment3/src/me/day05/practice/Practice02/Users.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package me.day05.practice.Practice02;

import me.day05.practice.Practice01.User;

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

public class Users {

private User[] userList;
private static Users instance;

private Users() {}

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

return instance;
}

User findByUserId(String userId) {
Copy link

Choose a reason for hiding this comment

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

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

for(User user : userList) {
if(user.getUserId().equals(userId))
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;
}

User copy(User user) {
User userCopy = new User(user.getUserId(), user.getUserPassword(), user.getUserPhoneNumber()
Copy link

Choose a reason for hiding this comment

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

registerTime 도 복사해야 하지 않을까요?

, user.getUserEmail(), user.getUserBirthDate(), user.getElectronicDevices());
Copy link

Choose a reason for hiding this comment

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

.getElectronicDevices() 의 데이터를 변경하면 어떻게 될까요?

return userCopy;
}

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

@Override
public boolean equals(Object obj) {
if(!(obj instanceof Users)) return false;

Users list = (Users)obj;
return Arrays.equals(userList, list.userList);
}

@Override
public String toString() {
return "{userList:" + Arrays.toString(userList) + "}";
}

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

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