Skip to content

Commit 0f61d3f

Browse files
feat: adds Randy's library management (#262)
* chore: created classes * chore: created getters and setters. * feat: updates to test 1 * Feat: created seperate files for Book,library,Patron. * feat: update Patron file * chore: finished Patrontest * chore: update librarytest * chore: added new content in library file and book file * chore: fixing code and tests Signed-off-by: Anthony D. Mays <[email protected]> * chore: renaming files Signed-off-by: Anthony D. Mays <[email protected]> --------- Signed-off-by: Anthony D. Mays <[email protected]> Co-authored-by: Anthony D. Mays <[email protected]>
1 parent d33d07c commit 0f61d3f

File tree

6 files changed

+169
-0
lines changed

6 files changed

+169
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.codedifferently.lesson9.randycastro;
2+
3+
public class Book {
4+
5+
private String title;
6+
private String isbn;
7+
private String author;
8+
private int page;
9+
private boolean checkedOut;
10+
11+
// constructor for Book
12+
public Book(String title, String isbn, String author, int page, boolean checkedOut) {
13+
this.title = title;
14+
this.isbn = isbn;
15+
this.author = author;
16+
this.page = page;
17+
this.checkedOut = checkedOut;
18+
}
19+
20+
// Getters and Setters
21+
22+
public String getTitle() {
23+
return title;
24+
}
25+
26+
public String getIsbn() {
27+
return isbn;
28+
}
29+
30+
public String getAuthor() {
31+
return author;
32+
}
33+
34+
public int getPage() {
35+
return page;
36+
}
37+
38+
public boolean getCheckedout() {
39+
return checkedOut;
40+
}
41+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.codedifferently.lesson9.randycastro;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class Library {
7+
// Map to store books by ISBN
8+
private Map<String, Book> booksbyISBN;
9+
// Map to store patrons by ID
10+
private Map<String, Patron> patronsID;
11+
12+
{
13+
this.booksbyISBN = new HashMap<>();
14+
this.patronsID = new HashMap<>();
15+
}
16+
17+
// add book
18+
public void addBook(String isbn, Book book) {
19+
booksbyISBN.put(isbn, book);
20+
}
21+
22+
// remove book
23+
public void removeBook(String isbn) {
24+
booksbyISBN.remove(isbn);
25+
}
26+
27+
// Getters and Setters
28+
public Book getBookByISBN(String isbn) {
29+
Book book = booksbyISBN.get(isbn);
30+
if (book != null && !book.getCheckedout()) {
31+
return book;
32+
} else {
33+
return null;
34+
}
35+
}
36+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.codedifferently.lesson9.randycastro;
2+
3+
public class Patron {
4+
5+
private String name;
6+
private String booksCheckedOut;
7+
8+
// constructor
9+
public Patron(String name, String booksCheckedOut) {
10+
this.name = name;
11+
this.booksCheckedOut = booksCheckedOut;
12+
}
13+
14+
// Getters and Setters
15+
public String getName() {
16+
return name;
17+
}
18+
19+
public String getbooksCheckedOut() {
20+
return booksCheckedOut;
21+
}
22+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.codedifferently.lesson9.randycastro;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
public class BookTest {
8+
9+
@Test
10+
// testing Book constructor
11+
// Arrange
12+
public void testBookConstructor() {
13+
String title = "dd";
14+
String isbn = "f32d";
15+
String author = "mas";
16+
int page = 33;
17+
boolean checkedOut = false;
18+
// Act
19+
Book book = new Book(title, isbn, author, page, checkedOut);
20+
// Assert
21+
assertEquals(title, book.getTitle());
22+
assertEquals(isbn, book.getIsbn());
23+
assertEquals(author, book.getAuthor());
24+
assertEquals(page, book.getPage());
25+
assertEquals(checkedOut, book.getCheckedout());
26+
}
27+
28+
@Test
29+
public void testBook() {
30+
String title = "The Software Engineer Guidebook";
31+
String isbn = "12345e";
32+
String author = "Gergely Orosz";
33+
int page = 405;
34+
boolean checkedOut = false;
35+
}
36+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.codedifferently.lesson9.randycastro;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
public class LibraryTest {
6+
@Test
7+
public void testGetBookByISBN() {
8+
Library library = new Library();
9+
10+
Book retrievedBook1 = library.getBookByISBN("12345e");
11+
}
12+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.codedifferently.lesson9.randycastro;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
public class Patrontest {
8+
9+
@Test
10+
// testing patron
11+
// Arange
12+
public void testPatron() {
13+
String name = "Randy";
14+
String booksCheckedOut = "Code Complete";
15+
// Act
16+
17+
Patron patron = new Patron(name, booksCheckedOut);
18+
// Asserts
19+
assertEquals(name, patron.getName());
20+
assertEquals(booksCheckedOut, patron.getbooksCheckedOut());
21+
}
22+
}

0 commit comments

Comments
 (0)