ISC computer practical paper 2010 Question 1 solved

ISC computer practical paper 2010 Question 1 solved

Question 1 
A bank intends to design a program to display the denomination of an input amount, up to 5 digits. The available denomination with the bank are of rupees 1000 , 500 , 100 , 50 , 20 , 10 , 5 , 2 , and 1.
Design a program to accept the amount from the user and display the break-up in descending order of denomination. (i.e. preference should be given to the highest denomination available) along with the total number of notes. [Note: Only the denomination 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                      =          14856
TOTAL NUMBER OF NOTES  =          21

Solution.
First Version the program with using method or function
// ISC 2010 practical Exam solution
import java.io.*;
public class Bank
{
    public static void main(String args[]) throws IOException
    {
        int rev = 0, amount, temp, rem;
        int denomination[] = {1000, 500, 100, 50, 20, 10, 5, 2, 1};
        String denomiation1[] = {" Zero"," One", " Two", " Three", " Four", " Five", " Six",
                " Seven", " Eight", " Nine"};
        int i, totalNotes = 0;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the Amount:");
        amount=Integer.parseInt(br.readLine());
        // Checking for the entered amount not more then 100000
        if(amount >99999)
        {
            System.out.println("Invalid Amount…");
            return;
        }
        temp = amount;
        // Reverse the amount, example 3456 into 6543
        // for displaying as THREE FOUR FIVE SIX
        while(temp !=0)
        {
            rev=rev*10+temp%10;
            temp=temp/10;
        }
        System.out.print("Amount in words :");
        // Display the note in words
        while(rev!=0)
        {
            rem=rev%10; // Mod division for reminder
            for(i=0;i<10;i++)
            {
                if(rem==i)
                    System.out.print(denomiation1[i]);
            }

            rev=rev/10; // Ineger division
        }
        i = 0;
        // Display the denominators notes   
        System.out.print("\n\nDENOMINATION:\n");
        System.out.print("============:\n");
        while (amount!=0)
        {
            rev=amount/denomination[i];
            if(rev!=0)
            {
                System.out.println(denomination[i]+"\t X " + rev + "\t\t\t= " + rev*denomination[i]);
                totalNotes+=rev;
            }
            amount=amount % denomination[i];
            i++;
        }
        System.out.println("TOTAL NUMBER OF NOTES:  " + totalNotes);
    }

}
Output Sample :
Enter the Amount:
15475
Amount in words : One Five Four Seven Five

DENOMINATION:
============:
1000    X 15                            = 15000
100      X 4                              = 400
50        X 1                              = 50
20        X 1                              = 20
5          X 1                              = 5
TOTAL NUMBER OF NOTES:  22



Second Version the program with using method or function
// ISC 2010 practical Exam Question 1 solution
import java.io.*;
public class DenominationominationOfAmount
{
    // Instance Variable
    int rev, amount, temp, rem;
    int denomination[] = new int[10];;
    int i, totalNotes;
    public DenominationominationOfAmount()
    {
        // Use to initialize the instance variable
        rev = 0; // for reverse number
        i = 0;  
        totalNotes = 0;
        denomination =new int[]{1000, 500, 100, 50, 20, 10, 5, 2, 1};
    }

    public void input() throws IOException
    {

        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the Amount:");
        amount=Integer.parseInt(br.readLine());
    }

    void calculate()
    {
        // Checking for the entered amount not more then 100000
        if(amount >99999)
        {
            System.out.println("Invalid Amount…");
            return;
        }
        temp = amount;
        // Reverse the amount, example 3456 into 6543
        // for displaying as THREE FOUR FIVE SIX
        while(temp !=0)
        {
            rev=rev*10+temp%10;
            temp=temp/10;
        }
        System.out.print("Amount in words :");
        // Display the note in words
        while(rev!=0)
        {
            rem=rev%10; // Mod division for reminder
            switch(rem)
            {
                case 0:
                System.out.print(" ZERO");
                break;
                case 1:
                System.out.print(" ONE");
                break;
                case 2:
                System.out.print(" TWO");
                break;
                case 3:
                System.out.print(" THREE");
                break;
                case 4:
                System.out.print(" FOUR");
                break;
                case 5:
                System.out.print(" FIVE");
                break;
                case 6:
                System.out.print(" SIX");
                break;
                case 7:
                System.out.print(" SEVEN");
                break;
                case 8:
                System.out.print(" EIGHT");
                break;
                case 9:
                System.out.print(" NINE");
            }
            rev=rev/10; // Ineger division
        }
        // Display the denominators notes   
        System.out.print("\n\nDENOMINATION:\n");
        System.out.print("============:\n");
        while (amount!=0)
        {
            rev=amount/denomination[i];
            if(rev!=0)
            {
                System.out.println(denomination[i]+"\t X " + rev + "\t\t\t= " + rev*denomination[i]);
                totalNotes+=rev;
            }
            amount=amount % denomination[i];
            i++;
        }
        System.out.println("TOTAL NUMBER OF NOTES:  "+ totalNotes);
    }

    public static void main(String args[])throws IOException
    {
        // Object ob creation
        DenominationominationOfAmount ob = new DenominationominationOfAmount();
        ob.input();     // Call input() method
        ob.calculate(); // Call calculate method
    }

}

Sample output of second version
Enter the Amount:
1235
Amount in words : ONE TWO THREE FIVE

DENOMINATION:
============:
1000    X 1                              = 1000
100      X 2                              = 200
20        X 1                              = 20
10        X 1                              = 10
5          X 1                              = 5


TOTAL NUMBER OF NOTES:  6

ISC Best Book


More program

Java program for Niven or Harshad number




SHARE THIS
Previous Post
Next Post