Created
October 2, 2012 15:05
-
-
Save benfb/3819899 to your computer and use it in GitHub Desktop.
BBaileyBook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BBaileyBook //the name of the class should be "Book" | |
{ | |
private String bookName; //the variables need to be private because they are instance variables | |
private int bookISBN; //you don't need to assign default values because they are assigned in the constructors | |
public BBaileyBook(){ //default constructor named book that should provide default values ("" and 0, respectively) for the instance variables | |
bookName = ""; //when no arguments are passed, the title defaults to "" | |
bookISBN = 0; //when no arguments are passed, the ISBN defaults to 0 | |
} | |
public BBaileyBook(String name, int isbn){ //creates a book object and assigns the name and isbn arguments to the instance variables | |
bookName = name; //these values are set to something that is passed, not the default | |
bookISBN = isbn; //set to the argument passed when the object is created | |
} | |
//modifier methods | |
public void setName(String newName){ //there is no return type and only one argument should be passed | |
bookName = newName; | |
} | |
public void setISBN(int newISBN){ //the data type of the argument is the same as the type of instance variable | |
bookISBN = newISBN; | |
} | |
//accessor methods | |
public String getName(){ //the accessor returns the same data type of the variable you wouuld have modified | |
return bookName; //returns bookName because it's a return method | |
} | |
public int getISBN(){ //one argument | |
return bookISBN; | |
} | |
//toString method | |
public String toString(){ //The purpose is to provide textual output from an object. It returns a string | |
return "The Title is: " + bookName + "\nThe ISBN is: " + bookISBN; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment