add case/if statement to java

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
rutgermonsAsked:
Who is Participating?
 
CEHJConnect With a Mentor 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

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

Open in new window

0
 
rutgermonsAuthor Commented:
how would i place that in my code?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
CEHJCommented:
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

0
 
CEHJCommented:
Is that now clear?
0
 
objectsCommented:
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);
                }

0
 
CEHJCommented:
Instead of

priodesc *= 1.35;

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

Open in new window

0
 
rutgermonsAuthor 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
0
 
CEHJCommented:
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

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

Open in new window

0
 
rutgermonsAuthor Commented:
lemme test it,thanks and great work! i app. it
0
 
CEHJCommented:
Is that now clear rutgermons?
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.