?
Solved

add case/if statement to java

Posted on 2009-02-17
13
Medium Priority
?
568 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
0
Comment
Question by:rutgermons
  • 9
  • 3
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 23660932
Do
switch(WOPRIORITY) {
    case 10:
        doX();
        break;
    case 20:
        doY();
        break;
}

Open in new window

0
 

Author Comment

by:rutgermons
ID: 23661360
how would i place that in my code?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 23661460
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Expert Comment

by:CEHJ
ID: 23663080
Is that now clear?
0
 
LVL 92

Expert Comment

by:objects
ID: 23664452
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 23664547
Instead of

priodesc *= 1.35;

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

Open in new window

0
 

Author Comment

by:rutgermons
ID: 23669265
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 23669455
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
 
LVL 86

Expert Comment

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

Open in new window

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 23669480
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
 

Author Comment

by:rutgermons
ID: 23669590
lemme test it,thanks and great work! i app. it
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 23671352
Is that now clear rutgermons?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 23675802
:-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

839 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