Results 1 to 12 of 12
- 09-08-2011, 03:46 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 5
- Rep Power
- 0
Got the idea but cannot write in code... help me
Question: Suppose you are given a gift voucher worth $100. Assuming that the shop does not give change on gift voucher and you do not wish to spend any more than what is in the gift voucher. This means for example:
if there are items $87, $20, $99, $12 then the most I can spend is $100 since
buying 4 $20 item.
I have wrote some of the codes but...stuck.
Java Code:public class lab233 { static int voucherMoney = 100; static int item1 = 23; static int item2 = 38; static int item3 = 40; static int item4 = 58; static int a = voucherMoney/item1; //by dividing most no of this items can be bought static int b = voucherMoney/item2; static int c = voucherMoney/item3; static int d = voucherMoney/item4; public static void main(String[] args){ for(int i = 0; i < a; i++){ for(int j = 0; j < b; j++){ for(int k = 0; k < c; k++){ for(int g = 0; g < d; g++){ //I think by using 4 loops and compare the combinations.... by using compareTo methods??? help me here T.T } } } } } }Last edited by sunde887; 09-08-2011 at 05:29 PM.
- 09-08-2011, 03:51 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,425
- Blog Entries
- 7
- Rep Power
- 17
- 09-08-2011, 03:56 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 5
- Rep Power
- 0
Re: Got the idea but cannot write in code... help me
5 $20 my bad lol thanks!..hmm.. how should i type..to find out the model solution for this then?
- 09-08-2011, 04:38 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,425
- Blog Entries
- 7
- Rep Power
- 17
Re: Got the idea but cannot write in code... help me
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 09-08-2011, 07:43 PM #5
Member
- Join Date
- Sep 2011
- Posts
- 5
- Rep Power
- 0
Re: Got the idea but cannot write in code... help me
I search for the google and saw your example but I cannot apply to this situation... can you help me directly here???? anyone?
- 09-08-2011, 07:51 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,425
- Blog Entries
- 7
- Rep Power
- 17
- 09-08-2011, 08:02 PM #7
Member
- Join Date
- Sep 2011
- Posts
- 5
- Rep Power
- 0
Re: Got the idea but cannot write in code... help me
I think my brain is dead right now :).... cannot understand the algorithm probably hww..;;
- 09-08-2011, 08:09 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,425
- Blog Entries
- 7
- Rep Power
- 17
Re: Got the idea but cannot write in code... help me
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 09-08-2011, 08:22 PM #9
Member
- Join Date
- Sep 2011
- Posts
- 5
- Rep Power
- 0
Re: Got the idea but cannot write in code... help me
hmm................I think I should give up... cannot write the code... T.T among those values how can I get the maximum combination that is equalto or less than $100... the combination............hmm..
- 09-08-2011, 08:29 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,425
- Blog Entries
- 7
- Rep Power
- 17
Re: Got the idea but cannot write in code... help me
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 09-09-2011, 03:28 AM #11
Member
- Join Date
- Sep 2011
- Posts
- 22
- Rep Power
- 0
Re: Got the idea but cannot write in code... help me
wa.. how do i do this??????????????????????????????
- 09-09-2011, 03:33 AM #12
Similar Threads
-
What are you using to write your code?
By CaptainMorgan in forum New To JavaReplies: 948Last Post: 05-21-2013, 12:41 PM -
I need to acheive multi chatting in net beans...plz give idea and code for that..
By vetrivelmanian in forum NetBeansReplies: 1Last Post: 07-28-2011, 08:48 AM -
Questions about the idea of the code
By Innocent in forum New To JavaReplies: 2Last Post: 04-03-2011, 09:42 PM -
hi can you give me some idea to move this code back to soabean (Presentation bean). c
By bharanik in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-21-2011, 09:46 AM -
No idea why my code won't work...
By hopelessnoob in forum New To JavaReplies: 11Last Post: 03-21-2011, 03:41 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks