+ 1

Write a progran in java:

to accept the amount of money to be withdrawn from a bank and find out the number of notes of each denomination to be given by the bank if the bank offers the following denominations of notes: Rs. 500, Rs. 100, Rs. 50, Rs. 20, Rs.10, Rs. 5, Rs. 2, Rs. 1.

3rd Mar 2017, 5:26 AM
Alok Agarwal
Alok Agarwal - avatar
7 Answers
+ 1
Hi, I'm not going to write a full code for now, but I can help you with the algorithm. If you have to withdraw a quantity called X and you want to know how many notes do you need: Is X bigger than the bigger note? If yes, give one of them and the new X is X-note. Then try again (smells like while). If not, do the same with the next bigger note. At the end, X should be 0 (or 0.something if you allow float input). If it's not enough information, reply and I'll try to give you more details (if I can find this post again). Good luck!
3rd Mar 2017, 6:53 PM
Qwerty
+ 1
You're wellcome :) It seems like I get notifications so I can get back here. If you need something else don't hesitate to ask. I'm looking forward to see your finished code, sounds interesting
3rd Mar 2017, 7:00 PM
Qwerty
+ 1
That's very cool. Just a couple of things. First, instead of the array you could use an enum. There is no big difference but...The next thing is I'm not completely sure if it will work if you enter 4 for example because it should give you 2 notes of the same thing, am I right? Just change the if inside the for for a while. Lastly, even if the code works, it is not very..."object oriented". So you come from C or something like that? You should implement an atm class with the method withdraw. It is possible that I'll do it myself in the next days. I'll notify you when it's ready
4th Mar 2017, 7:50 AM
Qwerty
+ 1
ok 👍 I'll try it too😊 thank you so much â˜șâ˜ș
4th Mar 2017, 9:08 AM
Alok Agarwal
Alok Agarwal - avatar
+ 1
Your atm class is ready. Take a look at my codes, it is there. Try it and tell me if you like it :)
4th Mar 2017, 11:38 AM
Qwerty
0
thank you so much for helping me out😊👍 I'll try to write the code & then let I'll let you knowâ˜ș
3rd Mar 2017, 6:58 PM
Alok Agarwal
Alok Agarwal - avatar
0
import java.util.*; public class Program2 { public static void main(String[] args) { Scanner in=new Scanner(System.in); int a[]={500,100,50,20,10,5,2}; System.out.println("Enter amount to be withdrawn"); int amt=in.nextInt(); int m=0; int n; n=amt; for(int i=0; i<7;i++) { if(amt>=a[i]) { m=amt/a[i]; amt=amt%a[i]; System.out.println(a[i]+ " = " +m); } } } } I've written the code and executed it..took me some time but it works!! I've done it with arrays though
4th Mar 2017, 4:22 AM
Alok Agarwal
Alok Agarwal - avatar