-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBudgetingPage.java
More file actions
61 lines (55 loc) · 2.25 KB
/
BudgetingPage.java
File metadata and controls
61 lines (55 loc) · 2.25 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
57
58
59
60
61
import com.google.gson.annotations.Expose;
import java.util.Scanner;
/**
* Represents a single budgeting page that holds a budget and facilitates user interaction
* for creating budgets. Integrates with budget services and analysis engines to manage and
* analyze budget data, with Gson support for serialization.
*/
public class BudgetingPage {
/** The budget associated with this page, exposed for serialization. */
@Expose
private Budget budget;
/** Shared budget service instance for creating and managing budgets. */
static BudgetService budgetService = new BudgetService();
/** Shared analysis engine for generating spending reports. */
static AnalysisEngine analysis = new AnalysisEngine(budgetService.getDatabase());
/**
* Initializes a budgeting page with a specified budget.
*
* @param budget The budget to associate with this page.
*/
public BudgetingPage(Budget budget) {
this.budget = budget;
}
/**
* Retrieves the budget linked to this budgeting page.
*
* @return The associated budget.
*/
public Budget getBudget() {
return budget;
}
/**
* Runs an interactive session to create a new budget for a user. Prompts for category
* and amount, creates a budget, and triggers spending analysis if creation succeeds.
*
* @param user The user for whom the budget is being created.
*/
public static void run(User user) {
// Initialize scanner for user input
Scanner scanner = new Scanner(System.in);
// Prompt for budget details
System.out.print("Enter budget category (e.g., Transport): ");
String category = scanner.nextLine();
System.out.print("Enter amount: ");
double amount = scanner.nextDouble();
scanner.nextLine();
// Create a new budget and budgeting page
Budget budget = new Budget(amount, category);
BudgetingPage budgetingPage = new BudgetingPage(budget);
// Attempt to create the budget and run analysis if successful
if (budgetService.createBudget(amount, category, user)) {
analysis.generateSpendingAnalysis(user); // Validate and analyze
}
}
}