This week's book giveaway is in the OCP forum.We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Help with IF statements

Greenhorn
Posts: 1
Hi guys, im in need of some help with my project, so any help would be greatly appreciated.

My app is to be able to find out the cost of a journey between two stations. The cost of the journey depends on which zones the station is located in.

So far i have two spinners which have a list of stations :-

Station A = Zone 2
Station B = Zone 3
Station C = Zone 3
Station D = Zone 1
Station E = Zone 2 etc...

The only method i could think of is very long and tiring, which is to do an if statement for each possible journey e.g if "spinner1 = station A" and "spinner 2 = Station B" then "cost = 25"

I was hoping to find a quicker method based on the zones, for example all the journeys from Zone 1 to Zone 2 = "Cost=20"

any examples or pointers in the right direction would be great

Ranch Hand
Posts: 56
Depends on how the price is calculated, and how the stations are placed in the zone map. If the price between all zone's is equal and all stations are sequentially placed on one line traveling from zone 1 to zone 2 and so on, you can calculate how many zone's you travel trough (end zone minus starting zone) and multiply that with the cost per zone.

If that's not the case you can create a two dimensional array containing the prices and use something like:

 It is sorta covered in the JavaRanch Style Guide.