-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
91 lines (67 loc) · 2.46 KB
/
Main.java
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
package oop.indwes.main;
import java.util.ArrayList;
import java.util.Scanner;
import oop.indwes.entites.Bill;
public class Main {
static void optionsChoice() {
System.out.println("1. Register a new bill. ");
System.out.println("2. List total amount of existing bills.");
System.out.println("3. Exit the program!");
}
public static void main(String[] args) {
int choice;
Scanner options = new Scanner(System.in);
System.out.println("Welcome to your bill management system! Here are your options: ");
System.out.println();
optionsChoice();
choice = options.nextInt();
// ArrayList that keeps track of all the bills
ArrayList<Bill> bills = new ArrayList<Bill>();
double total = bills.stream().mapToDouble(Bill::getBillAmount).sum();
boolean stop = false;
do {
// User is choosing to register a new bill
if (choice == 1) {
Scanner userInput = new Scanner(System.in);
System.out.println();
System.out.println("Please enter the type of the bill and the amount of the bill: ");
String billType = userInput.next();
double billAmount = userInput.nextDouble();
bills.add(new Bill(billType, billAmount));
for (Bill b : bills) {
System.out.println(b.toString());
}
System.out.println();
System.out.println("Thanks for adding a bill! Here are your options:");
optionsChoice();
choice = options.nextInt();
}
// User wants to get the total amount of the bills
if (choice == 2) {
if (bills.size() == 0) {
System.out.println("There are currently no bills.");
System.out.println();
}
else {
if (bills.size() == 1) {
System.out.println("There is currently " + bills.size() + " bill and the total amount is: $" + bills.stream().mapToDouble(Bill::getBillAmount).sum());
}
else {
System.out.println("There are currently " + bills.size() + " bills and the total amount is: $" + bills.stream().mapToDouble(Bill::getBillAmount).sum());
}
}
// User is asked once again if they want to register a bill,
// list total amount of existing bills, or exit the program.
System.out.println("Here are your options:");
optionsChoice();
choice = options.nextInt();
}
// User has quit the application
if (choice == 3) {
System.out.println();
System.out.println("Thanks for playing!");
stop = true;
}
} while (!stop);
}
}