Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
44 lines (40 loc) · 1.38 KB
/
Copy pathMain.java
File metadata and controls
44 lines (40 loc) · 1.38 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
import java.util.ArrayList;
import java.util.List;
import model.Expense;
public class Main {
private static List<Expense> expenses = new ArrayList<>();
private static int nextId = 1;
public static void main(String[] args) {
String command = args[0];
switch (command) {
case "add":{
String name = args[1];
float amount = Float.parseFloat(args[2]);
Expense expense = new Expense(name, amount);
expenses.add(expense);
System.out.println("Expense added successfully.");
break;
}
case "list": {
for (Expense expense : expenses) {
System.out.println(expense.getName() + " - $" + expense.getAmount());
}
break;
}
case "delete": {
int idToDelete = Integer.parseInt(args[1]) - 1;
if (idToDelete >= 0 && idToDelete < expenses.size()) {
expenses.remove(idToDelete);
System.out.println("Expense deleted successfully.");
} else {
System.out.println("Invalid expense ID.");
}
break;
}
default: {
System.out.println("Invalid command.");
break;
}
}
}
}