/*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.
Example 1:
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
EXAMPLE 2:
INPUT: 235001
OUTPUT: INVALID AMOUNT
*/
import java.io.*;
public class Denomination
{
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
private static int[] denomin={1000,500,100,50,20,10,5,2,1}; private static int amount=0;
public void denominate(int amount)
{
int count[]=new int[9];
for(int i=0;i<denomin.length;i++) // COMPUTING DENOMINATION
{
while(denomin[i]<amount)
{ count[i]+=1; amount-=denomin[i]; }
}
System.out.println("\nDenomination Generated :\n");
for(int i=0;i<count.length;i++)
{
if(count[i]>0) System.out.println(denomin[i]+" : "+count[i]);
}
}
public static void main(String[] args)throws IOException
{
try{System.out.print("Enter Amount : ");
amount=Integer.parseInt(br.readLine());}
catch(Exception e){System.out.println("Amount Too Large to Denominate or Error Input");System.exit(1);}
Denomination obj=new Denomination();
obj.denominate(amount);
}
}
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.
Example 1:
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
EXAMPLE 2:
INPUT: 235001
OUTPUT: INVALID AMOUNT
*/
import java.io.*;
public class Denomination
{
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
private static int[] denomin={1000,500,100,50,20,10,5,2,1}; private static int amount=0;
public void denominate(int amount)
{
int count[]=new int[9];
for(int i=0;i<denomin.length;i++) // COMPUTING DENOMINATION
{
while(denomin[i]<amount)
{ count[i]+=1; amount-=denomin[i]; }
}
System.out.println("\nDenomination Generated :\n");
for(int i=0;i<count.length;i++)
{
if(count[i]>0) System.out.println(denomin[i]+" : "+count[i]);
}
}
public static void main(String[] args)throws IOException
{
try{System.out.print("Enter Amount : ");
amount=Integer.parseInt(br.readLine());}
catch(Exception e){System.out.println("Amount Too Large to Denominate or Error Input");System.exit(1);}
Denomination obj=new Denomination();
obj.denominate(amount);
}
}
No comments:
Post a Comment