Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
February 11th, 2013, 06:10 PM
 bfmcgee
Registered User

Join Date: Feb 2013
Posts: 4
Time spent in forums: 1 h 33 m 32 sec
Reputation Power: 0
Help changing pseudo code to java language.

I have this pseudocode and I'm having trouble translating it into java language.

While the size of the items needed list is greater than 0 and the size of the list of stores to visit is greater than zero
Pick the first store on the list of stores to visit list as the best store to visit so far
Find what items in the store match the items in the list. Save this list as the best list of items so far
Using the items found, calculate value ratio (the total quantity of items found / the total cost of those items + distance cost)
Set its value ratio as the best value ratio so far
For each of the rest of the stores
Find what items in the current store match the items in the list.
Using the items found, calculate value ratio
If the value ratio of the current store is greater than the value ratio of the best store so far
Set this store as the best store to visit so far
Set its value ratio as the best value ratio so far
Set the list of items found at this store as the best list so far
end
end

If the best store has any items
Remove the best store from the list of stores to visit (since we are now visiting it)
Use the list of items found in the best store above to remove these items from the list of all items needed
Subtract the number of units from the number of units needed (leaving the number still needed)
If the number of units needed is 0, remove that item from the list of items needed.
end

Create a new store object that is a copy of the best store without the items
Put the list of items found above (those from the best store that match the onese we need) into the store copy
Add the copy of the store to the ShoppingPlan
end
Add any remaining items in the list of items needed to the shopping plan as items that were not found

I'm having trouble with picking the first store from a list of stores. Can anyone demonstrate that?

#2
February 11th, 2013, 07:24 PM
 MrFujin
Lord of the Dance

Join Date: Oct 2003
Posts: 3,339
Time spent in forums: 2 Months 2 Weeks 4 Days 16 h 36 m 10 sec
Reputation Power: 1828
What have you tried until now? you have any code?

If you have an list (array) of stores, the first store would normally be at index 0.

 Viewing: Dev Shed Forums > Programming Languages > Java Help > Help changing pseudo code to java language.