Solved

Java Application that applies conditional logic to a set of tasks

Posted on 2004-03-25
11
191 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 98
mapAB Challlenge 35 124
nextBoolean(double p) for Random class 3 35
varialbe initialization 11 30
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

911 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

22 Experts available now in Live!

Get 1:1 Help Now