Code with Vinay

ISC practical papers › ISC 2010 › Question 1

Denomination breakup

ISC 2010 Computer Science Practical, Question 1 · Number programs

The question

A bank intends to design a program to display the denomination of an input amount of upto five digits. The available denomination with the bank are of rupees 1000, 500, 100, 50, 20, 10, 5, 2, 1.

Design a program to accept the amount from the user and display the breakup in descending order of denomination, (i.e. preference shoud be given to the highest denomination available) along with the total number of notes. [Note: Only the denominations used should be displayed.] Also print the amount in words according to the digits.

Example 1
INPUT:  14856
OUTPUT: ONE FOUR EIGHT FIVE SIX
        DENOMINATION
        1000    x   14          =   14000
        500     x   1           =     500
        100     x   3           =     300
        50      x   1           =      50
        5       x   1           =       5
        1       x   1           =       1
        TOTAL                   =   14586
        TOTAL NUMBER OF NOTES   =      21

Question: ISC 2010 Computer Science Paper 2 (Practical), Question 1, set by the Council for the Indian School Certificate Examinations (CISCE). Solution and video: Vinay Singh.

Java solution

ISC2010Q1.java Download GitHub
import java.util.*;
class Amount{
    private int amount;
    private String output;
    private static String digit[]={"ZERO","ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"};
    private static int notes[]={1000, 500, 100, 50, 20, 10, 5, 2, 1};
    public Amount(int amount){
        this.amount=amount;
        output="";
        digitsToWord();
    }
    public String toString(){
        return output;
    }

    public void digitsToWord(){
        for( int temp=amount;temp>0;temp/=10){
            output=digit[temp%10]+" "+output;
        }
        output=output.trim();
    }
    public void showDenomination(){
        System.out.println("\tDENOMINATION");
        int quantity, amt=amount,noteCount=0;
        for( int note:notes){
            quantity=amt/note;
            if(quantity>0){
                System.out.printf("\t%-8d x %-13d = %9d\n",note, quantity,(note*quantity));
                noteCount+=quantity;
            }
            amt%=note;
        }
        System.out.printf("\tTOTAL                   =  %9d\n",amount);
        System.out.printf("\tTOTAL NUMBER OF NOTES   =  %9d\n", noteCount);
    }
}
class ISC2010Q1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("INPUT:\t");
        int amount = in.nextInt();
        Amount amt = new Amount(amount);
        System.out.println("OUTPUT:\t"+amt);
        amt.showDenomination();
        in.close();
    }
}

All these solutions in one free book

Pragmatic Solutions to ISC Computer Science Practical Problems collects every program from 2004 to 2021 in a 202-page PDF.

Get the free PDF ₹0 ISC 2027 mock papers