Home Tutorial Java Core Java Cash Dispenser

 
 

Java Cash Dispenser
Posted on: June 19, 2010 at 12:00 AM
Advertisement
In this section,we are going to print the receipt in which there is information of rupees note.

Java Cash Dispenser

You all are aware of ATM machines. It prints the receipt and provides you the requested amount. Here we are going to do the same thing i.e, printing the receipt in which there is information of rupees note. For this we have allowed the user to enter an amount and display the receipt in a format.

For e.g. if user enters 2750 then he/she should get receipt in this format:
1000*2=2000
500*1=500
100*2=200
50*1=50

Here is the code:

import java.util.*;

class ATM {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.println("Enter Amount: ");
		int amount = input.nextInt();
		int[] rupees = { 1000, 500, 100, 50 };
		int[] count = { 0, 0, 0, 0 };

		for (int i = 0; i < rupees.length; i++) {
			if (rupees[i] < amount || rupees[i] == amount) {
				count[i] = amount / rupees[i];
				amount = amount % rupees[i];
			}
		}
		for (int i = 0; i < count.length; i++) {
			if (count[i] != 0) {
				System.out.println(rupees[i] + " * " + count[i] + " = "
						+ (rupees[i] * count[i]));
			}
		}
	}
}

Output:

Enter Amount:
4550
1000 * 4 = 4000
500 * 1 = 500
50 * 1 = 50
Advertisement

Related Tags for Java Cash Dispenser:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 19, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com