diff --git a/README.md b/README.md index 21a6a336..b1355152 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,10 @@ Every good university/college has a well-stocked library for the students. The students get access to a wide variety of literature on topics/subjects that are crucial for their personal as well as professional development. But as the number of students using the library increases, the task of keeping records get very difficult. In this assignment, we - are going to simulate that task by writing a piece of software. + are going to simulate that task by writing a piece of software. + In this software we'll create some definition classes and execution classes. + We'll create as many objects as we can to improve the functioning of our Library. + We'll then call these objects in the execution classes to make a better library. @@ -65,4 +68,5 @@ Since this is the first assignment, feel free to add as many methods as you can, of a field, and a method; the name of a field should be a noun, and the name of a method should be a verb! It is completely alright if you cannot implement the actual code for the methods, you can simple write a print -statement to represent that the methods are working, just like in the `Video Rental Inventory System` project. \ No newline at end of file +statement to represent that the methods are working, just like in the `Video Rental Inventory System` project. +* Author - Naman Agarwal diff --git a/src/definitions/Book.java b/src/definitions/Book.java index a0f1b417..124ff088 100644 --- a/src/definitions/Book.java +++ b/src/definitions/Book.java @@ -1,10 +1,76 @@ /* Created by IntelliJ IDEA. - * User: Divyansh Bhardwaj (dbc2201) + * User: Md. Faraaz Siddiqui (faraaz0) * Date: 21/08/20 * Time: 3:49 PM * File Name : Book.java * */ package definitions; +import java.util.Objects; + public class Book { + private String bookName; + private String authorName; + private String bookISBNNumber; + + public Book(String bookName, String authorName, String bookISBNNumber) { + this.bookName = bookName; + this.authorName = authorName; + this.bookISBNNumber = bookISBNNumber; + } + + public String getBookName() { + + return bookName; + } + + public void setBookName(String bookName) { + + this.bookName = bookName; + } + + public String getAuthorName() { + + return authorName; + } + + public void setAuthorName(String authorName) { + + this.authorName = authorName; + } + + public String getIsbnNumber() { + + return bookISBNNumber; + } + + public void setIsbnNumber(String bookISBNNumber) { + + this.bookISBNNumber = bookISBNNumber; + } + + @Override + public String toString() { + return String.format( + "Book Name: %s, Author Name: %s, ISBN Number: %s", + getBookName(), getAuthorName(), getIsbnNumber() + ); + } + + @Override + public boolean equals (Object o){ + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Book book = (Book) o; + return Objects.equals(getBookName(), book.getBookName()) && + Objects.equals(getAuthorName(), book.getAuthorName()) && + Objects.equals(getIsbnNumber(), book.getIsbnNumber()); + } + + @Override + public int hashCode () { + return Objects.hash(getBookName(), getAuthorName(), getIsbnNumber()); + } + + } diff --git a/src/definitions/Library.java b/src/definitions/Library.java index 0c55b5a1..c8d10e7e 100644 --- a/src/definitions/Library.java +++ b/src/definitions/Library.java @@ -1,10 +1,51 @@ /* Created by IntelliJ IDEA. - * User: Divyansh Bhardwaj (dbc2201) + * User: Md. Faraaz Siddiqui (faraaz0) * Date: 21/08/20 * Time: 3:50 PM * File Name : Library.java * */ package definitions; +import java.util.Arrays; + public class Library { + private Book[] books; + + public Library() { + + this.books = new Book[1000]; + } + + public Book[] getBooks() { + + return books; + } + + public void setBooks(Book[] books) { + + this.books = books; + } + + + @Override + public String toString() { + return String.format( + "Books List: %s", getBooks()); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Library library = (Library) o; + return Arrays.equals(getBooks(), library.getBooks()); + } + + @Override + public int hashCode() { + + return Arrays.hashCode(getBooks()); + } + + } diff --git a/src/definitions/Student.java b/src/definitions/Student.java index 4be682cb..632212c7 100644 --- a/src/definitions/Student.java +++ b/src/definitions/Student.java @@ -6,5 +6,99 @@ * */ package definitions; +import java.util.Arrays; +import java.util.Objects; + + public class Student { + private String[] nameOfTheStudent; + private long universityRollNumber; + private int numberOfBooksIssued; + private Book[] books; + + public Student(String nameOfTheStudent, long universityRollNumber, int numberOfBooksIssued) { + this.nameOfTheStudent = nameOfTheStudent.split(" "); + this.universityRollNumber = universityRollNumber; + this.numberOfBooksIssued = numberOfBooksIssued; + this.books = new Book[numberOfBooksIssued]; + } + + public String[] getNameOfTheStudent() { + + return nameOfTheStudent; + } + + public void setNameOfTheStudent(String[] nameOfTheStudent) { + + this.nameOfTheStudent = nameOfTheStudent; + } + + public long getUniversityRollNumber() { + + return universityRollNumber; + } + + public void setUniversityRollNumber(long universityRollNumber) { + + this.universityRollNumber = universityRollNumber; + } + + public int getNumberOfBooksIssued() { + + return numberOfBooksIssued; + } + + public void setNumberOfBooksIssued(int numberOfBooksIssued) { + + this.numberOfBooksIssued = numberOfBooksIssued; + } + + public Book[] getBooks() { + return books; + } + + public void setBooks(Book[] books) { + this.books = books; + } + + public void addNewBook(String bookName) { + System.out.println(bookName + " has been successfully issued."); + } + + public void myIssuedBooks() { + for (Book books : books) { + System.out.println(books); + } + } + + public void returnAnIssuedBook(String bookName) { + System.out.println(bookName + " has been successfully returned."); + } + + @Override + public String toString() { + return String.format( + "Student Name: %s, University Roll Number: %l, Number Of Books Issued: %d, Name Of Books Issued By The Student: %d", + getNameOfTheStudent(), getUniversityRollNumber(), getNumberOfBooksIssued(), getBooks() + ); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Student student = (Student) o; + return getUniversityRollNumber() == student.getUniversityRollNumber() && + getNumberOfBooksIssued() == student.getNumberOfBooksIssued() && + Arrays.equals(getNameOfTheStudent(), student.getNameOfTheStudent()) && + Arrays.equals(getBooks(), student.getBooks()); + } + + @Override + public int hashCode() { + int result = Objects.hash(getUniversityRollNumber(), getNumberOfBooksIssued()); + result = 31 * result + Arrays.hashCode(getNameOfTheStudent()); + result = 31 * result + Arrays.hashCode(getBooks()); + return result; + } } diff --git a/src/execution/FrontDesk.java b/src/execution/FrontDesk.java index e0ebd741..7c13bde4 100644 --- a/src/execution/FrontDesk.java +++ b/src/execution/FrontDesk.java @@ -6,8 +6,62 @@ * */ package execution; +import definitions.Student; + +import java.util.Scanner; + public class FrontDesk { + private static final int ADD_NEW_BOOK = 1; + private static final int RETURN_BOOK = 2; + private static final int MY_ISSUED_BOOKS = 3; + private static final int EXIT = 4; + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int userInput; + Student student = new Student("Md Faraaz Siddiqui", 191500454, 3); + do { + System.out.println("-=-=--=-=-Welcome To The Front Desk-=-=--=-=-"); + System.out.println("How may I help you today?"); + System.out.println("1. Issue a new book for me: "); + System.out.println("2. Return a previously issued book for me: "); + System.out.println("3. Show me all my issued books: "); + System.out.println("4. Exit."); + System.out.println("Enter your choice (1..4): "); + userInput = scanner.nextInt(); + switch (userInput) { + case ADD_NEW_BOOK: + System.out.println("Enter the name of the book you want to read: "); + scanner.nextLine(); + String bookName = scanner.nextLine(); + student.addNewBook(bookName); + break; + + case RETURN_BOOK: + System.out.println("Enter the name of the book you want to return: "); + scanner.nextLine(); + bookName = scanner.nextLine(); + student.returnAnIssuedBook(bookName); + break; + + case MY_ISSUED_BOOKS: + student.myIssuedBooks(); + break; + default: + System.out.println("WRONG CHOICE!"); + } + } + + while (userInput != EXIT); + { + scanner.close(); + } + } } + + + + +