-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElectronic.java
More file actions
88 lines (70 loc) · 2.34 KB
/
Electronic.java
File metadata and controls
88 lines (70 loc) · 2.34 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
package Practice_03;
import java.util.*;
import java.time.*;
import java.time.format.DateTimeFormatter;
public class Electronic {
public enum Company { SAMSUNG, LG, APPLE }
public enum AuthMethod { FINGERPRINT, PIN, PATTERN, FACE }
private static int registrationNo;
private String productNo;
private String modelName;
private Company company;
private LocalDate dateOfMade;
private AuthMethod[] authMethods;
public Electronic(String modelName, Company company, AuthMethod[] authMethods) {
this.modelName = modelName;
this.company = company;
this.authMethods = authMethods;
this.productNo = generateProductNo();
}
private String generateProductNo() {
String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd"));
registrationNo++;
registrationNo %= 100000;
String registrationNoStr = String.format("%04d", registrationNo);
return date + registrationNoStr;
}
public boolean containsAuthMethod(AuthMethod authMethod) {
return Arrays.asList(authMethods).contains(authMethod);
}
public String getProductNo() {
return productNo;
}
public String getModelName() {
return modelName;
}
public void setModelName(String modelName) {
this.modelName = modelName;
}
public Company getCompany() {
return company;
}
public void setCompany(Company company) {
this.company = company;
}
public LocalDate getDateOfMade() {
return dateOfMade;
}
public AuthMethod[] getAuthMethods() {
return authMethods;
}
public void setAuthMethods(AuthMethod[] authMethods) {
this.authMethods = authMethods;
}
@Override
public int hashCode() {
return Objects.hash(productNo, modelName, company, authMethods);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Electronic that = (Electronic) obj;
return Objects.equals(this.productNo, that.productNo);
}
@Override
public String toString() {
return String.format("Electronic { productNo=%s, modelName=%s, company=%s, authMethods=%s }",
productNo, modelName, company, Arrays.toString(authMethods));
}
}