Solved

verfiy if else statement

Posted on 2006-07-06
3
239 Views
Last Modified: 2010-04-01
folks

I have the following:

if (mroApp.equals("WOTRACK"))
            {
                  
                  mroRepName = "woprint";
            }
but i want to add a statement into this:

if (mroApp.equals("WOTRACK"))
            and (mroSite.equals("JFK"))

   mroRepName = "woprint2";

so its an if esle

could anyone advise what the correct way

the pschuedo code is

if app =wotrack then repname=woprint else if app =wotrack and site=jfk then woprint2

all other will not have the site parameter bound

all help will do

rutger

0
Comment
Question by:rutgermons
3 Comments
 
LVL 4

Expert Comment

by:evnafets
ID: 17055800
The logic you specified is bad, because the second condition is a subset of the first.
If the second condition is true, the first condition is also true, and so fires first - you would never get into the second test.
Reversing the tests, putting the more specific one first would work.

I would probably write it like this.

  if ("WOTRACK".equals(mroApp)){
    mroRepName = "JFK".equals(mroSite) ? "woprint2" : "woprint";
  }

Using "WOTRACK".equals(mroApp) rather than mroApp.equals("WOTRACK") makes the code more robust by avoiding a null pointer exception if mroApp is null.
I also used a ternary statement to set the value of the mroRepName variable.

0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 17055965
if (mroApp.equals("WOTRACK")
         && (mroSite.equals("JFK"))
   mroRepName = "woprint2";

I think this is what u wanted.
0
 
LVL 8

Accepted Solution

by:
kaliyugkaarjun earned 500 total points
ID: 17056345
If (mroApp.equals("WOTRACK"))
{
   if(mroSite.equals("JFK"))
       mroRepName = "woprint";
   else
        mroRepName = "woprint2";
}
   
   
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
J2SE 5.0 metadata 1 56
AlarmClock Challenge 35 150
Is it possible to "sandbox" html content within a JSP? 4 101
Unhandled exception type Exception 18 31
Data breaches are on the rise, and companies are preparing by boosting their cybersecurity budgets. According to the Cybersecurity Market Report (http://www.cybersecurityventures.com/cybersecurity-market-report), worldwide spending on cybersecurity …
Each year, investment in cloud platforms grows more than 20% (https://www.immun.io/hubfs/Immunio_2016/Content/Marketing/Cloud-Security-Report-2016.pdf?submissionGuid=a8d80a00-6fee-4b85-81db-a4e28f681762) as an increasing number of companies begin to…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question