Our Book class really models a specific title in the library. What would we do if we wanted to record the bar code numbers of each copy of that book?
public class Library {
public static void main (String[] args) {
Book b1 = new Book("Jurasic Park");
b1.setBarCode("3423-0");
System.out.println(b1);
b1.setBarCode("3424-1");
System.out.println(b1);
}
}
class Book {
// ... omitting the name and related methods
private String title;
private String barCode;
public Book (String t) {
title = t;
}
public void setBarCode (String code) {
barCode = code;
}
public String toString () {
String result = "Title: " + title;
return result + " Code: " + barCode;
}
}
Title: Jurasic Park Code: 3423-0 Title: Jurasic Park Code: 3424-1