-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathVisit.java
More file actions
26 lines (21 loc) · 737 Bytes
/
Visit.java
File metadata and controls
26 lines (21 loc) · 737 Bytes
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
package org.codedifferently;
public class Visit {
String name;
String receiptCode;
public Visit(String name) {
this.name = name;
}
// Generate receipt code: first 2 letters of name + random 4-digit number
public void generateReceiptCode() {
int visitId = (int) (Math.random() * 9000) + 1000;
receiptCode = name.substring(0, Math.min(2, name.length())).toUpperCase() + visitId;
}
// Check if final total is within the user's budget
public boolean checkBudget(double finalTotal, double budget) {
return finalTotal <= budget;
}
// Print the receipt code
public void printReceiptCode() {
System.out.println("Receipt Code: " + receiptCode);
}
}