-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBudgetManager.java
More file actions
107 lines (88 loc) · 5.2 KB
/
BudgetManager.java
File metadata and controls
107 lines (88 loc) · 5.2 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import java.util.Scanner; // استخدمناه عشان ناخد input من ال user
public class BudgetManager { // اسم ال class ولازم يبقي نفس اسم الملف
public static void main(String[] args) { // ال function اللي بنكتب جواها الكود
Scanner input = new Scanner(System.in);
boolean runAgain = true; // عشان اعيده اكتر من مرة
System.out.println("===Welcome to Budget Manager==="); // جمله الطباعة زي ال cout في ++c
while (runAgain){
System.out.print("Enter your monthly income: ");
int income = input.nextInt(); // باستخدام السطر ده ال user بيدخل دخله الشهري
System.out.print("How many expenses do you have? ");
int n = input.nextInt(); // باستخدام السطر ده بطلب منه يقولي عدد المصاريف
double[] expenses = new double[n]; // عملنا Array عشان نخزن فيه المصاريف
String[] categories = new String[n]; //Array تاني عشان نخرن نوع كل مصروف
double foodTotal = 0;
double transportTotal = 0;
double billsTotal = 0;
double otherTotal = 0;
double maxExpense = 0; // اكبر حاجه صرف عليها
for (int i = 0; i < n; i++) {
System.out.print("Enter expense amont " + (i + 1) + ": "); // عملت loops عشان ادخل كل مصروف لوحده
expenses[i] = input.nextDouble(); // عشان اخزن كل المصروفات اللي دخلتها
if (expenses[i] > maxExpense) { // بتقارن كل مصروف باللي قبله عشان لو في حاجه اكبر تخزنها كأكبر مصروف
maxExpense = expenses[i];
}
System.out.println("Select category: ");
System.out.println("1- Food");
System.out.println("2- Transport");
System.out.println("3- Bills");
System.out.println("4- Other");
int choice = input.nextInt();
switch (choice) {
case 1:
categories[i] = "Food";
foodTotal += expenses[i];
break;
case 2:
categories[i] = "Transport";
transportTotal += expenses[i];
break;
case 3:
categories[i] = "Bills";
billsTotal += expenses[i];
break;
default:
categories[i] = "Other";
otherTotal += expenses[i];
}
}
double totalExpenses = calculateTotal(expenses); // بيحسب كل المصاريف
double remaining = income - totalExpenses; // بيطرح المصاريف من الدخل و يقول متبقي كام
double savingsPercent = (remaining / income) * 100; // ببحسب نسبة الادخار
System.out.println("\n=== Monthly Report ===");
System.out.println("Total Expenses: " + totalExpenses);
System.out.println("Remaining Balance: " + remaining);
System.out.println("Savings Percentage: " + savingsPercent + "%");
System.out.println("\nCategory Breakdown:");
System.out.println("Food: " + foodTotal);
System.out.println("Transport: " + transportTotal);
System.out.println("Bills: " + billsTotal);
System.out.println("Other: " + otherTotal);
System.out.println("\nHighest Expense: " + maxExpense);
showFinancialStatus(savingsPercent);
System.out.print("\nDo you want to calculate again? (true/false): ");
runAgain = input.nextBoolean(); // ال user عايز يعيد و لا يقفل
}
input.close();
}
// لحساب مجموع كل المصاريف
public static double calculateTotal(double[] arr) {
double sum = 0;
for (double value : arr) {
sum += value;
}
return sum;
}
// لتقيم الوضع المالي
public static void showFinancialStatus(double savingsPercent) {
if (savingsPercent >= 30) {
System.out.println("Status : Excellent Financial Control !");
} else if (savingsPercent >= 10) {
System.out.println("Status: Stable, but can improve.");
} else if (savingsPercent >= 0) {
System.out.println("Status: Risky spending behavior.");
} else {
System.out.println("Status: Critical! You are spending more than you earn.");
}
}
}