-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetIncomeCalculator.java
More file actions
38 lines (26 loc) · 1.09 KB
/
NetIncomeCalculator.java
File metadata and controls
38 lines (26 loc) · 1.09 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
package calculator;
import java.util.Arrays;
import java.util.Scanner;
public class NetIncomeCalculator {
static final Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
String[] items = new String[] { "Bubblegum", "Toffee", "Ice cream", "Milk chocolate", "Doughnut", "Pancake" };
int[] prices = new int[] { 202, 118, 2250, 1680, 1075, 80 };
System.out.println("Earned amount:");
for (int i = 0; i < items.length; i++) {
System.out.printf("%s: $%d", items[i], prices[i]);
System.out.println();
}
System.out.println();
int income = Arrays.stream(prices).sum();
System.out.printf("Income: $%d\n", income);
int staffExpenses = getIntInput("Staff expenses");
int additionalExpenses = getIntInput("Other expenses");
int netIncome = income - staffExpenses - additionalExpenses;
System.out.printf("Net income: %d", netIncome);
}
static int getIntInput(String message) {
System.out.println(message + ":");
return sc.nextInt();
}
}