Solved

Java Application that applies conditional logic to a set of tasks

Posted on 2004-03-25
11
193 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:Mayank S
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 15

Expert Comment

by:Javatm
ID: 10685066
0
 
LVL 30

Expert Comment

by:Mayank S
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
 
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:Mayank S
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:Mayank S
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:Mayank S
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
nextBoolean(double p) for Random class 3 41
use lov values 2 61
spring jars download 1 35
How  can  i  resolve  HTTP Status 404 -? 8 41
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

790 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