I am new to programming and new to posting on this forum so please forgive me if I make any mistakes.
I have the following code:
public class BillsDriver { public static void main(String[] args) { //array of Bills ArrayList<Bills> bills = new ArrayList<Bills>(); ArrayList<Income> income1 = new ArrayList<Income>(); boolean money = true; while(money) { Scanner scan = new Scanner(System.in); System.out.println("Enter income: "); double incomes = scan.nextDouble(); Income thisIncome = new Income(incomes); income1.add(thisIncome); System.out.println("More income?(true/false)"); money = scan.nextBoolean(); } printIncome(income1); boolean more = true; while(more) { Scanner sc = new Scanner(System.in); System.out.println("Enter bill name: "); String name = sc.nextLine(); System.out.println("Enter bill amount: "); double amount = sc.nextDouble(); Bills thisBill = new Bills(name, amount); bills.add(thisBill); System.out.println("More bills?(true/false)"); more = sc.nextBoolean(); } printBill(bills); } public static void printIncome(ArrayList<Income> income) { double totals =0; for(int i=0; i<income.size(); i++) { System.out.println("Income total: " + i + income.get(i).toString()); totals += ((Income)income.get(i)).getTotals(); System.out.println("\tTotal income: \t" + totals); } } public static void printBill(ArrayList<Bills> bills) { //prints out data double total = 0; for(int i = 0; i < bills.size(); i++) { //show ArrayList of bills added by user System.out.println("Bill number: " + (i+1) + ":" + bills.get(i).toString()); //get total amount due total += ((Bills) bills.get(i)).getTotal(); System.out.println("\tTotal amount due: \t" + total); } } }
What I have questions about is how to subtract the total of the Bills ArrayList from the total of the Income ArrayList?