473,770 Members | 4,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

super class function

105 New Member
Hi everyone!

I'm using a super class (DVD.java) that handles another class (EnhancedDVD.ja va). I want to pass the "details" of the DVD into the super class DVD.java. The super class contains the Title, RegionCode, Format, and Length of a dummy DVD...let's say..."Forrest Gump." But I can't figure out how to do this and I have 4 errors going on when I compile the two classes. I have a driver that runs the System.out.prin tln's. But I think it might be handling the classes wrongly as well. Any help? What am I doing wrong?

I want to take this one step at a time. First I'd like to just print out the "details" of the DVD, not worrying about the toString method in the DVD.java class.

But anyways...here' s my code for the two classes and the driver. I'll bold where my errors exist, they exist in the ENHANCEDDVD.jav a class...i have 3 errors

DVD.java class
--------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * File: DVD.java
  3.  * Author:
  4.  * Vers: 1.0.0.0, 1/31/2008, jdm - Initial coding
  5.  * Vers: 1.0.0.1, 2/19/2008, jdm - modified for TUI
  6.  * Vers. 1.0.0.2, 2/28/2008, jdm - modified for super class
  7.  * Desc: This program models a DVD in several ways.
  8.  */
  9.  
  10. /**
  11. * Beginning of the DVD class
  12. */
  13. public class DVD
  14. {
  15.     public static final int REGION_FREE = 0; // Final variable for the DVD region_free code
  16.     public static final int NTSC_FORMAT = 1; // Final variable for the DVD NTSC_format
  17.     public static final int PAL_FORMAT = 2; // Final variable for the DVD PAL_format
  18.     public static final int DVD_SECTOR_SIZE = 2048; // Final variable for the DVD sector size
  19.     public static final int DATA_RATE = 4096 * 1000; // Final variable for the DVD sector size in bytes
  20.  
  21.     public static int serialNumberDVD = 0; // int static variable for the DVD serial number
  22.     public static int region; // int variable for the DVD region
  23.     public static int format; // int variable for the DVD format
  24.     public static String title; // String variable for the DVD title
  25.     public static double length = 0.0; // double variable for the DVD length in minutes
  26.  
  27.     private int sectorNumber = 0; // int variable for the DVD length in minutes
  28.  
  29.     /**
  30.     * Constructor: builds the DVD object
  31.     */
  32.     public DVD(String title, int region, int format, double length)
  33.     {      
  34.       this.title = title; // initialization of title
  35.       this.region = region; // initialization of region
  36.       this.format = format; // initialization of format
  37.       this.length = length; // initialization of length
  38.  
  39.       serialNumberDVD = serialNumberDVD + 1; // increments the serial number
  40.     }    
  41.  
  42.     //Queries:-----------------------------------------
  43.  
  44.     /**
  45.     * Query: getClassAuthor
  46.     */ 
  47.     public static String getClassAuthor() // returns name of class’ author (my name)
  48.     {  
  49.       return " my name " + "\n"; // returns my name
  50.     }
  51.  
  52.     /**
  53.     * Query: returns the DVD sector number
  54.     */
  55.     public long getSectorNumber(double minutes)
  56.     {
  57.       long bytesToGoThrough = (long)(minutes * 60 * DATA_RATE) / 8; // converts to bits
  58.       long sectorNumber = bytesToGoThrough / DVD_SECTOR_SIZE + 1024; // computes the sector size of the DVD
  59.       return sectorNumber; // returns the sector number
  60.     }
  61.  
  62.     /**
  63.     * Query: returns the DVD serial number
  64.     */
  65.     public static int getSerialNumberDVD()
  66.     {
  67.       return serialNumberDVD; // returns the serial number
  68.     }
  69.  
  70.     /**
  71.     * Query: returns the DVD title
  72.     */
  73.     public static String getTitle()
  74.     {
  75.       if (region >= 0 && region <= 8) // conditional AND statement
  76.         {
  77.           return title; // return DVD title
  78.         }
  79.         else
  80.         {
  81.           return "Bad Region Code"; // return Bad Region Code
  82.         }
  83.     }
  84.  
  85.     /**
  86.     * Query: returns the DVD region
  87.     */
  88.     public int getRegion()
  89.     {
  90.       return region; // returns the DVD region
  91.     }
  92.  
  93.     /**
  94.     * Query: returns the DVD format
  95.     */
  96.     public int getFormat()
  97.     {
  98.       return format; // returns the DVD format
  99.     }
  100.  
  101.     /**
  102.     * Query: returns the DVD length
  103.     */
  104.     public double getLength()
  105.     {
  106.       return length; // returns the DVD length
  107.     }
  108.  
  109.     //Commands:--------------------------------------------
  110.  
  111.     /**
  112.     * Command: toString
  113.     */
  114.     public String toString() // returns a text representation of all the data pertaining to a given 
  115.                              // DVD: "serial number, title, region, format, length."
  116.     {                             
  117.       // return of the full DVD printable object - formatted as a form
  118.       // (properly formatted for display, and without the quotes).
  119.       return "\n" + "Serial Number: " + getSerialNumberDVD() + "\n" + 
  120.         "Title: " + getTitle() + "\n" + 
  121.         "Region Code: " + getRegion() + "\n" + 
  122.         "Format: " + getFormat() + "\n" + 
  123.         "Length: " + getLength();
  124.     }
  125. }
EnhancedDVD.jav a
------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * File: EnhancedDVD.java
  3.  * Author:
  4.  * Vers: 1.0.0.0, 3/4/2008, jdm - Initial coding
  5.  * Desc: This class gathers "details" for a DVD
  6.  */
  7.  
  8. /**
  9.  * Beginning of the EnhancedDVD class.
  10.  */ 
  11. public class EnhancedDVD implements DVD
  12. {
  13.   public String dvdDetails = ""; // string DVD details
  14.   /**
  15.    * Constructor: EnhancedDVD constructor that passes in the initial DVD details (dvdDetails).
  16.    */ 
  17.   public EnhancedDVD(String title, int region, int format, double length, String dvdDetails)
  18.   { 
  19.     super(title, region, format, length); // passes the dvdDetails into the EnhancedDVD constructor    this.dvdDetails = dvdDetails; // assign this dvdDetails to dvdDetails
  20.   } 
  21.  
  22.   // --------------- Beginning of queries ---------------------------
  23.  
  24.   /**
  25.    * Query: getdvdDetails
  26.    */
  27.   public String getDetails()
  28.   {
  29.     return dvdDetails; // return of the DVD's details
  30.   }
  31.  
  32.   // --------------- Beginning of commands ---------------------------
  33.  
  34.   /**
  35.    * Command: setDVDDetails
  36.    */
  37.   public static void setDetails(String DetailsOfDVD)
  38.   {
  39.     this.dvdDetails = DetailsofDVD; // sets the DVD's details
  40.   }
  41.  
  42.   public String toString() // returns a text representation of all the data pertaining to a given 
  43.                            // DVD's details: stars of the movie, movie rating, genre, basic plot, etc., etc., 
  44.   {                             
  45.     // return of the details of the DVD printable object - formatted as a form
  46.     // (properly formatted for display, and without the quotes).
  47.     return "\n" + "Details: " + getDetails();
  48.   }
  49. }
Driver class
----------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * File: Driver5.java
  3.  * Author:  
  4.  * Vers: 1.0.0.0, 2/28/2008, jdm - Initial coding
  5.  * Desc: This is a driver for the program
  6.  */
  7.  
  8. public class Driver5 {
  9.  
  10.     public static void main(String[] args) {
  11.  
  12.         System.out.println("Spring 2008 P5 by " + DVD.getClassAuthor()); // print my name as author
  13.  
  14.         EnhancedDVD newDVD = new EnhancedDVD("Forrest Gump", 1, DVD.NTSC_FORMAT, 200.); // creates the newDVD object
  15.         EnhancedDVD.setDetails("Stars: Tom Hanks, Robin White" + "\n" +
  16.                           "Rating: PG-13" + "\n" + 
  17.                           "Genre: Drama" + "\n" + 
  18.                           "Plot: The title character leads viewers through an accidental" + "\n" + 
  19.                           "travelogue of American social history from the early 1960s" + "\n" +
  20.                           "through the present in this revisionist fable."); 
  21.  
  22.         //System.out.println(newdvd); // print dvd
  23.  
  24.         //System.out.println("Last Sectors:"); // print DVD sectors
  25.         //System.out.println("For \"" + dvd.getTitle() + "\": " + 
  26.         //                     dvd.getSectorNumber(dvd.getLength())); // print dvd1 sectors    
  27.  
  28.         System.out.println(newDVD); // print the details of the DVD
  29.     }
  30. }
Feb 29 '08 #1
6 2142
BigDaddyLH
1,216 Recognized Expert Top Contributor
I didn't look at your code too closely because as soon as I started reading, I saw that you have some basic misconceptions. Do you understand "static"?

What is the difference between a static field and a non-static (instance) field?

How does one determine which to use?

There are basic questions and you not should write another line of code until you can answer these questions without hesitation.
Feb 29 '08 #2
jmarcrum
105 New Member
I didn't look at your code too closely because as soon as I started reading, I saw that you have some basic misconceptions. Do you understand "static"?

What is the difference between a static field and a non-static (instance) field?

How does one determine which to use?

There are basic questions and you not should write another line of code until you can answer these questions without hesitation.
don't you use static if you want to KEEP something from changing? The things I have made static are that way for a reason. If i delete the static assignment I get MORE errors. Also, for other concepts...use public and private if you want to be able to reference the instance variables via their respective class from other classes
Feb 29 '08 #3
BigDaddyLH
1,216 Recognized Expert Top Contributor
don't you use static if you want to KEEP something from changing?
No, I'm afraid that's got absolutely nothing to do with the keyword static. You should review the language basics. Here is a page from Sun's tutorial that talks about static:
http://java.sun.com/docs/books/tutor...classvars.html

The things I have made static are that way for a reason. If i delete the static assignment I get MORE errors.
I'm afraid that's not a reason. That's voodoo. Just because one error leads you to make more errors doesn't make any of the errors, uh, not an error.

What you need to do is understand static then use it where it's needed and don't use it where it's wrong to use it.

My rule of thumb is to almost never use it, except for three spots:

1. You program's main method is required to be static
2. Constants can be static:

Expand|Select|Wrap|Line Numbers
  1. public static final int DALMATIONS = 101;
3. Utility classes like java.lang.Math can have static methods (sqrt, sin, cos, ...)
Feb 29 '08 #4
jmarcrum
105 New Member
No, I'm afraid that's got absolutely nothing to do with the keyword static. You should review the language basics. Here is a page from Sun's tutorial that talks about static:
http://java.sun.com/docs/books/tutor...classvars.html



I'm afraid that's not a reason. That's voodoo. Just because one error leads you to make more errors doesn't make any of the errors, uh, not an error.

What you need to do is understand static then use it where it's needed and don't use it where it's wrong to use it.

My rule of thumb is to almost never use it, except for three spots:

1. You program's main method is required to be static
2. Constants can be static:

Expand|Select|Wrap|Line Numbers
  1. public static final int DALMATIONS = 101;
3. Utility classes like java.lang.Math can have static methods (sqrt, sin, cos, ...)
I appreciate you pointing me in the right direction BigDaddyLH. i understand where i need to be going. I've actually changed my code a good bit since my last post now that I am in the right mindset! I changed my code to now look like this...however, I'm getting 1 other error...you are absolutely right about errors.

The error is in my EnhancedDVD.jav a class on line 33 (this.dvdDetail s = DetailsOfDVD; // sets the DVD's details
). Could you please point in in the right direction one more time? IT IS an error about a static variable....als o, i need to print out the DVD''s toString method as well...but how would i do that?

I'm such a newbie at this stuff!!!

I would greatly appreciate it BigDaddyLH!!!!! !!

DVD.java
-----------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. /**
  2. * Beginning of the DVD class
  3. */
  4. public class DVD
  5. {
  6.     public static final int REGION_FREE = 0; // Final variable for the DVD region_free code
  7.     public static final int NTSC_FORMAT = 1; // Final variable for the DVD NTSC_format
  8.     public static final int PAL_FORMAT = 2; // Final variable for the DVD PAL_format
  9.     public static final int DVD_SECTOR_SIZE = 2048; // Final variable for the DVD sector size
  10.     public static final int DATA_RATE = 4096 * 1000; // Final variable for the DVD sector size in bytes
  11.  
  12.     public static int serialNumber = 0; // int static variable for the DVD serialNumber
  13.  
  14.     private String title; // String variable for the DVD title
  15.     private int region; // int variable for the DVD region
  16.     private int format; // int variable for the DVD format
  17.     private double length = 0.0; // double variable for the DVD length in minutes
  18.     private int sectorNumber = 0; // int variable for the DVD length in minutes
  19.  
  20.     /**
  21.     * Constructor: builds the DVD object
  22.     */
  23.     public DVD(String title, int region, int format, double length)
  24.     {
  25.         this.title = title; // initialization of title
  26.         this.region = region; // initialization of region
  27.         this.format = format; // initialization of format
  28.         this.length = length; // initialization of length
  29.  
  30.         serialNumber = serialNumber + 1; // increments the serial number
  31.     }    
  32.  
  33.     //Queries:-----------------------------------------
  34.  
  35.     /**
  36.     * Query: getClassAuthor
  37.     */ 
  38.     public static String getClassAuthor() // returns name of class’ author (my name)
  39.     {  
  40.       return "my name" + "\n"; // returns my name
  41.     }
  42.  
  43.     /**
  44.     * Query: returns the DVD sector number
  45.     */
  46.     public long getSectorNumber(double minutes)
  47.     {
  48.       long bytesToGoThrough = (long)(minutes * 60 * DATA_RATE) / 8; // converts to bits
  49.       long sectorNumber = bytesToGoThrough / DVD_SECTOR_SIZE + 1024; // computes the sector size of the DVD
  50.       return sectorNumber; // returns the sector number
  51.     }
  52.  
  53.     /**
  54.     * Query: returns the DVD serial number
  55.     */
  56.     public static int getSerialNumber()
  57.     {
  58.       return serialNumber; // returns the serial number
  59.     }
  60.  
  61.     /**
  62.     * Query: returns the DVD title
  63.     */
  64.     public String getTitle()
  65.     {
  66.       return title; // returns the title
  67.     }
  68.  
  69.     /**
  70.     * Query: returns the DVD region
  71.     */
  72.     public int getRegion()
  73.     {
  74.       return region; // returns the region
  75.     }
  76.  
  77.     /**
  78.     * Query: returns the DVD format
  79.     */
  80.     public int getFormat()
  81.     {
  82.       return format; // returns the format
  83.     }
  84.  
  85.     /**
  86.     * Query: returns the DVD length
  87.     */
  88.     public double getLength()
  89.     {
  90.       return length; // returns the length
  91.     }
  92.  
  93.     //Commands:--------------------------------------------
  94.  
  95.     /**
  96.     * Command: toString
  97.     */
  98.     public String toString() // returns a text representation of all the data pertaining to a given DVD: "serial number, title, region, format, length."
  99.     {                             
  100.         // return of the full DVD printable object - formatted as a form
  101.         // (properly formatted for display, and without the quotes).
  102.         return "Serial Number: " + getSerialNumber() + "\n" + 
  103.           "Title: " + getTitle() + "\n" + 
  104.           "Region: " + getRegion() + "\n" + 
  105.           "Format: " + getFormat() + "\n" + 
  106.           "Length: " + getLength() + "\n"; 
  107.     }
  108. }
EnhancedDVD.jav a
---------------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * Beginning of the EnhancedDVD class.
  3.  */ 
  4. public class EnhancedDVD extends DVD
  5. {
  6.   public String dvdDetails = ""; // string DVD details
  7.   /**
  8.    * Constructor: EnhancedDVD constructor that passes in the initial DVD details (dvdDetails).
  9.    */ 
  10.   public EnhancedDVD(String title, int region, int format, double length)
  11.   { 
  12.     super(title, region, format, length); // passes the DVD class instance variables into the EnhancedDVD constructor
  13.     this.dvdDetails = dvdDetails; // assign this dvdDetails to dvdDetails
  14.   } 
  15.  
  16.   // --------------- Beginning of queries ---------------------------
  17.  
  18.   /**
  19.    * Query: getdvdDetails
  20.    */
  21.   public String getDetails()
  22.   {
  23.     return dvdDetails; // return of the DVD's details
  24.   }
  25.  
  26.   // --------------- Beginning of commands ---------------------------
  27.  
  28.   /**
  29.    * Command: setDVDDetails
  30.    */
  31.   public static void setDetails(String DetailsOfDVD)
  32.   {    
  33.     this.dvdDetails = DetailsOfDVD; // sets the DVD's details
  34.     File: C:\Desktop\EnhancedDVD\EnhancedDVD.java  [line: 33]
  35.     Error: non-static variable this cannot be referenced from a static context 
  36.   }
  37.  
  38.   public String toString() // returns a text representation of all the data pertaining to a given 
  39.                            // DVD's details: stars of the movie, movie rating, genre, basic plot, etc., etc., 
  40.   {                             
  41.     // return of the details of the DVD printable object - formatted as a form
  42.     // (properly formatted for display, and without the quotes).
  43.     return "Details: " + getDetails();
  44.   }
  45. }
Driver5.java
---------------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. /**
  2. * Beginning of the Driver5 class
  3. */
  4. public class Driver5 {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         System.out.println("Spring 2008 P5 by " + DVD.getClassAuthor()); // print my name as author
  9.  
  10.         EnhancedDVD newDVD = new EnhancedDVD("Forrest Gump", 1, DVD.NTSC_FORMAT, 200.); // creates the EnhancedDVD object
  11.         newDVD.setDetails("Stars: Tom Hanks, Robin White" + "\n" +
  12.                           "Rating: PG-13" + "\n" + 
  13.                           "Genre: Drama" + "\n" + 
  14.                           "Plot: The title character leads viewers through an accidental" + "\n" + 
  15.                           "travelogue of American social history from the early 1960s" + "\n" +
  16.                           "through the present in this revisionist fable.");     
  17.  
  18.         System.out.println(newDVD); // print the details of the DVD
  19.     }
  20. }
Mar 1 '08 #5
qintao1987
2 New Member
maybe the key reason is the implements misused;

change the imlements to extends
Mar 1 '08 #6
jmarcrum
105 New Member
OK!!!, I got it working....ever ything looks good. Many thanks to everyone who posted!! I would never make it through java alone!!! All i had to do was remove the "static" type like BigDaddyLH said. Here's the final working solution....

DVD.java class
------------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. /**
  2. * Beginning of the DVD class
  3. */
  4. public class DVD
  5. {
  6.     public static final int REGION_FREE = 0; // Final variable for the DVD region_free code
  7.     public static final int NTSC_FORMAT = 1; // Final variable for the DVD NTSC_format
  8.     public static final int PAL_FORMAT = 2; // Final variable for the DVD PAL_format
  9.     public static final int DVD_SECTOR_SIZE = 2048; // Final variable for the DVD sector size
  10.     public static final int DATA_RATE = 4096 * 1000; // Final variable for the DVD sector size in bytes
  11.  
  12.     public static int serialNumber = 0; // int static variable for the DVD serialNumber
  13.  
  14.     public String title; // String variable for the DVD title
  15.     public int region; // int variable for the DVD region
  16.     public int format; // int variable for the DVD format
  17.     public double length = 0.0; // double variable for the DVD length in minutes
  18.     public int sectorNumber = 0; // int variable for the DVD length in minutes
  19.  
  20.     /**
  21.     * Constructor: builds the DVD object
  22.     */
  23.     public DVD(String title, int region, int format, double length)
  24.     {
  25.         this.title = title; // initialization of title
  26.         this.region = region; // initialization of region
  27.         this.format = format; // initialization of format
  28.         this.length = length; // initialization of length
  29.  
  30.         serialNumber = serialNumber + 1; // increments the serial number
  31.     }    
  32.  
  33.     //Queries:-----------------------------------------
  34.  
  35.     /**
  36.     * Query: getClassAuthor
  37.     */ 
  38.     public static String getClassAuthor() // returns name of class’ author (my name)
  39.     {  
  40.       return "Joseph D. Marcrum, III" + "\n"; // returns my name
  41.     }
  42.  
  43.     /**
  44.     * Query: returns the DVD sector number
  45.     */
  46.     public static long getSectorNumber(double minutes)
  47.     {
  48.       long bytesToGoThrough = (long)(minutes * 60 * DATA_RATE) / 8; // converts to bits
  49.       long sectorNumber = bytesToGoThrough / DVD_SECTOR_SIZE + 1024; // computes the sector size of the DVD
  50.       return sectorNumber; // returns the sector number
  51.     }
  52.  
  53.     /**
  54.     * Query: returns the DVD serial number
  55.     */
  56.     public static int getSerialNumber()
  57.     {
  58.       return serialNumber; // returns the serial number
  59.     }
  60.  
  61.     /**
  62.     * Query: returns the DVD title
  63.     */
  64.     public String getTitle()
  65.     {
  66.       return title; // returns the title
  67.     }
  68.  
  69.     /**
  70.     * Query: returns the DVD region
  71.     */
  72.     public int getRegion()
  73.     {
  74.       return region; // returns the region
  75.     }
  76.  
  77.     /**
  78.     * Query: returns the DVD format
  79.     */
  80.     public int getFormat()
  81.     {
  82.       return format; // returns the format
  83.     }
  84.  
  85.     /**
  86.     * Query: returns the DVD length
  87.     */
  88.     public double getLength()
  89.     {
  90.       return length; // returns the length
  91.     }
  92.  
  93.     //Commands:--------------------------------------------
  94.  
  95.     /**
  96.     * Command: toString
  97.     */
  98.     public String toString() // returns a text representation of all the data pertaining to a given DVD: "serial number, title, region, format, length."
  99.     {                             
  100.         // return of the full DVD printable object - formatted as a form
  101.         // (properly formatted for display, and without the quotes).
  102.         return "Serial Number: " + getSerialNumber() + "\n" + 
  103.           "Title: " + getTitle() + "\n" + 
  104.           "Region: " + getRegion() + "\n" + 
  105.           "Format: " + getFormat() + "\n" + 
  106.           "Length: " + getLength() + "\n"; 
  107.     }
  108. }
EnhancedDVD.jav a class
-----------------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * Beginning of the EnhancedDVD class.
  3.  */ 
  4. public class EnhancedDVD extends DVD
  5. {
  6.   public String dvdDetails = ""; // string DVD details
  7.   /**
  8.    * Constructor: EnhancedDVD constructor that passes in the initial DVD details (dvdDetails).
  9.    */ 
  10.   public EnhancedDVD(String title, int region, int format, double length)
  11.   { 
  12.     super(title, region, format, length); // passes the DVD class instance variables into the EnhancedDVD constructor
  13.     this.dvdDetails = dvdDetails; // assign this dvdDetails to dvdDetails
  14.   } 
  15.  
  16.   // --------------- Beginning of queries ---------------------------
  17.  
  18.   /**
  19.    * Query: getdvdDetails
  20.    */
  21.   public String getDetails()
  22.   {
  23.     return dvdDetails; // return of the DVD's details
  24.   }
  25.  
  26.   // --------------- Beginning of commands ---------------------------
  27.  
  28.   /**
  29.    * Command: setDVDDetails
  30.    */
  31.   public void setDetails(String DetailsOfDVD)
  32.   {    
  33.     this.dvdDetails = DetailsOfDVD; // sets the DVD's details 
  34.   }
  35.  
  36.   public String toString() // returns a text representation of all the data pertaining to a given 
  37.                            // DVD's details: stars of the movie, movie rating, genre, basic plot, etc., etc., 
  38.   {                             
  39.     // return of the details of the DVD printable object - formatted as a form
  40.     // (properly formatted for display, and without the quotes).
  41.     return "Title: " + title + "\n" + 
  42.       "Region: " + region + "\n" + 
  43.       "Format: " + format + "\n" + 
  44.       "Length: " + length + "\n" + "\n" +
  45.       getDetails() + "\n";
  46.   }
  47. }
Driver5.java class
-------------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. /**
  2. * Beginning of the Driver5 class
  3. */
  4. public class Driver5 {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         System.out.println("Spring 2008 P5 by " + DVD.getClassAuthor()); // print my name as author
  9.  
  10.         EnhancedDVD newDVD = new EnhancedDVD("Forrest Gump", 1, DVD.NTSC_FORMAT, 200.); // creates the EnhancedDVD object
  11.         newDVD.setDetails("Stars: Tom Hanks, Robin White" + "\n" +
  12.                           "Rating: PG-13" + "\n" + 
  13.                           "Genre: Drama" + "\n" + 
  14.                           "Plot: The title character leads viewers through an accidental" + "\n" + 
  15.                           "travelogue of American social history from the early 1960s" + "\n" +
  16.                           "through the present in this revisionist fable.");     
  17.  
  18.         System.out.println(newDVD); // print the details of the DVD
  19.  
  20.         System.out.println( "Last Sectors:");
  21.         System.out.println( "For \"" + newDVD.title + "\": " + 
  22.                              DVD.getSectorNumber(newDVD.length) ); // print newdvd sectors
  23.     }
  24. }
Mar 1 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
50363
by: Phil Powell | last post by:
<?php class SuperClass { var $mySuperClassVar; function SuperClass($myVar) { $this->mySuperClassVar = $myVar; echo "super class var = $myVar<p>"; }
2
9600
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A, while an instance of class C should be able to check all methods #defined in C, B and A. #------------------------------------------------
11
5035
by: Nicolas Lehuen | last post by:
Hi, I hope this is not a FAQ, but I have trouble understanding the behaviour of the super() built-in function. I've read the excellent book 'Python in a Nutshell' which explains this built-in function on pages 89-90. Based on the example on page 90, I wrote this test code : class A(object): def test(self): print 'A'
2
1789
by: David MacQuigg | last post by:
I think there is a documentation error in both the Library Reference section 2.1 and the Python 2.2 Quick Reference page 19. The explanation for this function is: super( type) Returns the superclass of type. I could not get this function to work right until I realized that it is searching the entire MRO, not just the superclasses of 'type'. Here is a simple experiment to show the difference.
0
1512
by: Delaney, Timothy C (Timothy) | last post by:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286195 This is a new version of super that automatically determines which method needs to be called based on the existing stack frames. It's much nicer for writing cooperative classes. It does have more overhead, but at this stage I'm not so concerned about that - the important thing is it actually works. Note that this uses sys._getframe() magic ...
10
2136
by: Chris Green | last post by:
Good day, I've done a bit of searching in the language reference and a couple pages referring the behavior of super() but I can't find any discussion of why super needs the name of the class as an argument. Feel free to point me into the bowels of google if this has been discussed to death already. super(self).method() seems like super could just do the right thing...
9
1714
by: Paul Rubin | last post by:
I'm trying the super() function as described in Python Cookbook, 1st ed, p. 172 (Recipe 5.4). class A(object): def f(self): print 'A' class B(object): def f(self):
4
1562
by: John Salerno | last post by:
Here's some code from Python in a Nutshell. The comments are lines from a previous example that the calls to super replace in the new example: class A(object): def met(self): print 'A.met' class B(A): def met(self): print 'B.met'
4
3273
by: Noah | last post by:
Am I the only one that finds the super function to be confusing? I have a base class that inherits from object. In other words new style class: class foo (object): def __init__ (self, arg_A, arg_B): self.a = arg_A self.b = arg_B # Do I need to call __init__ on "object" base class?
10
13306
by: Finger.Octopus | last post by:
Hello, I have been trying to call the super constructor from my derived class but its not working as expected. See the code: class HTMLMain: def __init__(self): self.text = "<HTML><BODY>"; print(self.text); def __del__(self): self.text = "</BODY></HTML>"; print(self.text);
0
10237
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.