[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

alternative ways of writing these lines...

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
anosTekbot
Asked:
anosTekbot
  • 4
  • 3
  • 2
1 Solution
 
objectsCommented:
thats not valid java code, what exactly is it you are trying to achieve?
0
 
MogalManicCommented:
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
 
anosTekbotAuthor Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
objectsCommented:
what is your concern?
0
 
anosTekbotAuthor Commented:
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
 
objectsCommented:
> IsSpeakerOn == "yes"

btw, that should be:

IsSpeakerOn.equals("yes")
0
 
objectsCommented:
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
 
MogalManicCommented:
Is this a multi-threaded application?

What does the WHOLE application do?
0
 
anosTekbotAuthor Commented:
i c thats why i get terminated after a do while loop
thanks object and all
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now