Created
September 20, 2017 00:47
-
-
Save btforsythe/e1daa52b374dfa2a5804e5e7ec37725b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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; | |
| } | |
| } |
This file contains hidden or 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
| 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); | |
| } | |
| } |
This file contains hidden or 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
| 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