473,396 Members | 1,921 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,396 software developers and data experts.

which method is called first ?

Hi all, I have a question and any suggestions for solutions would be
greatly appreciated.
In my program, I first defined a variable called 'incidence' which has
to be updated at every time step,

public static int incidence = 0;

Then I have a method which is called 'step()' and inside 'incidence' is
updated.

public void step() {
updateIncidence();
}
......

I have another method called 'stepReport()' which writes the
'incidence' into a file.

public void stepReport() {
System.out.printf(" %d infected ( inside stepReport).\n", incidence
);
s += String.format(" %d", incidence );
}
......

I am interested in keeping the variable 'incidence' initialized and
updated at every tick count and thought it worked well. Because If I
see the output from the 'updateIndence(); method', then the output is
congruent with all the other outputs.

But the problem happens when I tried to write the variable 'incidence'
into a file. It is not updated every tick count. the incidence value
inside the method, 'stepReport()' doesn't match
that inside the 'partnerInfection( nodeList );'

So I incorporated a print method inside the 'stepReport()' and the
result is

0 infected ( inside stepReport).
0 infected.(inside updateIncidence)
0 infected ( inside stepReport).
2 infected.(inside updateIncidence)
2 infected ( inside stepReport).
2 infected ( inside stepReport).
0 infected.(inside updateIncidence)
0 infected ( inside stepReport).
0 infected.(inside updateIncidence)
0 infected ( inside stepReport).
1 infected.(inside updateIncidence)
1 infected ( inside stepReport).
0 infected.(inside updateIncidence)
0 infected.(inside updateIncidence)
0 infected ( inside stepReport).

So it seems that sometimes, 'stepReport()' method is executed first and
then 'updateIncidence()' is executed. But other times, the opposite.
If it would work, those two methods have to be in same order over
time.

Is there any way to control the order in which the methods are excuted
?

Any suggestions would be appreciated.

Thank you.

Apr 7 '06 #1
1 1818
thickface <ki*******@gmail.com> wrote:
Hi all, I have a question and any suggestions for solutions would be
greatly appreciated.
In my program, I first defined a variable called 'incidence' which has
to be updated at every time step,
<snip>
Is there any way to control the order in which the methods are excuted
?


Unfortunately, you haven't really shown enough code to see what's going
on. The order in which methods are executed is deterministic (in all
cases I can think of at the moment), and can be controlled fairly
closely.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
4
by: mflll | last post by:
I am looking into the different techniques of handling arrays of edit boxes in Java Script. The first program below works fine. However, are there better ways of doing this, where the person...
1
by: John Davison | last post by:
When you have the following: function foo() { var bar = 10; // do some other stuff } It is my understanding that bar is *not* a property of function object foo. Now, when you have the...
3
by: AWasilenko | last post by:
I'm still in the process of learning python via a handful of books I bought. One book I am reading just introduced Base Class Methods. I found that I needed more understanding on this concept and...
9
by: 7stud | last post by:
Hi, I'm trying to figure out what this passage from GvR's tutorial means: ------- Class definitions, like function definitions (def statements) must be executed before they have any effect.......
2
by: Bill Jackson | last post by:
For example, class A: def __init__(self,a): self.a = a def __eq__(self, other): return self.a == other.a class B: def __init__(self,b):
2
by: Gugale at Lincoln | last post by:
Hi, I am creating a user control which has a radio button and few other controls. I would like the user control to behave like a radio button, in the sense when added to a container radio button...
3
by: =?Utf-8?B?Um9sYW5kcGlzaA==?= | last post by:
Hi, I'm doing an application using C# and I have this question: I have a method called sqlQueryBD which receives a string sql query and executes it against a database. I also have a class called...
9
by: VK | last post by:
<OT>I am finishing TransModal 0.1 so planning to move it from alpha to beta stage.<OT> Besides that I am planning to write an introductory to inheritance schema currently used in Javascript...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.