Menu
Question Index
...


Given the currency notes in a cash box, write a program to select which notes should be dispensed to return an amount. When returning, higher preference should be given to larger notes.

Input (List, int) Output (List)
[0], 1 null
[1, 2, 4], 1 [1]
[2, 4, 4, 5, 8], 16 [4, 4, 8]
[1, 2, 4, 20, 40 , 60], 70 null
[2, 4, 5, 6, 15, 20, 30, 45, 70], 90 [20, 70]
[2, 4, 6, 20, 30, 70, 120, 200, 400, 500], 1000 [30, 70, 400, 500]
[100, 500, 342, 12, 6, 1], 443 [1, 100, 342]
[92, 89, 91, 6, 7, 8, 10, 30], 220 [7, 30, 91, 92]
[191, 236, 432, 409, 698], 889 [191, 698]
[1, 1, 1, 1, 1, 6, 6, 6, 6, 6, 6, 12, 90, 100, 800, 800, 1200, 600, 1600, 1900], 3109 [1, 1, 1, 6, 1200, 1900]

class DispenseCash

{    public static void main(String s[])
    {
        List currencyNotes = new ArrayList();
        currencyNotes.add(2);
        currencyNotes.add(4);
        currencyNotes.add(4);
        currencyNotes.add(5);
        currencyNotes.add(8);
        List output = dispense(currencyNotes, 16);
        System.out.println("The notes to be returned are : " + output);

    }


public static List<Integer> dispense(List<Integer> currencyNotes, int amount) {
//Write code here to identify the currency notes which have to be returned for the dispensing the requested amount
}

//If required, write any additional methods here
}

Doubts

Problems

Topic: Collection Framework In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App