Results 1 to 9 of 9
  1. #1
    Laythe's Avatar
    Laythe is offline Member
    Join Date
    Mar 2009
    Posts
    28
    Rep Power
    0

    Question [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.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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.

  3. #3
    Laythe's Avatar
    Laythe is offline Member
    Join Date
    Mar 2009
    Posts
    28
    Rep Power
    0

    Default

    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 :)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You are quite welcome. Good luck with your project.

  5. #5
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Sir Fubarable, MOD

    You've been needing a signature...

  6. #6
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Quote Originally Posted by Steve11235 View Post
    Sir Fubarable, MOD

    You've been needing a signature...
    Definitely... I had a signature from my first post. They help people feel welcome (and that's a good thing.) :D
    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!

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  8. #8
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    Your just jealous because the voices will talk to only me.
    haha i like that one.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  9. #9
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

Similar Threads

  1. Playing an AudioInputStream multiple times
    By pmgallardo in forum Advanced Java
    Replies: 6
    Last Post: 03-09-2009, 04:29 PM
  2. Replies: 3
    Last Post: 10-02-2008, 05:48 AM
  3. Replies: 2
    Last Post: 02-16-2008, 08:52 PM
  4. presse 1 menuitem execute 4 times the same JFrame
    By marcvb in forum New To Java
    Replies: 0
    Last Post: 12-27-2007, 09:48 PM
  5. Replies: 2
    Last Post: 11-11-2007, 08:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •