-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomer.java
123 lines (107 loc) · 2.63 KB
/
Customer.java
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Program: Customer
* Purpose: Customer is an abstract superclass, it also had a abstract method incentives()
* Date: 22 June 2021
* @author Yug Shah
*/
public abstract class Customer {
private String firstName;
private String lastName;
private String customerID;
private String customerLevel;
/**
*
* @param firstName First Name of Customer
* @param lastName Last Name of Customer
* @param customerLevel The type of Customer
*/
public Customer(String firstName, String lastName, String customerLevel) {
this.firstName = firstName;
this.lastName = lastName;
this.customerLevel = customerLevel;
setCustomerID();
}
/**
*
* @return Returns firstName
*/
public String getFirstName() {
return this.firstName;
}
/**
*
* @return Returns lastName
*/
public String getLastName() {
return this.lastName;
}
/**
*
* @return Returns customerID
*/
public String getCustomerID() {
return this.customerID;
}
/**
*
* @return Returns customerLevel
*/
public String CustomerLevel() {
return this.customerLevel;
}
/**
*
* @param firstName First Name of Customer
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
*
* @param lastName Last Name of Customer
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* Assigns the customerID with the first 4 letter of the last name following with the 4 digit
* random number
*/
private void setCustomerID() {
String fourCust = "";
int randNum = (int) (10000 + Math.random() * 99999);
if (this.lastName.length() == 1) {
fourCust = this.lastName.toUpperCase().substring(0, 1) + "XXX";
}
if (this.lastName.length() == 2) {
fourCust = this.lastName.toUpperCase().substring(0, 2) + "XX";
}
if (this.lastName.length() == 3) {
fourCust = this.lastName.toUpperCase().substring(0, 3) + "X";
}
if (this.lastName.length() == 4 || this.lastName.length() > 4) {
fourCust = this.lastName.toUpperCase().substring(0, 4);
}
this.customerID = fourCust + "-" + randNum;
}
/**
*
* @param customerLevel The type of Customer
*/
public void setCustomerLevel(String customerLevel) {
this.customerLevel = customerLevel;
}
/**
*
* @return incentives() is a abstract method which must be
* initiated in the sub-classes not in the superclass
*/
public abstract double incentives();
/**
*
* @return toString()
*/
public String toString() {
return getCustomerID() + ", " + this.firstName + " " + this.lastName;
}
}//end class