#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    4
    Rep 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. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,576
    Rep Power
    1906
    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.

IMN logo majestic logo threadwatch logo seochat tools logo