Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

alternative ways of writing these lines...

Posted on 2004-10-24
9
Medium Priority
?
246 Views
Last Modified: 2010-03-31
hello

I have couple of codes, very simple, but I would like to learn other ways to write instead of classis ways which what i have wrote. : )



public void istalking(int data) {

private int setcomm = 0;
 private static String IsSpeakerOn = "no";                             
     private static String IsListenerOn = "no";      //          
                while(IsSpeakerOn == "yes"){ExtraSpeaker.sleep(); }                
                          if (IsListenerOn =="yes")
                      {
                                  IsSpeakerOn ="yes";                                  
                                  setcomm = word;                                 
                                  currentcondition.wake();                  
                      }
                            else
                                        {
                                              IsSpeakerOn ="yes";             
                                              setcomm = word;                      
                                              currentcondition.sleep();            
                                              IsSpeakerOn ="no";                  
                                              IsListenerOn ="no";
                          }
               }
0
Comment
Question by:anosTekbot
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12396473
thats not valid java code, what exactly is it you are trying to achieve?
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12396483
The only obvious change I can see is replacing the strings with Booleans:
  public void istalking(int data)
    {
        int setcomm = 0;
            int word = 0;
        boolean IsSpeakerOn = false;
        boolean IsListenerOn = false; //        

        while (IsSpeakerOn == true) {
            ExtraSpeaker.sleep();
        }

        if (IsListenerOn == true) {
            IsSpeakerOn = true;
            setcomm = word;
            currentcondition.wake();
        } else {
            IsSpeakerOn = true;
            setcomm = word;
            currentcondition.sleep();
            IsSpeakerOn = false;
            IsListenerOn = false;
        }
    }

What are you trying to accomplish?
0
 

Author Comment

by:anosTekbot
ID: 12396511
i know it is not a valid code becasue there are other parts, but my concern about the while loop and if statements. other than using booleans ..
my question is there a way these line of  statements
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 92

Expert Comment

by:objects
ID: 12396522
what is your concern?
0
 

Author Comment

by:anosTekbot
ID: 12396548
to know more about loops and statements..
for example
i tried to use
do {
...........
} while (IsSpeakerOn == "yes");

but when i tested .. it will take longer time than average and cost the machine to terminate ..
0
 
LVL 92

Expert Comment

by:objects
ID: 12396577
> IsSpeakerOn == "yes"

btw, that should be:

IsSpeakerOn.equals("yes")
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 12396581
the difference between a while and a do while loop is when the test is done.
in a do it is done at the start of the loop,
in a do while it is done at the end of loop meaning the loop itself will always get executed at least onse. this would not seem appropriate in your case.
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12396768
Is this a multi-threaded application?

What does the WHOLE application do?
0
 

Author Comment

by:anosTekbot
ID: 12396917
i c thats why i get terminated after a do while loop
thanks object and all
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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 …
Suggested Courses

610 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