Upload project files

This commit is contained in:
James Musselman 2025-01-16 19:37:13 -06:00
commit 9f8250ae15
Signed by: Musselman
GPG key ID: 1DAEFF35ECB5D6DB
20 changed files with 2936 additions and 0 deletions

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.pawprintstudios</groupId>
<artifactId>LibraryManagementSystem</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>LibraryManagementLibrary</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>

View file

@ -0,0 +1,283 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package librarymanagementsystem;
import java.util.ArrayList;
/**
* Represents a book's identification including title, author, year, publisher,
* publisherDate, edition, isbn, numCopies, numCheckedCopies, currentHolders,
* idNum, and price.
* @author Pawprint Studios
*/
public class Book
{
public String title;
public String author;
public int year;
public String publisher;
public String publisherDate;
public int edition;
public long isbn;
public int numCopies;
public int numCheckedCopies;
private long idNum;
private double price;
private ArrayList<Long> currentHolders;
// Ryan Reminder: We need to add more constructors to this class that
// require less parameters, i.e. one constructor only requires the Title and
// the Author.
/**
* Represents the title of the book.
* @param bookTitle represents the title of the book
*/
public Book(String bookTitle)
{
title = bookTitle;
}
/**
* Represents the book's title, author, year, number of copies, number of
* checked out copies, current holders, and Library Id number.
* @param bookTitle represents the title of the book.
* @param bookAuthor represents the author of the book.
* @param bookYear represents the year the book was published.
* @param bookNumCopies represents the number of copies library holds of
* book.
* @param bookNumCheckedCopies represents the number of checked out copies
* of a book.
* @param bookIdNum represents the book's ID number.
* @param bookCurrentHolders represents the current holders of a book.
*/
public Book(String bookTitle, String bookAuthor, int bookYear,
int bookNumCopies, int bookNumCheckedCopies, long bookIdNum,
ArrayList<Long> bookCurrentHolders)
{
title = bookTitle;
author = bookAuthor;
year = bookYear;
numCopies = bookNumCopies;
numCheckedCopies = bookNumCheckedCopies;
idNum = bookIdNum;
currentHolders = bookCurrentHolders;
}
/**
* Book information containing book's title, author, released year,
* publisher, edition, Isbn, number of copies, number of checked copies,
* who all is has a hold on the book, book's Id number, price.
* @param bookTitle this represents the title of the book
* @param bookAuthor represents the author of the book.
* @param bookYear represents the year the book was published.
* @param bookPublisher represents the publisher of the book.
* @param bookPublisherDate represents date the book was published.
* @param bookEdition represents the edition of the book.
* @param bookIsbn represents the ISBN of the book.
* @param bookNumCopies represents the number of copies of a book within
* library.
* @param bookNumCheckedCopies represents the number of checked out copies
* of a book.
* @param bookIdNum represents the book's ID number.
* @param bookPrice represents the price of the book.
* @param bookCurrentHolders represents the current holders of a book.
*/
public Book(String bookTitle, String bookAuthor, int bookYear,
String bookPublisher, String bookPublisherDate, int bookEdition,
long bookIsbn, int bookNumCopies, int bookNumCheckedCopies,
long bookIdNum, double bookPrice, ArrayList<Long> bookCurrentHolders)
{
title = bookTitle;
author = bookAuthor;
year = bookYear;
publisher = bookPublisher;
publisherDate = bookPublisherDate;
edition = bookEdition;
isbn = bookIsbn;
numCopies = bookNumCopies;
numCheckedCopies = bookNumCheckedCopies;
idNum = bookIdNum;
price = bookPrice;
currentHolders = bookCurrentHolders;
}
// *** Accessors. ***
public String getTitle()
{
return title;
}
public String getAuthor()
{
return author;
}
public int getYear()
{
return year;
}
public String getPublisher()
{
return publisher;
}
public String getPublisherDate()
{
return publisherDate;
}
public int getEdition()
{
return edition;
}
public long getIsbn()
{
return edition;
}
public int getNumCopies()
{
return numCopies;
}
public int getNumCheckedCopies()
{
return numCheckedCopies;
}
public long getIdNum()
{
return idNum;
}
public double getPrice()
{
return price;
}
public String getCurrentHolders()
{
String holders = "";
if (numCheckedCopies > 0)
{
for (int i = 0; i < numCheckedCopies; i++)
{
holders += currentHolders.get(i);
if (i != numCheckedCopies - 1)
{
holders += ",";
}
}
}
else
{
holders += currentHolders.get(0);
}
return holders;
}
// *** Other Methods. ***
public void loanBook(long userIdNum)
{
currentHolders.add(userIdNum);
numCheckedCopies++;
}
public void returnBook(long userIdNum)
{
currentHolders.remove(userIdNum);
numCheckedCopies--;
}
// *** Other Methods. ***
/**
* Compares one book to another.
* @param otherBook represents other book
* @return result
*/
public boolean equalsBook(String otherBook)
{
boolean result = false;
if (otherBook != null)
{
result = title.equalsIgnoreCase(otherBook);
}
return result;
}
/**
* Prints the book and identifications.
* @return books identifications
*/
public String printLoan()
{
return "Title: " + title + "\nAuthor: " + author + "\nYear: " + year
+ "\nPrice: " + price + "\nID Number: " + idNum + "\n";
}
public String printBook()
{
return "Title: " + title + "\nAuthor: " + author + "\nYear: " + year
+ "\nNumber of Copies Available: " + (numCopies - numCheckedCopies)
+ " out of " + numCopies + "\nID Number: " + idNum + "\n";
}
public String printFullBook()
{
return "Title: " + title + "\nAuthor: " + author + "\nYear: " + year
+ "\nPublisher: " + publisher + "\nPublication Date: "
+ publisherDate + "\nEdition: " + edition + "\nISBN: " + isbn
+ "\nNumber of Copies: " + numCopies
+ "\nNumber of Copies Checked: " + numCheckedCopies
+ "\nCurrent Holders: " + currentHolders + "\nID Number: " + idNum
+ "\nPrice: " + price;
}
//It's returning an object for current holder instead of username.
/**
* Prints the string version of book and all it's identifications.
* @return book's identifications.
*/
@Override
public String toString()
{
String formattedIdNum = String.format("%06d", idNum);
String toString = "\n" + title + "," + author + "," + year + ","
+ publisher + "," + publisherDate + "," + edition + "," + isbn
+ "," + numCopies + "," + numCheckedCopies + "," + formattedIdNum
+ "," + price;
if (numCheckedCopies > 0)
{
for(Long userId : currentHolders)
{
toString += "," + userId;
}
}
return toString;
}
}

View file

@ -0,0 +1,339 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package librarymanagementsystem;
import java.util.ArrayList;
/**
* Represents the basic privileges for every user (Patron, Librarian, Admin).
* @author Pawprint Studios
*/
public class GeneralUser
{
public String username;
protected String password;
protected long userId;
protected String userType;
protected ArrayList<Long> currentLoans;
private String patronName;
private String email;
private long phoneNumber;
private int numLoans;
/**
*
*/
public GeneralUser()
{
// Ryan Note: I am not sure if I need to put anything in this default
// constructor.
}
/**
* General information of user, including username, password, userId,
* and user type (Patron, Librarian, Admin).
* @param personUsername represents the user's username.
* @param personPassword represents the user's password.
* @param personUserId represents the user's ID.
* @param personUserType represents the user's type.
*/
public GeneralUser(String personUsername, String personPassword,
long personUserId, String personUserType)
{
username = personUsername;
password = personPassword;
userId = personUserId;
userType = personUserType;
}
public GeneralUser(String personUsername, String personPassword,
long personUserId, String personUserType, String name,
String patronEmail, long patronPhoneNumber)
{
username = personUsername;
password = personPassword;
userId = personUserId;
userType = personUserType;
patronName = name;
email = patronEmail;
phoneNumber = patronPhoneNumber;
}
public GeneralUser(String personUsername, String personPassword,
long personUserId, String personUserType, String name,
String patronEmail, long patronPhoneNumber, int patronNumLoans)
{
username = personUsername;
password = personPassword;
userId = personUserId;
userType = personUserType;
patronName = name;
email = patronEmail;
phoneNumber = patronPhoneNumber;
numLoans = patronNumLoans;
}
public GeneralUser(String personUsername, String personPassword,
long personUserId, String personUserType, String name,
String patronEmail, long patronPhoneNumber, int patronNumLoans,
ArrayList<Long> patronCurrentLoans)
{
username = personUsername;
password = personPassword;
userId = personUserId;
userType = personUserType;
patronName = name;
email = patronEmail;
phoneNumber = patronPhoneNumber;
numLoans = patronNumLoans;
currentLoans = patronCurrentLoans;
}
// *** Accessors. ***
/**
* Gets username.
* @return username
*/
public String getUsername()
{
return this.username;
}
/**
* Gets password.
* @return password
*/
public String getPassword()
{
return this.password;
}
/**
* Gets user ID.
* @return userId
*/
public long getUserId()
{
return this.userId;
}
/**
* Gets the user type.
* @return userType
*/
public String getUserType()
{
return this.userType;
}
public ArrayList<Long> getCurrentLoans()
{
return this.currentLoans;
}
public String getPatronName()
{
return this.patronName;
}
public String getEmail()
{
return this.email;
}
public long getPhoneNumber()
{
return this.phoneNumber;
}
public int getNumLoans()
{
return this.numLoans;
}
// *** Mutators. ***
/**
* Sets username.
* @param nameUser represents the current username.
*/
public void setUsername(String nameUser)
{
this.username = nameUser;
}
/**
* Sets password
* @param wordPass represents if passwords is validated.
*/
public void setPassword(String wordPass)
{
this.password = wordPass;
}
public void setCurrentLoans(ArrayList<Long> patronsCurrentLoans)
{
currentLoans = patronsCurrentLoans;
}
public void setPatronName(String name)
{
patronName = name;
}
public void setEmail(String patronsEmail)
{
email = patronsEmail;
}
public void setPhoneNumber(long patronsPhoneNumber)
{
phoneNumber = patronsPhoneNumber;
}
public void setNumLoans(int patronsNumLoans)
{
numLoans = patronsNumLoans;
}
// *** Book Stuff. ***
public void loanBook(long bookIdNum)
{
currentLoans.add(bookIdNum);
numLoans++;
}
public void returnBook(long bookIdNum)
{
currentLoans.remove(bookIdNum);
numLoans--;
}
// *** Other Methods. ***
/**
* Determines if users match.
* @param obj represents other username.
* @return result
*/
public boolean equals(Object obj)
{
boolean result = false;
if (obj != null && getClass() == obj.getClass())
{
GeneralUser other = (GeneralUser) obj;
result = username.equalsIgnoreCase(other.username)
&& password.equals(other.password)
&& userId == other.userId
&& userType.equals(other.userType);
}
return result;
}
public String printUser()
{
String formattedIdNum = String.format("%06d", userId);
String printUser = "Username: " + username + "\nID Number: "
+ formattedIdNum + "\nUser Type: " + userType
+ "\nFirst and Last Name: " + patronName;
if (numLoans > 0)
{
printUser += "/n" + numLoans + " Current Loans: ";
for(Long bookId : currentLoans)
{
printUser += "," + bookId;
}
}
return printUser;
}
public String printFullUser()
{
String formattedIdNum = String.format("%06d", userId);
String printUser = "Username: " + username + "\nPassword: " + password
+ "\nID Number: " + formattedIdNum + "\nUser Type: " + userType
+ "\nFirst and Last Name: " + patronName + "\nEmail Address: "
+ email + "\nPhone Number: " + phoneNumber + "\nNumber of Loans: "
+ numLoans;
if (numLoans > 0)
{
printUser += "/nCurrent Loans: ";
for(Long bookId : currentLoans)
{
printUser += "," + bookId;
}
}
return printUser;
}
// Ryan Note: Update this later at some point
/**
* Prints the user's name and password.
* @return username and password
*/
@Override
public String toString()
{
String formattedIdNum = String.format("%06d", userId);
String toString = "\n" + username + "," + password + "," + formattedIdNum
+ "," + userType + "," + patronName + "," + email + ","
+ phoneNumber + "," + numLoans;
if (numLoans > 0)
{
for(Long bookId : currentLoans)
{
toString += "," + bookId;
}
}
return toString;
}
}

View file

@ -0,0 +1,557 @@
package librarymanagementsystem;
import java.io.*;
import java.util.*;
/**
* Represents the library of a Library Management System.
*
* @author Pawprint Studios
*/
public class Library
{
public String libraryName;
public String libraryAddress;
public static double dailyLateFine = 0.25;
public int maxLoans = 30;
public ArrayList<Book> libraryBooks = new ArrayList<>();
protected ArrayList<GeneralUser> libraryUsers = new ArrayList<>();
protected long highestUserID;
protected long highestBookID;
private String bookLocation;
private String userLocation;
/**
* Represents the databases of books and users.
*/
public Library()
{
this("../resources/Books.csv", "../resources/Users.csv");
}
/**
* Represents where the databases are held.
*
* @param bookLocation represents the location of where the book database
* is being held.
* @param userLocation represents the location of where the book database
* is being held.
*/
public Library(String bookLocation, String userLocation)
{
this.bookLocation = bookLocation;
this.userLocation = userLocation;
updateBooksArray();
updateUsersArray();
highestUserID = libraryUsers.size() + 1;
highestBookID = libraryBooks.size() + 1;
}
// *** Accessors. ***
/**
* Get the library name.
*
* @return libraryname
*/
public String getLibraryName()
{
return libraryName;
}
/**
* Get the library address.
*
* @return libraryAddress
*/
public String getLibraryAddress()
{
return libraryAddress;
}
/**
* Get the daily late fine.
*
* @return dailyLateFine
*/
public double getDailyLateFine()
{
return dailyLateFine;
}
/**
* Get the Highest User ID.
*
* @return highestUserID
*/
public long getHighestUserID()
{
return highestUserID;
}
public long getHighestBookID()
{
return highestBookID;
}
/**
* Get all the library books within the library.
*
* @return printList
*/
public String getLibraryBooks()
{
String printList = "";
for (Book printBook : libraryBooks) {
printList += printBook;
}
return printList;
}
/**
* Get all the users within the Library.
*
* @return printList
*/
public String getLibraryUsers()
{
String printList = "";
for (GeneralUser printUser : libraryUsers) {
printList += printUser;
}
return printList;
}
// *** Mutators. ***
/**
* Set name of the Library management system.
*
* @param name represents the name of the library.
*/
protected void setLibraryName(String name)
{
libraryName = name;
}
/**
* Set the address for the Library.
*
* @param address represents the address of the library.
*/
protected void setLibraryAddress(String address)
{
libraryAddress = address;
}
/**
* Set how much a user will get fined for each day a book isn't returned.
*
* @param dailyFine represents the daily late fine for a user.
*/
protected void setDailyLateFine(Double dailyFine)
{
dailyLateFine = dailyFine;
}
/**
* Update the database for the book and adds books.
*/
public void updateBooksArray()
{
libraryBooks.clear();
try (Scanner bookScan = new Scanner(new File(bookLocation)))
{
bookScan.nextLine();
while (bookScan.hasNextLine())
{
String[] bookParts = bookScan.nextLine().trim().split(",");
String title = bookParts[0];
String author = bookParts[1];
int year = Integer.parseInt(bookParts[2]);
String publisher = bookParts[3];
String publisherDate = bookParts[4];
int edition = Integer.parseInt(bookParts[5]);
long isbn = Long.parseLong(bookParts[6]);
int numCopies = Integer.parseInt(bookParts[7]);
int numCheckedCopies = Integer.parseInt(bookParts[8]);
long idNum = Long.parseLong(bookParts[9]);
double price = Double.parseDouble(bookParts[10]);
ArrayList<Long> currentHolders = new ArrayList<>(numCopies);
for (int i = 11; i < 10 + numCheckedCopies; i++)
{
currentHolders.add(Long.parseLong(bookParts[i]));
}
libraryBooks.add(new Book(title, author, year, publisher,
publisherDate, edition, isbn, numCopies, numCheckedCopies,
idNum, price, currentHolders));
}
}
catch (FileNotFoundException e)
{
System.out.println("Could not find file: " + bookLocation);
System.exit(1);
}
}
/**
* Update the user database and adds users.
*/
public void updateUsersArray()
{
libraryUsers.clear();
try (Scanner fileScan = new Scanner(new File(userLocation)))
{
fileScan.nextLine();
while (fileScan.hasNextLine())
{
String[] userParts = fileScan.nextLine().trim().split(",");
String username = userParts[0];
String password = userParts[1];
long userId = Long.parseLong(userParts[2]);
String userType = userParts[3];
String name = userParts[4];
String email = userParts[5];
long phoneNumber = Long.parseLong(userParts[6]);
if (userType.equals("Patron"))
{
int numLoans = Integer.parseInt(userParts[7]);
ArrayList<Long> currentLoans = new ArrayList(maxLoans);
for (int i = 8; i <= 7 + numLoans; i++) {
currentLoans.add(Long.parseLong(userParts[i]));
}
libraryUsers.add(new GeneralUser(username, password, userId,
userType, name, email, phoneNumber, numLoans,
currentLoans ));
}
else
{
libraryUsers.add(new GeneralUser(username, password, userId,
userType, name, email, phoneNumber));
}
}
}
catch (FileNotFoundException e)
{
System.out.println("Could not find file: " + userLocation);
System.exit(2);
// Ryan Note: I still don't know what to put in the catch blocks.
}
}
public void updateBooksFile(String location)
{
try (PrintWriter outFile = new PrintWriter(
new BufferedWriter(new FileWriter(location))))
{
outFile.print("Title,Author,Year,Publisher,PublishDate,ISBN,"
+ "NumCopies,NumChecked,IdNum,Price,CurrentHolders");
for (Book libBook : libraryBooks)
{
outFile.print(libBook.toString());
}
}
catch (IOException e)
{
System.out.println(e);
}
}
public void updateUsersFile(String location)
{
try (PrintWriter outFile = new PrintWriter(
new BufferedWriter(new FileWriter(location))))
{
outFile.print("Username,Password,UserID,UserType,Name,Email,"
+ "PhoneNumber,NumLoans,CurrentLoans");
for (GeneralUser libUser : libraryUsers)
{
outFile.print(libUser.toString());
}
}
catch (IOException e)
{
System.out.println(e);
}
}
// *** Abilities that all users can access. ***
/**
* Verify the login of a user.
*
* @param username represents the username of a user.
* @param password represents the password of a user.
* @return loginUser
*/
public GeneralUser verifyLogin(String username, String password)
{
GeneralUser loginUser = null;
for (GeneralUser arrayUser : libraryUsers)
{
if (username.equalsIgnoreCase(arrayUser.getUsername())
&& password.equals(arrayUser.getPassword()))
{
loginUser = arrayUser;
}
}
return loginUser;
}
/**
* Allow guest to apply for Membership of a Patron
*
* @param username represents the username given by user.
* @param password represents the password given by user.
* @return successfulAplication represents if user was created
*/
public boolean applyMembership(String username, String password,
String name, String email, long phoneNumber)
{
boolean successfulAplication = false;
if (findUser(username) == null)
{
libraryUsers.add(new GeneralUser(username, password, highestUserID,
"Patron", name, email, phoneNumber, 0,
new ArrayList<>(maxLoans)));
updateUsersFile(userLocation);
highestUserID++;
successfulAplication = true;
}
else
{
System.out.println("A user with that username already exists!");
}
return successfulAplication;
}
/**
* Search the library for a book/media.
*
* @param bookSearch represents the name of the book being searched.
*/
public ArrayList<Book> searchLibrary(String bookSearch)
{
ArrayList<Book> foundBooks = new ArrayList<>();
String searchBook = bookSearch.toLowerCase();
for (Book arrayBook : libraryBooks)
{
if (arrayBook.getTitle().toLowerCase().contains(searchBook)
|| arrayBook.getAuthor().toLowerCase().contains(searchBook))
{
foundBooks.add(arrayBook);
}
}
return foundBooks;
}
// *** Abilities that Patrons can access. ***
public Book findBook(long libIdNum)
{
for (Book arrayBook : libraryBooks)
{
if (arrayBook.getIdNum() == libIdNum)
{
return arrayBook;
}
}
return null;
}
public Book findBook(String bookTitle)
{
for (Book arrayBook : libraryBooks)
{
if (arrayBook.getTitle().contains(bookTitle))
{
return arrayBook;
}
}
return null;
}
public String borrowBook(long userIdNum, Book bookSearch)
{
String successfulBorrow = "";
GeneralUser user = findUser(userIdNum);
long bookIdNum = bookSearch.getIdNum();
if (!user.currentLoans.contains(bookIdNum))
{
if (user.getNumLoans() < maxLoans)
{
user.loanBook(bookIdNum);
bookSearch.loanBook(userIdNum);
updateBooksFile(bookLocation);
updateUsersFile(userLocation);
successfulBorrow = "Borrowed";
}
else
{
successfulBorrow = "You already have " + maxLoans + " books.";
}
}
else
{
successfulBorrow = "You already have " + bookSearch.getTitle()
+ " checked out.";
}
return successfulBorrow;
}
public ArrayList<Book> viewLoans(long userIdNum)
{
ArrayList<Book> loanedBooks = new ArrayList<>();
for (long lo : findUser(userIdNum).getCurrentLoans())
{
loanedBooks.add(findBook(lo));
}
return loanedBooks;
}
public String returnBook(long userIdNum, long bookIdNum)
{
String successfulReturn = "";
GeneralUser user = findUser(userIdNum);
if (user.currentLoans.contains(bookIdNum))
{
user.returnBook(bookIdNum);
findBook(bookIdNum).returnBook(userIdNum);
updateBooksFile(bookLocation);
updateUsersFile(userLocation);
successfulReturn = "Returned";
}
else
{
successfulReturn = "You don't have a copy of " + findBook(bookIdNum)
.getTitle() + " to return.";
}
return successfulReturn;
}
// *** Abilities that Librarians can access. ***
/**
* Add book into array list.
*
* @param addingBook represents the book being added to the array list.
*/
public void addBook(Book addingBook)
{
libraryBooks.add(addingBook);
updateBooksFile(bookLocation);
highestBookID++;
}
/**
* Retire/remove book from array list.
*
* @param retireIdNum represents the ID number of the book being retired.
*/
public void retireBook(long retireIdNum)
{
libraryBooks.remove(findBook(retireIdNum));
updateBooksFile(bookLocation);
}
/**
* Find user from user array list.
*
* @param userSearch represents what the user searched.
* @return
*/
public GeneralUser findUser(String userSearch)
{
for (GeneralUser arrayUser : libraryUsers)
{
if (userSearch.equalsIgnoreCase(arrayUser.getUsername()))
{
return arrayUser;
}
}
return null;
}
/**
* Find user from user array list.
*
* @param userIdSearch represents what the user searched.
* @return GeneralUser
*/
public GeneralUser findUser(long userIdSearch)
{
for (GeneralUser arrayUser : libraryUsers)
{
if (userIdSearch == arrayUser.getUserId())
{
return arrayUser;
}
}
return null;
}
// *** Abilities that Admins can access. ***
/**
* Remove users.
*
* @param User
*/
public void removeUser(long userId)
{
libraryUsers.remove(findUser(userId));
updateUsersFile(userLocation);
}
/**
* Backup database.
* @param backupLocation
*/
public void backupDatabase()
{
updateBooksFile("../backups/Books.csv");
updateUsersFile("../backups/Users.csv");
}
}

View file

@ -0,0 +1,152 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit4TestClass.java to edit this template
*/
package librarymanagementsystem;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.ArrayList;
/**
* Represents testing for the Book class.
* @author Pawprint Studios
*/
public class BookTest
{
private Book testBook;
public BookTest()
{
ArrayList<Long> holders = new ArrayList<Long>(1);
testBook = new Book("Title","Author",2021,"Publisher","April 1st",
1,22222,1,1,121212,2.1,holders);
}
@BeforeClass
public static void setUpClass()
{
}
/**
* Test of getTitle method, of class Book.
*/
@Test
public void testGetTitle()
{
String testTitle = "Title";
assertEquals(testTitle, testBook.getTitle());
}
/**
* Test of getAuthor method, of class Book.
*/
@Test
public void testGetAuthor()
{
String testAuthor = "Author";
assertEquals(testAuthor, testBook.getAuthor());
}
/**
* Test of getYear method, of class Book.
*/
@Test
public void testGetYear()
{
int testYear = 2021;
assertEquals(testYear, testBook.getYear());
}
/**
* Test of getPublisher method, of class Book.
*/
@Test
public void testGetPublisher()
{
String testPublisher = "Publisher";
assertEquals(testPublisher, testBook.getPublisher());
}
/**
* Test of getPublisherDate method, of class Book.
*/
@Test
public void testGetPublisherDate()
{
String testPublisherDate = "April 1st";
assertEquals(testPublisherDate, testBook.getPublisherDate());
}
/**
* Test of getEdition method, of class Book.
*/
@Test
public void testGetEdition()
{
int testEdition = 1;
assertEquals(testEdition, testBook.getEdition());
}
/**
* Test of getIsbn method, of class Book.
*/
@Test
public void testGetIsbn()
{
long testIsbn = 1;
assertEquals(testIsbn, testBook.getIsbn());
}
/**
* Test of getNumCopies method, of class Book.
*/
@Test
public void testGetNumCopies()
{
int testNumCopies = 1;
assertEquals(testNumCopies, testBook.getNumCopies());
}
/**
* Test of getNumCheckedCopies method, of class Book.
*/
@Test
public void testGetNumCheckedCopies()
{
int testNumCheckedCopies = 1;
assertEquals(testNumCheckedCopies, testBook.getNumCheckedCopies());
}
/**
* Test of getIdNum method, of class Book.
*/
@Test
public void testGetIdNum()
{
long testIdNum = 121212;
assertEquals(testIdNum, testBook.getIdNum());
}
/**
* Test of getPrice method, of class Book.
*/
@Test
public void testGetPrice()
{
double testPrice = 2.1;
assertEquals(testPrice, testBook.getPrice(),2.1);
}
}

View file

@ -0,0 +1,187 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit4TestClass.java to edit this template
*/
package librarymanagementsystem;
import java.util.ArrayList;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Represents testing for the GeneralUser class.
* @author Pawprint Studios
*/
public class GeneralUserTest
{
private GeneralUser testGeneralUser;
public GeneralUserTest()
{
testGeneralUser = new GeneralUser("pat", "pat",
000007, "Patron", "John Johnson", "JohnJohn@John.com",
5558976, 0);
}
@BeforeClass
public static void setUpClass()
{
}
/**
* Test of getUsername method, of class GeneralUser.
*/
@Test
public void testGetUsername()
{
String testUsername = "pat";
assertEquals(testUsername, testGeneralUser.getUsername());
}
/**
* Test of getPassword method, of class GeneralUser.
*/
@Test
public void testGetPassword()
{
String testPassword = "pat";
assertEquals(testPassword, testGeneralUser.getPassword());
}
/**
* Test of getUserId method, of class GeneralUser.
*/
@Test
public void testGetUserId()
{
long testUserId = 000007;
assertEquals(testUserId, testGeneralUser.getUserId());
}
/**
* Test of getUserType method, of class GeneralUser.
*/
@Test
public void testGetUserType()
{
String testUserType = "Patron";
assertEquals(testUserType, testGeneralUser.getUserType());
}
/**
* Test of getPatronName method, of class GeneralUser.
*/
@Test
public void testGetPatronName()
{
String testPatronName = "John Johnson";
assertEquals(testPatronName, testGeneralUser.getPatronName());
}
/**
* Test of getEmail method, of class GeneralUser.
*/
@Test
public void testGetEmail()
{
String testEmail = "JohnJohn@John.com";
assertEquals(testEmail, testGeneralUser.getEmail());
}
/**
* Test of getPhoneNumber method, of class GeneralUser.
*/
@Test
public void testGetPhoneNumber()
{
long testPhoneNumber = 5558976;
assertEquals(testPhoneNumber, testGeneralUser.getPhoneNumber());
}
/**
* Test of setUsername method, of class GeneralUser.
*/
@Test
public void testSetUsername()
{
String testUsername = "Lebron";
testGeneralUser.setUsername("Lebron");
assertEquals(testUsername, testGeneralUser.getUsername());
}
/**
* Test of setPassword method, of class GeneralUser.
*/
@Test
public void testSetPassword()
{
String testPassword = "James";
testGeneralUser.setPassword("James");
assertEquals(testPassword, testGeneralUser.getPassword());
}
/**
* Test of setPatronName method, of class GeneralUser.
*/
@Test
public void testSetPatronName()
{
String testPatronName = "Harry Potter";
testGeneralUser.setPatronName("Harry Potter");
assertEquals(testPatronName, testGeneralUser.getPatronName());
}
/**
* Test of setEmail method, of class GeneralUser.
*/
@Test
public void testSetEmail()
{
String testEmail = "dogcat@email.net";
testGeneralUser.setEmail("dogcat@email.net");
assertEquals(testEmail, testGeneralUser.getEmail());
}
/**
* Test of setPhoneNumber method, of class GeneralUser.
*/
@Test
public void testSetPhoneNumber()
{
long testPhoneNumber = 888333;
testGeneralUser.setPhoneNumber(888333);
assertEquals(testPhoneNumber, testGeneralUser.getPhoneNumber());
}
/**
* Test of setNumLoans method, of class GeneralUser.
*/
@Test
public void testSetNumLoans()
{
int testNumLoans = 3;
testGeneralUser.setNumLoans(3);
assertEquals(testNumLoans, testGeneralUser.getNumLoans());
}
}

View file

@ -0,0 +1,88 @@
package librarymanagementsystem;
import java.io.*;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author Pawprint Studios
*/
public class LibraryTest
{
private Library testLibrary;
public LibraryTest()
{
/*
PrintWriter bookWriter = new PrintWriter(new BufferedWriter(new FileWriter("testBooks.csv")));
bookWriter.println("Title,Author,Year,Publisher,PublishDate,ISBN,NumCopies,NumChecked,IdNum,Price,CurrentHolders");
bookWriter.println("Ahsoka,E. K. Johnston,2016,DisneyLucasfilm Press,October 11,1,1484705661,3,2,243578,15.99,10000,76543");
bookWriter.println("Dark Disciple,Christie Golden,2015,Del Rey,July 7,1,9780345511539,2,0,849332,9.99, ");
bookWriter.println("Star Wars: Episode III Revenge of the Sith,Matthew Stover,2005,Del Rey,April 7,2005,0345428838,3,0,65365,12.99, ");
testLibrary = new Library("testBooks.csv", "testUsers.csv");
*/
testLibrary = new Library();
}
@Test
public void testSetLibraryName()
{
String testLibraryName = "DingleFloopyNoop";
testLibrary.setLibraryName("DingleFloopyNoop");
assertEquals(testLibraryName, testLibrary.getLibraryName());
}
@Test
public void testSetLibraryAddress()
{
String testLibraryAddress = "2000 C Wourt Road";
testLibrary.setLibraryAddress("2000 C Wourt Road");
assertEquals(testLibraryAddress, testLibrary.getLibraryAddress());
}
@Test
public void testSetDailyLateFine()
{
double testDailyLateFine = 4.2;
testLibrary.setDailyLateFine(4.2);
assertEquals(testDailyLateFine, testLibrary.getDailyLateFine(), 0);
}
// Library verifyLibrary = new Library("Books.csv", "Users.csv");
@Test
public void testVerifyLogin()
{
GeneralUser testUser = new GeneralUser("RyanTheGreyJedi",
"HanShotFirst", 2, "Librarian");
GeneralUser verifyUser = testLibrary.verifyLogin("RyanTheGreyJedi",
"HanShotFirst");
assertEquals(testUser, verifyUser);
}
@Test
public void testSearchLibrary()
{
/*
Book testBook = new Book("________________________");
Book searchBook = testLibrary.searchLibrary("________________________");
assertEquals(testBook, searchBook);
*/
}
}

View file

@ -0,0 +1,31 @@
package librarymanagementsystemt;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.*;
/**
*
* @author qrow
*/
public class AdminTest {
public AdminTest()
{
String logName = "log";
}
@Before
public void setUp()
{
}
@Test
public void testViewLogs()
{
}
}