-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElectronic.java
More file actions
105 lines (83 loc) · 2.78 KB
/
Electronic.java
File metadata and controls
105 lines (83 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package me.day05.practice;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Objects;
public class Electronic {
enum CompanyName { SAMSUNG, LG, APPLE }
enum AuthMethod { FINGERPRINT, PIN, PATTERN, FACE }
private static final int MAX_REGISTRATION_NUMBER = 9999;
private static int registrationNo;
private String productNo;
private String modelName;
private CompanyName companyName;
private String dateOfMade;
private AuthMethod[] authMethod;
Electronic () {
registrationNo++;
setDateOfMade();
setProductNo();
}
Electronic (String modelName, CompanyName companyName, AuthMethod[] authMethod) {
this();
this.modelName = modelName;
this.companyName = companyName;
this.authMethod = authMethod;
}
private void setDateOfMade(){
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyMMdd");
dateOfMade = timeFormatter.format(LocalDate.now());
}
private void setProductNo(){
if (registrationNo > MAX_REGISTRATION_NUMBER) registrationNo = 1;
productNo = dateOfMade + String.format("%4d", registrationNo).replace(" ", "0");
}
public boolean isContainsAuthMethod(AuthMethod authMethod){
for (AuthMethod auth : this.authMethod)
if (authMethod.equals(auth)) return true;
return false;
}
public String getProductNo() {
return 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 String getDateOfMade() {
return dateOfMade;
}
public AuthMethod[] getAuthMethod() {
return authMethod;
}
public void setAuthMethod(AuthMethod[] authMethod) {
this.authMethod = authMethod;
}
@Override
public int hashCode() {
return Objects.hash(productNo, modelName, companyName, dateOfMade, Arrays.hashCode(authMethod));
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
return Objects.equals(productNo, ((Electronic)obj).productNo);
}
@Override
public String toString() {
return "Electronic { " +
"productNo=" + productNo +
", modelName=" + modelName +
", companyName= " + companyName +
", dateOfMade=" + dateOfMade +
", authMethod=" + Arrays.toString(authMethod) + " }";
}
}