Skip to content

Instantly share code, notes, and snippets.

@btforsythe
Created September 20, 2017 00:47
Show Gist options
  • Select an option

  • Save btforsythe/e1daa52b374dfa2a5804e5e7ec37725b to your computer and use it in GitHub Desktop.

Select an option

Save btforsythe/e1daa52b374dfa2a5804e5e7ec37725b to your computer and use it in GitHub Desktop.
package library;
public class Book {
private String title;
private String isbn;
private String author;
private String category;
public String getTitle() {
return title;
}
public String getIsbn() {
return isbn;
}
public String getAuthor() {
return author;
}
public String getCategory() {
return category;
}
public Book(String title, String isbn, String author, String category) {
this.title = title;
this.isbn = isbn;
this.author = author;
this.category = category;
}
}
package library;
import java.util.HashMap;
import java.util.Map;
public class Library {
Map<String, Book> booksByIsbn = new HashMap<String, Book>();
public void add(Book book) {
booksByIsbn.put(book.getIsbn(), book);
}
}
package library;
public class LibraryApp {
public static void main(String[] args) {
Library myLibrary = new Library();
String title = "The Great Gatsby";
String isbn = "178139685X";
String author = "F. Scott Fitzgerald";
String category = "Classics";
Book gatsby = new Book(title, isbn, author, category);
myLibrary.add(gatsby);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment