IncrementPointer( )

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lenin42001
    New Member
    • Jan 2007
    • 29

    #1

    IncrementPointer( )

    Add the following to class Store.
    private int current =0;
    public incrementPointe r()
    // pre: store is not empty
    // post: increments current;
    // if current is already pointing to the
    // last record in the Store then reset it to 0

    Please can someone help. We have to increment a class Store as part of an assignment. We have to read & write an array of files so stored to a folder. the first part of the assignment is as above but what does it mean exactly? Store inherits from "Person", "Date" & "Employee" if this makes any sense.What is an increment pointer exactly? Thanks
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    This is not a site that gives out solutions to homework (but you already know that, with 20 posts)....
    Mind you we are more than willing to help if you can clearly specify the exact nature of your problem....

    To help you in your problem, we need to know a little more information (what a Store is? I assume it is a class you have already created, but what is it's' function so far....etc)
    We would also like to know how you might approach the problem, whether you have had any ideas and specifically where it is that you're stuck.

    I'm sure if you post a little bit you're stuck on, then we can gradually work through the problem (just post again when you hit the next snag)...and hopefully help you to not just complete the assignment, but understand it as well....

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by lenin42001
      Add the following to class Store.
      private int current =0;
      public incrementPointe r()
      // pre: store is not empty
      // post: increments current;
      // if current is already pointing to the
      // last record in the Store then reset it to 0

      Please can someone help. We have to increment a class Store as part of an assignment. We have to read & write an array of files so stored to a folder. the first part of the assignment is as above but what does it mean exactly? Store inherits from "Person", "Date" & "Employee" if this makes any sense.What is an increment pointer exactly? Thanks
      Not everything here makes sense. You need to explan more clearly your goal, what you have done so far in trying to achieve that goal and where you are finding difficulty.

      Comment

      • lenin42001
        New Member
        • Jan 2007
        • 29

        #4
        public class Store
        {
        private Person list[];
        private int count;
        private int maxSize;
        private int current;


        // constructor

        public Store(int max)
        {
        list = new Person[max];
        maxSize = max;
        count = 0;
        current = 0;
        }

        // transformer



        public void add (Person p)
        {
        // pre p is not null and the store is not full
        // post p is added to array
        list[count] = p;
        count ++;
        }

        // accessors

        public boolean isFull()
        {
        // post returns true if no more room in store
        return count == maxSize;
        }


        public int getCount()
        {
        // returns the number of elements currently in store
        return count;

        }

        public Person elementAt(int index)
        {
        ///pre 0 <= index < getCount
        return list[index];
        }

        public boolean isIn(Person p)
        {
        // returns true if p is stored
        boolean found = false;
        for (int index = 0; index < count; index ++)
        if (p.equals(list[index]))
        found = true;
        return found;
        }

        //output method

        public void displayAll()
        {
        // displays the contents of store on screen
        for (int index = 0; index < count; index ++)
        System.out.prin tln(list[index]);

        }




        }
        Here is infamous store from an earlier assignment.
        Requirements You are required to produce a system that allows a user to do the following:
        a) Employee record using a form displayed on the screen; note: an employee record includes all the data items inherited from Person. b) save the entered record to a store;
        c) retrieve and display records from the store; each time this
        option is selected the next record is displayed; when the end of the store is reached the first record is displayed;
        d) save a store to a file;
        e) retrieve a store from a file.
        Person & Employee are similar classes which are inherited from. What we don't understand is what the increment pointer is trying to do & how. We appreciate it is a method of one sort of another, but does it require an operator or boolean or what?

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by lenin42001
          public class Store
          {
          private Person list[];
          private int count;
          private int maxSize;
          private int current;


          // constructor

          public Store(int max)
          {
          list = new Person[max];
          maxSize = max;
          count = 0;
          current = 0;
          }

          // transformer



          public void add (Person p)
          {
          // pre p is not null and the store is not full
          // post p is added to array
          list[count] = p;
          count ++;
          }

          // accessors

          public boolean isFull()
          {
          // post returns true if no more room in store
          return count == maxSize;
          }


          public int getCount()
          {
          // returns the number of elements currently in store
          return count;

          }

          public Person elementAt(int index)
          {
          ///pre 0 <= index < getCount
          return list[index];
          }

          public boolean isIn(Person p)
          {
          // returns true if p is stored
          boolean found = false;
          for (int index = 0; index < count; index ++)
          if (p.equals(list[index]))
          found = true;
          return found;
          }

          //output method

          public void displayAll()
          {
          // displays the contents of store on screen
          for (int index = 0; index < count; index ++)
          System.out.prin tln(list[index]);

          }




          }
          Here is infamous store from an earlier assignment.
          Requirements You are required to produce a system that allows a user to do the following:
          a) Employee record using a form displayed on the screen; note: an employee record includes all the data items inherited from Person. b) save the entered record to a store;
          c) retrieve and display records from the store; each time this
          option is selected the next record is displayed; when the end of the store is reached the first record is displayed;
          d) save a store to a file;
          e) retrieve a store from a file.
          Person & Employee are similar classes which are inherited from. What we don't understand is what the increment pointer is trying to do & how. We appreciate it is a method of one sort of another, but does it require an operator or boolean or what?
          1.)You do not have to post your homework code
          2.)If you really have to post code please do so using code tags
          3.)The store class should have a pointer (in this case int will do) that points to the currently displayed item. It should have signature
          Code:
           public void incrementPointer()

          Comment

          • lenin42001
            New Member
            • Jan 2007
            • 29

            #6
            YEH I'D ALREADY GOT THAT...It was kind of you and all that, but what is the incrementPointe r trying to do? Is it pointing to a particular name in the store?There is another part to the question. Shall I send it?

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by lenin42001
              YEH I'D ALREADY GOT THAT...It was kind of you and all that, but what is the incrementPointe r trying to do? Is it pointing to a particular name in the store?There is another part to the question. Shall I send it?
              incrementPointe r increments the value of the variable current (which points to the currently displayed person the Store). You need to make sure it caters for all scenarios. If you have completed all the other parts you can go ahead to the next part but make sure you try it first before you post. Post only if you really feel you are suck with it.

              Comment

              Working...