473,382 Members | 1,447 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,382 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 1546
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.