| | |
algorithm for java
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 17
Reputation:
Solved Threads: 0
I am building an xml parser in java which will handle a catalog with some books (that have price and usefulness) and I want to implement an optimum algorithm that selects the books from the catalog which have the maximum usefulness while staying within the budget.
Example:
,in this case the chosen books would be the first two books because they have a maximum usefulness of 180 and they stay in the budget.
Help would be appreciated,
Cheers
Example:
Java Syntax (Toggle Plain Text)
<catalog cash=”100”> <book usefulness=”90” price=”60” >The Art of Computer Programming</book> <book usefulness=”90” price=”40”>Programming Pearls</book> <book usefulness=”60” price=”40”>American Psycho</book> </catalog>
Help would be appreciated,
Cheers
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
here is some pseudo-code for you
Java Syntax (Toggle Plain Text)
List<Book> usefulBooks; int cashAvailable = cash; booklist = query books by usefulness descending for(Book book : booklist) { if(cashAvailable - book.getPrice() > 0) { //add the book usefulBooks.add(book); //decrement our cash cashAvailable = cashAvailable - book.getPrice(); } }
Last edited by ~s.o.s~; Nov 4th, 2008 at 10:46 am. Reason: Added code tags.
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
![]() |
Similar Threads
- Help with LR parser algorithm (Java)
- LSA algorithm in java (Java)
- Help with print statement in java (Java)
- Java DSW algorithm Coding (Java)
- comparing java and C ++(labeling) (Java)
- negamax algorithm (Java)
Other Threads in the Java Forum
- Previous Thread: Help me out with hashing in java
- Next Thread: Help with passing a parameter to the main method
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card chat class client code collision component crashcourse css csv database eclipse ee error fractal free game gis givemetehcodez graphics gui html ide image input integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan loop machine map method methods migrate mobile netbeans newbie objects oriented output panel phone physics problem program programming project radio recursion reporting scanner se server service set sms socket software sort sql string swing test textfield threads transfer tree trolltech ubuntu utility windows






