-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBobbyPatient.java
More file actions
56 lines (45 loc) · 1.74 KB
/
BobbyPatient.java
File metadata and controls
56 lines (45 loc) · 1.74 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
package org.codedifferently;
import java.util.Random;
// Defines the BobbyPatient class that stores customer information and generates unique IDs.
public class BobbyPatient {
// Stores the customer’s full name.
private String name;
// Stores the customer’s phone number.
private String phoneNumber;
// Stores the unique patient ID that remains constant after creation.
private final String customerId;
/* Constructor to instantiates a new BobbyPatient object using the provided name and phone number.
Generates and assigns a unique customer ID during object creation. */
public BobbyPatient(String name, String phoneNumber) {
this.name = name;
this.phoneNumber = phoneNumber;
this.customerId = generateCustomerId(new Random());
}
// Returns the customer’s name.
public String getName() {
return name;
}
// Returns the customer’s phone number.
public String getPhoneNumber() {
return phoneNumber;
}
// Returns the customer’s unique ID.
public String getCustomerId() {
return customerId;
}
// Generates a unique customer ID using the first three letters of the name and a random five-digit number.
public String generateCustomerId(Random random) {
String prefix;
if (name.length() >= 3) {
prefix = name.substring(0, 3).toUpperCase();
} else {
prefix = name.toUpperCase();
}
return prefix + random.nextInt(10000, 100000);
}
// Returns a formatted string representation of the customer’s information.
@Override
public String toString() {
return "\n(Name: " + name + ", Phone: " + phoneNumber + ", Customer Id: " + customerId + ")";
}
}