Task - DVD Class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jmarcrum
    New Member
    • Oct 2007
    • 105

    #16
    Originally posted by jmarcrum
    if i do this though...

    Code:
    /**
        * Query: returns the DVD serial number
        */
        public static int getSerialNumber()
        {
          return serialNumber; // returns the serial number
        }
    i get an error...because of how ive defined it above...

    Error: non-static variable serialNumber cannot be referenced from a static object
    Ok, i figured it out finally...

    Code:
    /**
        * Query: returns the DVD serial number
        */
        public static int getSerialNumber()
        {
          serialNumber = serialNumber + 1;
          return serialNumber; // returns the serial number
        }
    I made the serialNumber variable a public static int up top in my declarations as well.

    Code:
    public static int serialNumber = 0; // int static variable for the DVD serialNumber
    So my ONLY other question that exists is....i tried to convert getsectorNumber to long and pass double minutes through it....but i get nothing in my output. According to the project spec up top, i should be getting...somet hing.

    Code:
    /**
        * Query: returns the DVD sector number
        */
        public long getSectorNumber(double length)
        {
          return (long)sectorNumber; // returns the sector number
        }

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #17
      Static variables are shared among all instances of the same class. So all your DVDs would have the same serial number. The advice given by SmallDaddy was to use a static variable to remember the last id that was generated rather than to use a static serial number.

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #18
        Originally posted by jmarcrum
        So my ONLY other question that exists is....i tried to convert getsectorNumber to long and pass double minutes through it....but i get nothing in my output. According to the project spec up top, i should be getting...somet hing.

        Code:
        /**
            * Query: returns the DVD sector number
            */
            public long getSectorNumber(double length)
            {
              return (long)sectorNumber; // returns the sector number
            }
        This is confusing. Is the SectorNumber a long or a double? Choose one and stick to it. Then the code will be trivial: just another field+setter+ge tter. Nothing to it. But the code quoted here makes no sense. You pass it parameter length, which is not used in the body of the method! Stare at this code and think about what you really want to do. Why is a simple getter passed any parameter?

        Comment

        Working...