Thursday 19 January 2017

Bank...

A bank intends to design a program to display the denomination of an
input amount, upto 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 denominations. (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.

INPUT:                            14836
OUTPUT:               ONE FOUR EIGHT THREE 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:-
import java.util.*;
public class Bank
{
    public static void main(String args[])
     {
      Scanner sc=new Scanner(System.in);
         System.out.print("Enter the amount:");
         int amt=sc.nextInt();
         String s=""+amt;
         int l=s.length();
         if(l>5)
           System.out.println("INVALID AMOUNT");
           else
           {
               int n=amt;
               int rev=0,total=0,totaln=0,div;
               String word[]={"ZERO","ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"};
               int notes[]={1000,500,100,50,20,10,5,2,1};
               while(n>0) //reverses the number
               {
                   rev=(rev*10)+(n%10);
                   n=n/10;
                }
                while(rev>0) //to print the number in words
                {
                    System.out.print(word[rev%10]+" ");
                    rev=rev/10;
                }
               System.out.println();
                System.out.println("DENOMINATION:");
                for(int i=0;i<9;i++) //to display denomination
                 {
                     div=amt/notes[i];
                     amt=amt%notes[i];
                     if(div>0)
                      {
                        System.out.println(notes[i]+"\tX\t"+div+"\t=\t"+(notes[i]*div));
                        total+=notes[i]*div;
                        totaln+=div;
                    }
                }
                 System.out.println("TOTAL="+total);
                  System.out.println("TOTAL NUMBER OF NOTES="+totaln);
          }
    }
 }



No comments:

Post a Comment

Goldbach Number ISC 2018

Question: A Goldbach number is a positive even integer that can be expressed as the sum of two odd primes. Note: All even integer numbers ...