How do I keep track of how many times a method is called inside anthr clas?

I am writing code for a program that solves a Knight's Tour. A Knight's Tour is a path a Knight Chess piece can take around the board starting at any spot, touching every square once, and only once. I have to write 2 classes and one is provided. The provided class is encrypted and written by our professor. All I know that it does is simulates the game using the two classes I write and provides a print out and prompts to ask the user which square they want to move to next.
The square class I have to write consists of a constructor that makes a square object that keeps track of its color (white/black) and its status (whether it has been visited, is occupied by the knight, or is free and has not be visited).
The GameBoard class I have to write is what I am having problems with. I am writing a method that determines how many squares have been visited. The previous mentioned class that my professor wrote for me contains a method moveKnight();. The way the program works is that every time moveKnight() is called a square's status is changed to occupied and therefore visited later. moveKnight() will only work if the move requested by the user is a valid move.
SO! My main problem (sorry for all the explaining, just trying to give you all the information) is that I don't know how to keep track of how many times moveKnight() is called by the program. If i can figure this out it should be simple. I'm new to java but i believe...
if(moveKnight() is called)
{count++;} //count is a member variable already initialized
return count;
the moveKnight() is called section within the if() statement is what I am unclear how to do. Please help.
Thanks, Veritas

in your case you want 'count' to be a class attribute rather than a local variable. But yes, incrementing it each time that the method is called will serve your purpose.

Similar Messages

  • How to keep track of how many times a link has been clicked?

    How to keep track of how many times a link has been clicked or accessed? Do I need to use database for this?

    Hi
    Proably something like this can work,
    1> Have a servlet/bean invoked when the link is linked
    2> have a static variable in that servlet/bean wich gets incremented before the control is passed to another desired page..
    The problem with this approach is that care has to be taken that the servlet/bean is not re-instalised, in case of which the static variable will also be instalised and the data would be lost.
    The best thing is to store the count in the database.
    Regards
    Arathi.

  • How to keep track of how many records to display in a page.

    Hi All:
    I am using Weblogic 9.2, Web Services Client, and Struts.
    I have a java client in struts that calls a web services.
    The "ID" field contains a Java integer.
    The "First_Name" is a Java String.
    The "Effective_Date" field is a Java date field.
    The web service returns an arrayList of a class called Result.
    Code for Result.java:
    >
    public class Result
    int id;
    String first_Name;
    Date effective_Date;
    public int getId
    return id;
    public void setId(int id)
    this.id=id;
    public String getFirst_Name()
    return first_Name;
    public void setFirst_Name(String first_Name)
    this.first_Name = first_Name;
    public Date getEffective_Date()
         return effective_Date;
    public void setEffective_Date(Date effective_Date)
         this.effective_Date=effective_Date;
    From the arrayList, I displayed the result as the following:
    ID FIRST_NAME EFFECTIVE_DATE
    3 John 9/10/2007
    2 Andrew 1/11/2006
    5 Peter 3/4/2006
    The "ID" header is a link.
    The "First Name" header is a link.
    The "EFFECTIVE_Date" is a link.
    If I clicked on the link "ID", the first time, it will sort the rows in ascending
    order like the following:
    ID FIRST_NAME EFFECTIVE_DATE
    2 Andrew 1/11/2006
    3 John 9/10/2007
    5 Peter 3/4/2006
    If I clicked on the link "ID", the second time, it will sort the rows in descending
    order like the following:
    ID FIRST_NAME EFFECTIVE_DATE
    5 Peter 3/4/2006
    3 John 9/10/2007
    2 Andrew 1/11/2006
    If I clicked on the "First_Name" field the first time, it will sort the rows in
    desceding order.
    If I clicked on the "First_Name" field the second time, it will sort the rows in
    ascending order.
    This applies the same for the "EFFECTIVE_DATE".
    If the arrayList returns 80 records of class Results.java.
    I needed to displayed only the first 50 records for the first page and 30 records for the second page.
    How do I keep track of that so that when I am in the second page, I know to display only record 51 to 80?
    If I have a arrayList that returns 120 records of class Results.java.
    In the first page, it displayed only 50 records.
    In the second page, it displayed only 50 records.
    In the third page, it displayed only 20 records.
    Assuming I am able to sort the rows by ID, FirstName and Effective_Date by using Results.java implementing the
    Java Comparator class. Is it still possible to keep track of how many records displayed in the first page and how many records should
    be dispalyed in the second page?
    Any hint would be greatly appreciate.
    Yours,
    Frustrated.

    Hi,
    Access the table through SM30. It comes blank as standard. Click "New Entries" and make entries for changes to be tracked. For example, whenever an org. unit changes 002 and 003 relationship, you will make entries like:
    01 O 1001 B002 Activate box checked
    01 O 1001 B003 Activate box checked
    Here, 01 is your active plan version, O is org. unit, 1001 is infotype and B002 and B003 are the subtypes. You can also use * for infotype and subtype which means every change will be logged.
    If you then run the report RHCDOC_DISPLAY through SA38, it will pick up all the changes pertaining to B002 and B003 relationship for org. units (in the above example).
    Similarly, you can set up this table for other object types.
    For more information, follow SPRO>Personnel Management>OM>Basic Settings>Activate change documents and go through the documentation for that node. Also, read up the documentation for the report.
    Hope this helps.
    Donnie

  • Trying to keep track of how many objects I create

    Hello everyone I'm trying to keep track of how many message objects I created and Assign them to a data member.
    Right now it assigns all the Message objects the same number at the end which is 3. I wanted it to assign 1 to the first object it create, 2 for the 2nd, and 3 for the 3rd.
    here's a small version of my code:
    package ss;
    import java.util.ArrayList;
    import java.util.Iterator;
    public class MainTest {
         public static void main(String [] args)
              Message msg = null;
              ArrayList<Message> msgList = new ArrayList<Message>();
              for(int i = 0; i < 3; i++)
                   msg = new Message();
                   msgList.add(msg);
              System.out.println(msgList);
    package ss;
    //this class will hold the Event/Message
    import java.util.List;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.ArrayList;
    import java.util.Set;
    import java.util.Iterator;
    public class Message {
         //these are datamembers that will be used during
         //the sending of the message to the reciever
         //PacketID should be incremented each time a new message is created
         static int PacketID = 0;
         Message()
              PacketID +=1;
         public String toString() {
              return("PacketID: " + this.PacketID
                        + "\n");
    }output:
    [PacketID: 3
    , PacketID: 3
    , PacketID: 3
    Any ideas what I'm doing wrong?
    Thanks!

    Thanks BigDaddyLovehandles,
    Well there's the problem, I just posted a simpler problem to a bigger one. So I am keeping them in a collection as you can see below.
    I'm keeping these message stored in a multi map, and it is multi-threaded. Everytime a user connects to my server I create a new thread, and start adding the "messages" to the database.
    But I must have a packetID, meaning every new message created I need to assign that number to the message object.
    I also see a problem with this like you said, its not thread safe, if 2 clients connect to the server, and both send me events, there are going to be 2 different maps, copying events from the client and storing them in their own seperate databases.
    This might not be a problem because after I get the events on each thread, i send them to another server for processing.
    Here's an example of what my database looks like that stores the messages:
    //this class should store all the Messages or "Events" and
    //you can access them based on their Serial key.
    public class MessageDB {
         //database to hold the information
         //     holds the Alerts/messages
         Map<String, List<Message>> AlertMap;
         //Constructor
         MessageDB() {
              AlertMap = new HashMap<String, List<Message>>();
         //print, outputs the contents of the hashMap
         public void print() {
              //want to print out the Key and all the Messages
              //associated with that key
              //print, outputs the contents of the hashMap
                   for (String key : AlertMap.keySet())
                        System.out.println("\n\nSerial (key): " + key
                                  + "\nValues in Map: \n" + AlertMap.get(key));
         void add(Message msg) {
              //getting the position of the List by EntityID if avaiable
              List<Message> AlertList = AlertMap.get(msg.Serial);
              //checking to see if there is a unique Key already in the Map.
              if (AlertList == null) {
                   //if there isnt a key in the map, add a new key, and a new List mapping
                   //to the key EntityID;
                   AlertList = new ArrayList<Message>();
                   AlertMap.put(msg.Serial, AlertList);
                   AlertList.add(msg);
              } else {
                   //adding message to List
                   AlertList.add(msg);
         }Any suggestions on what I can to number all these messages and it will be thread safe?

  • How can I keep track of ans of quest ???? [Struts]

    hi,
    I am trying to develop Question-Answer pages using struts.
    The problem is when user selectes the right option(radio button) of different different quest. how can i keep track of these selected radio buttons ???
    I mean how can i trace the value of selected radio button corresponding to its quest. in my ActionForm and ActionClass.
    //loop for all questions
    <logic:notEmpty name="QUEST_LIST">
         <logic:iterate id="list" name="QUEST_LIST"  indexId="sno">     
         <tr>
              <td><%=(sno.intValue()+1) %>
              </td>
              <td> <bean:write name="list" property="QUESTION" />
              </td>               
         </tr>
         <tr>//loop for all options of corresponding question
    <logic:iterate id="OptionList" name="list" property="OPTION_LIST">
              <td> 
              </td>
              <td><INPUT type="radio" name="<bean:write name="list" property="QUESTION_ID" />" value="<bean:write name="OptionList" />">
                   <bean:write name="OptionList" />
              </td>
              </logic:iterate>
         </tr>     
         <tr><td> </td>
         </tr>
         </logic:iterate>
    </logic:notEmpty>Now my problem is in statement.....
    INPUT type="radio" name="<bean:write name="list" property="QUESTION_ID" />" value="<bean:write name="OptionList" />">
    if I hardcode the valueof "name" attribute then only one radio button is selected from all the question, so i created it dynamically using quesID.
    now its working fine only one radio can be selected for each quest. BUT how I set the values of these selected radio button in my ActionForm and get it into ActionClass
    I hope u understand what i am trying to say.....
    Please help me......

    hi,
    try "last" in the client's terminal. is this what you are looking for?
    cheers,
    Michael.

  • How do I keep track of dialog boxes?

    If I have a three question test, How do I keep track of the answers?

    OK a bit of sanity.
    you have a 3 question test.
    presumably you have a 3 element array of questions (Strings?)
    String[] questions = {"What is 1 + 1","What is 2 + 2","What is 3 + 3"};
    in a loop you ask each question, then get the response to each.
    String answer = .....readLine();
    if you change this to an object
    class Question
      String question;
      String answer;
      public Question (String q){question = q;}
    }then your array looks like this
    Question[] questions = {new Question("What is 1 + 1"), etc
    so now the display of the question changes from
    System.out.print(questions[x]);
    to
    System.out.print(questions[x].question);
    likewise for the answer
    from
    String answer = .....readLine();
    to
    questions[x].answer = .....readLine();
    now, in your Question array, each 'question' stores the answer received

  • How do I keep track of stats and subscriptions of my podcast? Mine was just added today.

    My podcast, The Big Seance Podcast, was just added to iTunes today. Other than keeping track of stats through my host (Libsyn), how can I keep track of subscriptions, ratings, and downloads through itunes? Thanks!

    Hi Patrick,
    You will not get any stats from Apple / iTunes.  You need to get that info from your libsyn account.
    If you want to see the number of people consuming via iTunes or the Podcasts App (AppleCoreMedia) - you will need to have the advanced stats - App 400 or greater level account in Libsyn.
    That is the only way to get the info you are looking for.
    Regards,
    Rob W

  • How does DIAdem keep track of which version is active when multiple versions are installed?

    I need a way to find out which version of DIAdem is active, without creating an automation reference. How does DIAdem keep track of this? I don't think it's through the registry as far as I can tell. Thanks.

    Hi,
    I'm not quite sure what you mean by "version of DIAdem is active". If you are trying to reference DIAdem from an external program, you will need to use an automation reference. Besides this case, I am not sure what you are referring to.
    Perhaps a short description of your application or intended use will help me point you in the right direction.
    Allen P.
    National Instruments

  • My IPad has been stolen and I was trying to track it on 'find my ipad' but the thief kept it offline. I just saw him change my user id. Any recommendations on how I can keep tracking the stolen device?

    My IPad has been stolen and I was trying to track it on 'find my ipad' but the thief kept it offline. I just saw him change my user id. Any recommendations on how I can keep tracking the stolen device?

    Yes, I filed police report, but there is nothing they can do until I get back to them on the tracking. It's been offline. I'm sure the whoever took it can find a way around breaking in the ipad..i really was hoping to get my pictures and videos of my kids back

  • How do I keep track of when a signal hits a certain voltage?

    I am fairly new to Labview, and I am having trouble with the following.  I am working on replacing a Digital Vector Filter with Labview software.  I have a rotating shaft with eccentricities, which are measured by X and Y proximitors.  Also, a keyphasor voltage keeps track of the rotation rate, which enables me to relate X and Y to each other. Essentially, I have to find when the keyphasor voltage hits -11 volts, and keep track of when that happens, then, keep track of the next time that happens, in order to get the time it takes for one revolution. I don't know if this makes a difference, but the data is coming in as dynamic data.  I want to be able to tell the user what the rotational rate is as the program is running.

    Thanks for the help!
    I have taken the vi you gave me and changed it to a bit.  The voltage going in is being sampled rather quickly, and thus there is no actual point that equals -11 Volts. I want to do something like the following: Check timer time, tm, and check:
    if tm-1 > -11 Volts   and tm < -11  
    do the following calculation to get the actual value time that voltage crosses -11 Volts, tk.
    tk= (tm-1) + (  (tm- (tm-1)     ) / ( Km - (Km-1)  ) )  *  (-11-(Km-1)),      where Km is the voltage at tm.
    I want to be able to do this streaming, to show the user what the tk value is live.  The only times I really need to save are tm and tm-1, from there I can save all the tk's in an array for further analysis.
    Please let me know if this is possible.
    Thanks 
    Attachments:
    keyphasordata.xls ‏1773 KB
    Barebones.vi ‏90 KB

  • I have itune on my first computer, but i cant download it for my other one,how can i do that, i tryed many time with the link it says you download it but nothing follows  thank you

    I have itune on my first computer, but i cant download it for my other one, how can i do that, i tryed many time with the link it says you download it but nothing follows  thank you

    I'd first try downloading an installer from the Apple website using a different web browser:
    http://www.apple.com/itunes/download/
    If you use Firefox instead of IE for the download (or vice versa), do you get a working installer?

  • My ipad mini is keep on crashing. reboot many times. after the apple logo shows up, the screen will turn into black again.

    my ipad mini is keep on crashing. reboot many times. after the apple logo shows up, the screen will turn into black again.

    Try the following:
    1. Reset
    Hold the Sleep and Home button down until you see the Apple logo
    2. Restore:
    http://support.apple.com/kb/HT1414
    3. Recovery:
    http://support.apple.com/kb/HT1808

  • Tracking every time a method is called in some object?

    Hi,
    I would like to use reflection to log every time some method is called in an object.
    Example;
    public class A {
    public void x () { }
    public void y () { }
    I would like some automatic mechanism that would allow me to register this object such that every time method x() is called, I have a System.out.println (or some other logging) saying "method 'x' called" and the same for every time method y() is called ... without having to modify the body of each method I want to track. If I have to put my logging calls into every method, then it defeats the purpose of what I'm trying to accomplish.
    Thank you,
    Gene

    If your method calls are through an interface, set up a proxy that logs the calls using java.lang.reflect.Proxy.
    If they're through a class, you can't use reflection and need to either use code generation or bytecode manipulation (either roll your own or use an aspect oriented programming kit - logging is the canonical AOP example).
    Pete

  • HT204053 how do i keep track of my stolen iphones location?

    I useed the find my phone app and was able to locate my iphone yesterday. I made it make a noise, put it in lost mode and then i erased. I recieved four mails  want toiApple giving me proof of what I had already sone to my iphone but I wanted to keep track of my phone and I  dont know how  or where to start again. Please help...

    Once you selected ERASE, you eliminated the ability to track the device.  Sorry.

  • How can I keep tracks playing when I'm browsing?

    There must be an obvious answer to this question, but I don't know what it is.
    If I'm playing an album, but then start to browse somewhere else (as one would do if listening to a CD), the music will stop after the track has finished, and not go on to the next track. (because the tracks are no longer in the browser window)
    How can I keep playing what I want, in the order that I want, while I am browsing other music?
    Thanks

    I find this to be a problem as well, especially since I know I was able to work with iTunes this way before I installed iTunes 7.3?
    I'm reading some other posts which suggest that being able to play tracks from an library subset (genre, album, artist) AND browse other playlists at the same time was never a feature of iTunes.
    Since I know I'm not imagining that I used to use iTunes quite happily, I'm wondering is there an option in 7.3 that I'm not paying attention to?
    It seems crazy not to be able to do this.

Maybe you are looking for