info@meritcampus.com    +91-85006-22255
...

Write a program to calculate the balance at the end of day. The initial balance and the list of transactions are given. If credit, then the balance will increase, else it will decrease by the given amount.

Input (List, double) Output (double)
{[500, true], [800, false], [600, false]}, 1000.0 100.0
{[10000, false], [8000, false], [14000, true], [4000, true]}, 28000.0 28000.0
{[100, true], [200, true], [200, false], [100, true], [50, false]}, 300.0 450.0
{[5000, true], [8000, false]}, 6000.0 3000.0

``` import java.util.*; class CalculateEndOfDayBalance {     public static void main(String s[])    {        ArrayList<Transaction> input = new ArrayList<Transaction>();        input.add(new Transaction(20000, true));        input.add(new Transaction(5000, false));        input.add(new Transaction(8000, false));        input.add(new Transaction(1000, true));        input.add(new Transaction(200, false));        input.add(new Transaction(1000, false));        input.add(new Transaction(5000, true));        int initialBalance = 25000;        System.out.println("The balance at end of the day is : " + calculateBalance(input, initialBalance));    }     public static double calculateBalance(List<Transaction> transactions, int initialBalance) { ```
```     } } class Transaction { double amount; boolean isCredit; public Transaction(double amount, boolean isCredit) { this.amount = amount; this.isCredit = isCredit; } } ```

Topic: Java ArrayList

0
Wrong
Score more than 2 points