Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds Jamira lesson09 response (#285)
* feat:added laptop class and test * Feat: updated Lesson 09 * Feat: added Book, Patron, and Llibrary File with Test * chore: removes files not relevant to assignment Signed-off-by: Anthony D. Mays <anthony@morganlatimer.com> * fix: code and tests Signed-off-by: Anthony D. Mays <anthony@morganlatimer.com> --------- Signed-off-by: Anthony D. Mays <anthony@morganlatimer.com> Co-authored-by: Anthony D. Mays <anthony@morganlatimer.com>
- Loading branch information
1 parent
dae48c5
commit 97dd93b
Showing
6 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
lesson_09/oop/oop_app/src/main/java/com/codedifferently/lesson9/jamira/Book.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.codedifferently.lesson9.jamira; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class Book { | ||
private String title; | ||
private String isbn; | ||
private List<String> authors; | ||
private int numPages; | ||
private boolean checkedOut; | ||
|
||
public Book(String title, String isbn, List<String> authors, int numPages, boolean checkedOut) { | ||
this.title = title; | ||
this.isbn = isbn; | ||
this.authors = authors; | ||
this.numPages = numPages; | ||
this.checkedOut = checkedOut; // Initially not checked out | ||
} | ||
|
||
// Getters and setters | ||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public String getIsbn() { | ||
return isbn; | ||
} | ||
|
||
public void setIsbn(String isbn) { | ||
this.isbn = isbn; | ||
} | ||
|
||
public List<String> getAuthors() { | ||
return authors; | ||
} | ||
|
||
public void setAuthors(List<String> authors) { | ||
this.authors = authors; | ||
} | ||
|
||
public int getNumPages() { | ||
return numPages; | ||
} | ||
|
||
public void setNumPages(int numPages) { | ||
this.numPages = numPages; | ||
} | ||
|
||
public boolean isCheckedOut() { | ||
return checkedOut; | ||
} | ||
|
||
public void setCheckedOut(boolean checkedOut) { | ||
this.checkedOut = checkedOut; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.isbn); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
lesson_09/oop/oop_app/src/main/java/com/codedifferently/lesson9/jamira/Library.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.codedifferently.lesson9.jamira; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Library { | ||
private List<Book> books; | ||
private List<Patron> patrons; | ||
|
||
// Constructor | ||
public Library() { | ||
this.books = new ArrayList<>(); | ||
this.patrons = new ArrayList<>(); | ||
} | ||
|
||
// Getters and setters | ||
public List<Book> getBooks() { | ||
return books; | ||
} | ||
|
||
public void setBooks(List<Book> books) { | ||
this.books = books; | ||
} | ||
|
||
public List<Patron> getPatrons() { | ||
return patrons; | ||
} | ||
|
||
public void setPatrons(List<Patron> patrons) { | ||
this.patrons = patrons; | ||
} | ||
|
||
public void removeBook(Book bookToRemove) { | ||
this.books.remove(bookToRemove); | ||
} | ||
|
||
public void addBook(Book newBook) { | ||
this.books.add(newBook); | ||
} | ||
|
||
// Methods to add/remove books, register new patrons, check out and return books | ||
// Add appropriate methods as needed... | ||
} |
25 changes: 25 additions & 0 deletions
25
lesson_09/oop/oop_app/src/main/java/com/codedifferently/lesson9/jamira/Patron.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.codedifferently.lesson9.jamira; | ||
|
||
import java.util.List; | ||
|
||
public class Patron { | ||
private String name; | ||
private List<Book> checkedOutBooks; | ||
|
||
public Patron(String name, List<Book> checkedOutBooks) { | ||
this.name = name; | ||
this.checkedOutBooks = checkedOutBooks; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public List<Book> getCheckedOutBooks() { | ||
return checkedOutBooks; | ||
} | ||
|
||
public void addCheckedOutBook(Book newBook) { | ||
checkedOutBooks.add(newBook); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
lesson_09/oop/oop_app/src/test/java/com/codedifferently/lesson9/jamira/BookTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.codedifferently.lesson9.jamira; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class BookTest { | ||
|
||
@Test | ||
public void testConstructorAndGetters() { | ||
Book book = new Book("Title", "ISBN123", List.of("author"), 200, false); | ||
assertEquals("Title", book.getTitle()); | ||
assertEquals("ISBN123", book.getIsbn()); | ||
assertEquals(List.of("author"), book.getAuthors()); | ||
assertEquals(200, book.getNumPages()); | ||
assertFalse(book.isCheckedOut()); | ||
} | ||
|
||
@Test | ||
public void testSetters() { | ||
Book java = new Book("Title", "ISBN123", List.of("author"), 200, false); | ||
java.setTitle("Title2"); | ||
java.setIsbn("ISBN456"); | ||
java.setAuthors(List.of("authors")); | ||
java.setNumPages(300); | ||
java.setCheckedOut(false); | ||
assertEquals("Title2", java.getTitle()); | ||
assertEquals("ISBN456", java.getIsbn()); | ||
assertEquals(List.of("authors"), java.getAuthors()); | ||
assertEquals(300, java.getNumPages()); | ||
assertFalse(java.isCheckedOut()); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
lesson_09/oop/oop_app/src/test/java/com/codedifferently/lesson9/jamira/LibraryTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.codedifferently.lesson9.jamira; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class LibraryTest { | ||
private Library library; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
List<Book> books = new ArrayList<>(); | ||
books.add(new Book("Book1", "ISBN1", List.of("Author1"), 100, true)); | ||
books.add(new Book("Book2", "ISBN2", List.of("Author2"), 150, true)); | ||
|
||
library = new Library(); | ||
library.setBooks(books); | ||
} | ||
|
||
@Test | ||
public void testAddBook() { | ||
Book newBook = new Book("New Book", "New ISBN", List.of("New Author"), 200, false); | ||
Book book1 = library.getBooks().get(0); | ||
Book book2 = library.getBooks().get(1); | ||
|
||
library.addBook(newBook); | ||
|
||
List<Book> expectedBooks = new ArrayList<>(); | ||
expectedBooks.add(book1); | ||
expectedBooks.add(book2); | ||
expectedBooks.add(newBook); | ||
|
||
assertEquals(expectedBooks.size(), library.getBooks().size()); | ||
assertEquals(expectedBooks, library.getBooks()); | ||
} | ||
|
||
@Test | ||
public void testRemoveBook() { | ||
Book book1 = library.getBooks().get(0); | ||
Book book2 = library.getBooks().get(1); | ||
library.removeBook(book1); | ||
|
||
List<Book> expectedBooks = new ArrayList<>(); | ||
expectedBooks.add(book2); | ||
|
||
assertEquals(expectedBooks.size(), library.getBooks().size()); | ||
assertEquals(expectedBooks, library.getBooks()); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
lesson_09/oop/oop_app/src/test/java/com/codedifferently/lesson9/jamira/PatronTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.codedifferently.lesson9.jamira; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class PatronTest { | ||
public static void main(String[] args) { | ||
// Create some sample data | ||
List<Book> checkedOutBooks = new ArrayList<>(); | ||
checkedOutBooks.add(new Book("Title1", "ISBN1", List.of("Author1"), 100, true)); | ||
checkedOutBooks.add(new Book("Title2", "ISBN2", List.of("Author2"), 150, true)); | ||
|
||
// Create a patron object | ||
Patron patron = new Patron("John Doe", checkedOutBooks); | ||
|
||
// Test the getName() method | ||
System.out.println("Patron's name: " + patron.getName()); | ||
|
||
// Test the getCheckedOutBooks() method | ||
System.out.println("Checked out books:"); | ||
for (Book book : patron.getCheckedOutBooks()) { | ||
System.out.println(book.getTitle() + " - " + book.getIsbn()); | ||
} | ||
|
||
// Test the addCheckedOutBook() method | ||
Book newBook = new Book("New Title", "New ISBN", List.of("New Author"), 200, true); | ||
patron.addCheckedOutBook(newBook); | ||
|
||
// Print the updated list of checked out books | ||
System.out.println("Updated checked out books:"); | ||
for (Book book : patron.getCheckedOutBooks()) { | ||
System.out.println(book.getTitle() + " - " + book.getIsbn()); | ||
} | ||
} | ||
} |