Repository navigation
Expand file tree
/
Copy pathBudget Analysis
More file actions
55 lines (34 loc) · 1.39 KB
/
Copy pathBudget Analysis
File metadata and controls
55 lines (34 loc) · 1.39 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
import java.io.IOException;
import java.util.Scanner;
/**
*
* @author Tutor
*/
public class BudgetAnalysis
{
public static void main(String[] args) throws IOException
{
int number = 0;
double max=0,min=0, expenses =0.0 ,totalExpenses =0.0 ;
//Creats Scanner Object for keyboard input
Scanner input = new Scanner (System.in);
// Get user's budget amount
System.out.println(" Enter the amount of your budget for the month. ");
double budget = input.nextDouble();
// Gets the number of expenses the user has
System.out.println("How many expeneses do you have for the month? ");
number=input.nextInt();
// loop to calculate the total expense
for(int i=0 ; i < number ;i++){
System.out.println("Enter the amount of each of your expenses for the month. ");
expenses = input.nextDouble();
totalExpenses += (expenses) ;
}
if ( budget < totalExpenses ) {
System.out.println( " Over Budget by :" + (budget - totalExpenses ));
}
else { System.out.println( " You're under budget by : " + (budget-totalExpenses ));
}
System.exit(0);
}
}