Link to home
Start Free TrialLog in
Avatar of rutgermons
rutgermons

asked on

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Open in new window

Avatar of rutgermons
rutgermons

ASKER

how would i place that in my code?
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

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

Instead of

priodesc *= 1.35;

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

Open in new window

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

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
lemme test it,thanks and great work! i app. it
Is that now clear rutgermons?
:-)