BenitoDannes

PBO-2.1-2-Book

Mar 6th, 2017
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. /**
  2.  * Fig. 8.10: Book.java
  3.  * Declaring an enum type with constructor and explicit instance
  4.  * fields and accessors for these fields.
  5.  *
  6.  * Benito Danneswara
  7.  * 6 March 2017
  8.  */
  9.  
  10. public enum Book
  11. {
  12.     // declare constants of enum type
  13.     JHTP ("Java How to Program", "2012"),
  14.     CHTP ("C How to Program", "2007"),
  15.     IW3HTP ("Internet & World Wide Web How to Program", "2008"),
  16.     CPPHTP ("C++ How to Program", "2012"),
  17.     VBHTP ("Visual Basic 2010 How to Program", "2011"),
  18.     CSHARPHTP ("Visal C# 2010 How to Program", "2011");
  19.    
  20.     // instance fields
  21.     private final String title; // book title
  22.     private final String copyrightYear; // copyright year
  23.    
  24.     // enum constructor
  25.     Book (String bookTitle, String year)
  26.     {
  27.         title = bookTitle;
  28.         copyrightYear = year;
  29.     } // end enum Book constructor
  30.    
  31.     // accessor for field title
  32.     public String getTitle()
  33.     {
  34.         return title;
  35.     } // end method getTitle
  36.    
  37.     // accessor for field copyrightYear
  38.     public String getCopyrightYear()
  39.     {
  40.         return copyrightYear;
  41.     } // end method getCopyrightYear
  42. } // end enum Book
Advertisement
Add Comment
Please, Sign In to add comment