-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddExpenseCommand.java
More file actions
30 lines (27 loc) · 1.01 KB
/
AddExpenseCommand.java
File metadata and controls
30 lines (27 loc) · 1.01 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
public class AddExpenseCommand implements Command {
private BudgetManager manager;
private double amount;
private String description;
private String currency;
private double convertedAmount;
private String category; // Added category
public AddExpenseCommand(BudgetManager manager, double amount, String description, String currency, double convertedAmount, String category) {
this.manager = manager;
this.amount = amount;
this.description = description;
this.currency = currency;
this.convertedAmount = convertedAmount;
this.category = category; // Initialize category
}
@Override
public void execute() {
manager.addExpense(amount, description, currency, convertedAmount, category); // Pass category
}
@Override
public void undo() {
boolean success = manager.removeExpense(description, convertedAmount);
if (!success) {
System.out.println("Undo failed: Expense not found.");
}
}
}