Solved

Java Application that applies conditional logic to a set of tasks

Posted on 2004-03-25
11
190 Views
Last Modified: 2010-03-31
Hi all

I am looking for some people who use or built a java application that applies conditional logic to a set of tasks.  For example, when a locomotive comes into one of our service shops a worker is given a set of static tasks.  What we would like it to be is conditional based, ie.  If user selects inputs 1 for task A, then display task C, else display task B.... right now it lists ALL of the tasks.

I am looking at the technical challenges, what worked and did not work

Thanks - V
0
Comment
Question by:pollacsekv
  • 5
  • 5
11 Comments
 
LVL 3

Expert Comment

by:fave_17
ID: 10684986
you can use if-else statements, or switch -case statement
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10685031
Explaining what fave_17 wrote in his first comment a little more, it could be like:

if ( input == 1 )
  -> taskA () ;
else if ( input == 2 )
  -> taskB () ;
else if ( input == 3 )
  -> taskC () ;

or:

switch ( input )
{
  case 1: -> taskA () ;
    break ;

  case 2: -> taskB () ;
    break ;

  case 3: -> taskC () ;
    break ;

  default: System.out.println ( "Invalid input" ) ;

}

Note that the switch-case will not work for String-arguments.
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10685056
There are many ways to do that you can use :

1.) If - Else :

if (YourTask) {
}
else {
}

2.) Switch Case :

switch () {

case A1:
Do your thing . . .
break;

case B1:
Do your thing . . .
break;

default:
Do your thing . . .
}

3.) Try / Catch :

try {
Do your thing . . .
}
catch(Exception e) {
Catch exception . . .
}

Hope that helps . . .
Javatm
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10685066
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10685573
Javatm,

>> 3.) Try / Catch :

Why should a try/ catch fit for conditional purposes? You can write anything in a try/ catch block - need not be a conditional statement block. And in the first two cases (if else, switch-case) too, you can have try/ catch blocks. I don't think that try/ catch blocks fit in as a 'different' or an 'isolated' third approach.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 15

Expert Comment

by:Javatm
ID: 10692225
> Why should a try/ catch fit for conditional purposes?

It is a good approach for programming purposes making a conditional statements will be better handle if you provided
more specific handle to a certain problem.

like :

try {

if () {
}
else {}
}
catch(Exeption) {}

> I don't think that try/ catch blocks fit in as a 'different' or an 'isolated' third approach.

Well you can be correct but you need to actually look on the real purpose why we use try/catch it
is also like if / else statements but with better purposes in Java.

Hope that helps . . .
Javatm
0
 
LVL 15

Accepted Solution

by:
Javatm earned 250 total points
ID: 10692264
Anyway congrats as I see you've already reached the Master Level, good luck :)
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10694526
Thanks, buddy.

>> but with better purposes in Java

Exactly. That's because it can be 'coupled' with anything, be it an if-else, a switch-case or any Java code :-)
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10731166
Was that the answer ;-) ??
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10737087
I dont know why I received the points but thanks anyway . . .

http://www.freewebs.com/cube-j

Always glad to help . . .
Friend : Javatm
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10738315
Points are ok, but if the accepted answer had been your first commet, it was better. Some people don't realize that they should select the appropriate answer - they just select any comment from the person whom they want to give the points and they think that its done.

But think about non-members. While browsing, if they open some pages on this site and if the question meets what they are searching for, they will quickly click on the "See Solution" link which takes to the Accepted Answer. Now if that is not the actual answer, then the person has to go through the trouble of going through all comments to see which could've been the right one. That gives a slightly bad impression of EE.

In fact, even when members are searching for answers in some old questions, they tend to click the "See Solution" link and it'd be better if it takes them to the actual answer only.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java virtual machine monitoring tools 3 39
json format text only 4 65
JDeveloper 12c for 32 bit 4 35
GUI builder for Eclipse? 8 11
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now