Results 1 to 9 of 9
- 06-03-2009, 02:17 AM #1
[SOLVED] how to count how many times you used a method
Hello EveryOne :)
Is there a way that alows me to count the number of time that i used a method in a class??
exemple:
Java Code:public class StudentRecord { public static void main(String Laythe[]) { // Declare Instance Variables; private String Name; // Set up the name of every single student; public void SetName(String Temp) { Name = Temp; } // Create Object instance of StudentRecod class; StudentRecord LaytheRecord = new StudentRecord(); StudentRecord NarutoRecord = new StudentRecord(); StudentRecord DragonRecord = new StudentRecord(); // Set the names of the sutdents; LaytheRecord.SetName("Laythe"); NarutoRecord.SetName("Naruto"); DragonRecord.SetName("Dragon"); // what can i do to count how many times i used the SetName() method?? ; } }Last edited by Laythe; 12-18-2009 at 01:49 AM.
-
give the class an int counter variable and increment it from within the setName method. If you want to know how many times it is called within each instance of the class, then make the counter an instance field. If you'd rather know how many times all instances have called this method, then make the counter a static field.
- 06-03-2009, 02:45 AM #3
Thank you very very very much sir Fubarable, it's exactly the way i wanted to be answered, your answer showed me how to make the cake not making it for me :D
it's the way i alwase want to be answered with ;)
Thank you again :)
-
You are quite welcome. Good luck with your project.
- 06-04-2009, 05:03 AM #5
Sir Fubarable, MOD
You've been needing a signature...
- 06-05-2009, 12:44 AM #6
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
-
- 06-06-2009, 07:10 PM #8
haha i like that one.Your just jealous because the voices will talk to only me.USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 06-07-2009, 02:29 AM #9
Similar Threads
-
Playing an AudioInputStream multiple times
By pmgallardo in forum Advanced JavaReplies: 6Last Post: 03-09-2009, 04:29 PM -
SwingWorker problem!!! How can I run it 2 times or more?
By davigre in forum AWT / SwingReplies: 3Last Post: 10-02-2008, 05:48 AM -
Recursive Method ==> find how many times a value is repeated in an array
By NatNat in forum New To JavaReplies: 2Last Post: 02-16-2008, 08:52 PM -
presse 1 menuitem execute 4 times the same JFrame
By marcvb in forum New To JavaReplies: 0Last Post: 12-27-2007, 09:48 PM -
Problem calling classes to flip coin x number of times and record heads or tails
By adlb1300 in forum New To JavaReplies: 2Last Post: 11-11-2007, 08:07 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks