Solved

Java Application that applies conditional logic to a set of tasks

Posted on 2004-03-25
11
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
spring jars download 1 53
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO) 1 59
java mysql insert application 14 45
Setup GlassFish 4 35
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

749 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