473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

issues getting this code to work

I am stuck trying to get this code work, it's suppose to return true or false if the FitnessFrog is on a black stone, numbered 1 - 11 and if it's on a stone 0 or 12 or higher, neither FitnessFrog is suppose to move. I want to know if I am on the right track with this or not. Thank you.

Expand|Select|Wrap|Line Numbers
  1.  /**
  2.     * 
  3.     */
  4.    private boolean isOnBlackStones(FitnessFrog AFitnessFrog)
  5.    {
  6.  
  7.     if (AFitnessFrog.getPosition() < 1)
  8.     {
  9.  
  10.       }
  11.      if (AFitnessFrog.getPosition() > 11)
  12.       {
  13.  
  14.       }
  15.       return false;
  16.    }
  17. }
Apr 3 '14 #1
2 1547
Nepomuk
3,112 Expert 2GB
Hi Chloe03 and welcome to bytes.com!

Just to make sure I understand this correctly, the above function should return true if the stone passed has a number between 1 and 11 inclusive and false otherwise? If so, you've switched the logic here as if it's neither smaller than 1 nor larger than 11 (which would mean it's not a black stone) it will return false when I would expect it to return true. Alternatively you could check whether it is at least 1 and no larger than 11 and if so return true and false otherwise.
Apr 7 '14 #2
chaarmann
785 Expert 512MB
The two if-statements are empty (despite its indentation), they are doing nothing. It always returns false. Just put "return false" in line 9 and 13 and change line 15 to "return true".

One more tip for expert:
Don't use copy-and-paste programming style!
So call AFitnessFrog.getPosition() only once and store it in a local variable.
Frogs can jump quickly and uncontrolled (whenever they want). So when you call AFitnessFrog.getPosition() first time, you may get back 1, but when the code moves on executing and you call the same AFitnessFrog.getPosition() again a few lines below, you may get back 0, because the frog jumped from stone 1 to stone 0 in the meantime.
That means now your method returns true which is wrong.

To avoid this, you can also use synchronization instead. But then issue remains that calling AFitnessFrog.getPosition() twice leads to bad performance if this method getPosition() does anything now (or will be changed in the future) that takes a long time.
Apr 7 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Anil | last post by:
hi will the following code work. typedef struct { unsigned char date; unsigned char sortie_num; unsigned int start_address; unsigned short offset; } sortie_data;
14
by: daveyand | last post by:
Hey guys, I've spent abit of time searching th web and also this group and cant seem to find a solution to my issue. Basically i want to get the current url, and then replace http:// with...
9
by: bhavik.patel | last post by:
Hi I have a rather simple question: I have following class definitions: class Base { public: virtual void display ()
2
by: MichaelAtCitiesDigital | last post by:
I am having multiple issues with a project I am working on. I keep discovering more problems as I get further and further into trying to fix it. First, sessions aren't working correctly. Now, some...
3
by: xmail123 | last post by:
Why does this code work? I am new to C# and have been studying this piece of code. It loops through an Adjacency Matrix table to populate a tree view. I have two questions about why this code...
0
by: fjm | last post by:
I am having a bit of a problem getting my head around how to handle a design issue and hope that someone can offer some assistance. I am making a front end to a mysql database in PHP. I am at the...
11
by: truezplaya | last post by:
Hi I have an issue with a list box. I populate the list box using listbox1.datasource = myCollectionOfCars listbox1.databind() When i go to retrieve the selected item from the listbox...
7
by: jharrison | last post by:
I'm finding it hard to make this code work in Python 3.0. Been looking at it for some time now: # import module for random functions import random # List of words for the computer to pick...
1
Samishii23
by: Samishii23 | last post by:
Ok assume the following: I have most recent jQuery, and jQueryUI, the problem is occuring in code in a seperate js file within an object function. I have 8 radio buttons, each the same name. When...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.