We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

add case/if statement to java

Medium Priority
634 Views
Last Modified: 2012-05-06
folks

i have the following

super.action();
          Mbo mbo = getMboValue().getMbo();
          String prioprity = mbo.getString("WOPRIORITY");


          if (!getMboValue().isNull())
          {
                SqlFormat sqlpriority = new SqlFormat(mbo, " domainid='SR_CALCPRIO' and value=:1 ");
                sqlpriority.setObject(1, "numericdomain", "value", prioprity);
                MboRemote WORemote = mbo.getMboSet("$numericdomain", "numericdomain", sqlpriority.format()).getMbo(0);
                if (WORemote != null && !mbo.isNull("TARGSTARTDATE")){
                      int priodesc = WORemote.getInt("DESCRIPTION");
                      Date targerstart = mbo.getDate("TARGSTARTDATE");
                      Calendar c = Calendar.getInstance();
                      c.setTime(targerstart);
                      c.add(Calendar.MINUTE,priodesc);
                      mbo.setValue("TARGCOMPDATE", c.getTime(), 2L);
                }

if want to add time on the targetstart as you see but i now want to have the following

if WOPRIORTIY = 10  then

c.add(Calendar.MINUTE,priodesc * 1.35)
if
WOPRIORTIY = 20 then
c.add(Calendar.MINUTE,priodesc * 1.55)

all help will do

r
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
Do
switch(WOPRIORITY) {
    case 10:
        doX();
        break;
    case 20:
        doY();
        break;
}

Open in new window

Author

Commented:
how would i place that in my code?
CERTIFIED EXPERT
Top Expert 2016

Commented:
You could do
        if (WORemote != null && !mbo.isNull("TARGSTARTDATE")){
            int priodesc = WORemote.getInt("DESCRIPTION");
            Date targerstart = mbo.getDate("TARGSTARTDATE");
            Calendar c = Calendar.getInstance();
            c.setTime(targerstart);
            switch(WOPRIORITY) {
                case 10:
                    priodesc *= 1.35;
                    break;
                case 20:
                    priodesc *= 1.55;
                    break;
            }
            c.add(Calendar.MINUTE,priodesc);
            mbo.setValue("TARGCOMPDATE", c.getTime(), 2L);
        }

Open in new window

CERTIFIED EXPERT
Top Expert 2016

Commented:
Is that now clear?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
try the following:


          if (!getMboValue().isNull())
          {
                SqlFormat sqlpriority = new SqlFormat(mbo, " domainid='SR_CALCPRIO' and value=:1 ");
                sqlpriority.setObject(1, "numericdomain", "value", prioprity);
                MboRemote WORemote = mbo.getMboSet("$numericdomain", "numericdomain", sqlpriority.format()).getMbo(0);
                if (WORemote != null && !mbo.isNull("TARGSTARTDATE")){
                      int priodesc = WORemote.getInt("DESCRIPTION");
                      Date targerstart = mbo.getDate("TARGSTARTDATE");
                      Calendar c = Calendar.getInstance();
                      c.setTime(targerstart);
                      if (prioprity==10)  priodesc *= 1.35;
                      else if (prioprity==20)  priodesc *= 1.55;              
                      c.add(Calendar.MINUTE,priodesc);
                      mbo.setValue("TARGCOMPDATE", c.getTime(), 2L);
                }

CERTIFIED EXPERT
Top Expert 2016

Commented:
Instead of

priodesc *= 1.35;

you need to do the following:
priodesc = (int)(priodesc * 1.35);

Open in new window

Author

Commented:
objects

the == statment in the if is causing issues ,could you advise pls, te priority is declared as a string at the top

all help will do
CERTIFIED EXPERT
Top Expert 2016

Commented:
SOrry - didn't know it was String. You can do
       if (WORemote != null && !mbo.isNull("TARGSTARTDATE")){
            int priodesc = WORemote.getInt("DESCRIPTION");
            Date targerstart = mbo.getDate("TARGSTARTDATE");
            Calendar c = Calendar.getInstance();
            c.setTime(targerstart);
            switch(Integer.parseInt(WOPRIORITY)) {
                case 10:
                    priodesc *= 1.35;
                    break;
                case 20:
                    priodesc *= 1.55;
                    break;
            }
            c.add(Calendar.MINUTE,priodesc);
            mbo.setValue("TARGCOMPDATE", c.getTime(), 2L);
        }

Open in new window

CERTIFIED EXPERT
Top Expert 2016

Commented:
And you'll need to make the adjustment i mentioned too:
                    priodesc = (int)(priodesc * 1.35); //etc

Open in new window

CERTIFIED EXPERT
Top Expert 2016
Commented:
So altogether that would be:
       if (WORemote != null && !mbo.isNull("TARGSTARTDATE")){
            int priodesc = WORemote.getInt("DESCRIPTION");
            Date targerstart = mbo.getDate("TARGSTARTDATE");
            Calendar c = Calendar.getInstance();
            c.setTime(targerstart);
            switch(Integer.parseInt(WOPRIORITY)) {
                case 10:
                    priodesc = (int)(priodesc * 1.35);
                    break;
                case 20:
                    priodesc = (int)(priodesc * 1.55);
                    break;
            }
            c.add(Calendar.MINUTE,priodesc);
            mbo.setValue("TARGCOMPDATE", c.getTime(), 2L);
        }

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
lemme test it,thanks and great work! i app. it
CERTIFIED EXPERT
Top Expert 2016

Commented:
Is that now clear rutgermons?
CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.