How do I compare two lists in Java and print the result based on each combination? -


i want compute ticket price between each stations based on price matrix:

         b c         0  2 3   b     4  0 1   c     7  2 0 

example: from b print 2 or from c a print 7 based on values in above price matrix.

here is, want print railway ticket fare based on 2 station lists: "from:" list , "to:" list. want print fare after comparing. there fixed fare each combination. example station station b, fare 10. 1 station other station there fixed fare.

i create class, responsible storing fares.

public class farestorage {     map<towncombination, double> fares;      //...      public double getfare(string towna, string townb) {         return fares.get(new towncombination(towna, townb));     }      public void addfare(string towna, string townb, double fare) {         fares.put(new towncombination(towna, townb));     }      class towncombination {         string town1;         string town2;          //if fare b equals fare b a,          //then a-b , b-a combinations should equal.          //override hashcode , equals way want.       } } 

it not complete, hope idea. how can use it:

        farestorage storage = new farestorage();         storage.addfare("a", "b", 10.2);          //....         double fare = storage.get("a", "b"); 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -