Object-Oriented Programming (Ccs0023) : College of Computer Studies
Object-Oriented Programming (Ccs0023) : College of Computer Studies
Final Project
Grade
Submitted by:
Submitted to:
OBJECTIVES
HELLO WORLD LIBRARY MANAGEMENT SYSTEM aims to manage the system of the
library in terms of adding, renting, etc. (see main menu for further details) This system also aims
to provide easy access materials and usage for the users. Through this system, the process will be
much easier.
1. ADD NEW/REGISTER STUDENT – this menu creates a new file where data is to be
stored.
2. BORROW BOOK – this menu let the user remove or rent an existing file.
3. RETURN BOOK – this menu will help the user to bring back the file that have been removed
or borrowed.
4. SHOW BOOK/SHOW STUDENTB – this menu will make the user enter of what existing
file should be shown.
5. SHOW ALL BOOK – this menu shows all the existing files that are stored with a correct
structure.
6. EXIT – this option will exit the application.
The user who’ll add new book must only indicate the title of the book and the author because
the book code is already automated.
Displaying all the books that have been added. It is all sorted in the file.
Figure
3.1 SHOWING BOOK
The user will enter one book code number to display the existing file and to know if it is available
or not.
Figure 3.1.1
The user who’ll register should only enter the name because the student code is automated
just like the book code.
The user will enter the student code to see the name and to know if she already borrowed a book
or not.
3.3.1
–
The user must indicate and enter the student code and book code to be able to borrow it.
–
Figure 4.1.2
Figure 4.2.1
This section displays all the book stored files. Book code number 3, on the other hand, is
already unavailable because it was rented by the student.
Figure 4.2.2
If the user entered the book code number 3 which is already rented, it will also show that the book
is not available.
If the user entered the student code who rented, it will show what book the student rented.
The user must indicate and enter the student code to be able to return the rented book.
–
Figure 5.1.1
This section displays all the stored files. The rented book code number 3 is available again
because the user returned it.
Figure 5.1.2
If the user entered the rented book code number 3 which is already returned, it will also
show that the book is available again.
If the user entered the student code who rented which the book has already returned, it will
show that the student has no borrowed book.
Main.java
package pack;
import java.io.FileWriter;
menu.render(libraryBookHandler);
if(!super.list.contains(book))
super.list.add(book);
}
import java.io.IOException;
BorrowBookCollection.java
package pack.Model;
import java.io.IOException;
@Override
public void add(BorrowBook borrowBook) throws IOException {
if(borrowBook == null) throw new
NullPointerException();
if(borrowBook.getStudent().getCode() == -1)
throw new IOException("Uninitialize student code");
if(!super.list.contains(borrowBook))
super.list.add(borrowBook);
}
@Override
protected BorrowBook getValue(int code){
return super.list.stream()
.filter(borrowBook -> borrowBook.getStudent().getCode() == code)
.findAny()
.orElse(null);
}
}
CodeGenerator.java
package pack.Model;
Collection.java
package pack.Model;
import java.io.IOException;
import java.util.ArrayList;
@Override
public T next() {
return collection.list.get(counter++);
}
}
}
Iterator.java
package pack.Model;
LibraryBookHandler.java
package pack.Model;
import java.io.IOException;
this.bookCollection = bookCollection;
this.studentCollection = studentCollection;
this.borrowCollection = borrowCollection;
}
@Override
public int borrowBook(int book_code, int stud_code) throws IOException {
var student = studentCollection.get(stud_code);
if(student == null)
return 1;
if(!book.isAvailable())
return 4;
book.setAvailability(false);
@Override
public int returnBorrowBook(int stud_code) {
var borrowBook = borrowCollection.get(stud_code);
if(borrowBook == null)
return 1;
@Override
public Book showBook(int code) {
return bookCollection.get(code);
}
@Override
public void registerStudent(Student student) throws IOException {
try {
studentCollection.add(student); }catch
(NullPointerException | IOException e){ throw
e;
}
}
@Override
public BorrowBook showStudentBorrowBook(int code) {
return borrowCollection.get(code);
}
}
Student.java
package pack.Model;
@Override
protected void doSetCode(int code) {
this.code = code;
}
}
StudentCollection.java
package pack.Model;
import java.io.IOException;
@Override
public void add(Student student) throws IOException {
if(student == null) throw new
NullPointerException(); if(student.getCode() == -1)
throw new IOException("Uninitialize student code");
if(!super.list.contains(student))
super.list.add(student);
}
Package Tools
BookReaderStream.java
package pack.Tools;
import pack.Model.*;
import java.io.BufferedReader;
import java.io.IOException;
Book.setInstanceCounter(bookCollection.size());
}
@Override
public void read(BookCollection bookCollection) {
_read(bookCollection);
}}
BookWriterStream.java
package pack.Tools;
import pack.Model.BookCollection;
import java.io.FileWriter;
import java.io.IOException;
System.out.print("BookWriterStream._write");
while (it.hasNext()){
@Override
public boolean write(BookCollection value) throws IOException {
return _write(value);
}
}
BorrowBookReaderStream.java
package pack.Tools;
import pack.Model.*;
import java.io.BufferedReader;
import java.io.IOException;
borrowBook.add(borrow);
}
System.out.println(":Success");
}catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void read(BorrowBookCollection value) {
_read(value);
}
BorrowBookWriterStream.java
package pack.Tools;
import pack.Model.BorrowBookCollection;
import java.io.FileWriter;
import java.io.IOException;
System.out.print("BorrowBookWriterStream._write");
while (it.hasNext()){
var borrowBook = it.next();
writer.write(borrowBook.getStudent().getCode() + "," +
borrowBook.getBook().getCode()+"\n");
}
System.out.println(":Success");
writer.close();
return true;
}
@Override
public boolean write(BorrowBookCollection value) throws IOException {
return _write(value);
}
}
CloseableFileReader.java
package pack.Tools;
import java.io.*;
import java.nio.charset.Charset;
@Override
public void close() throws IOException {
try{
super.close(); }
catch (IOException e){
throw e;
}
}
}
LibraryFileHandler.java
package pack.Tools;
import java.io.IOException;
studentReaderStream.read(studentCollection);
bookReaderStream.read(bookCollection);
borrowBookReaderStream.read(borrowCollection);
}
public void write(StudentWriterStream studentWriterStream,
BookWriterStream bookWriterStream,
BorrowBookWriterStream borrowBookWriterStream) throws IOException {
studentWriterStream.write(studentCollection);
bookWriterStream.write(bookCollection);
borrowBookWriterStream.write(borrowCollection);
}
}
ReaderStream.java
package pack.Tools;
import java.io.FileWriter;
StudentReaderStream.java
package pack.Tools;
import java.io.BufferedReader;
import java.io.IOException;
@Override
public void read(StudentCollection studentCollection) {
_read(studentCollection);
}
Student.setInstanceCounter(studentCollection.size());
}
StudentWriterStream.java
package pack.Tools;
import pack.Model.StudentCollection;
import java.io.FileWriter;
import java.io.IOException;
@Override
public boolean write(StudentCollection value) throws IOException {
var it = value.createIterator();
if (it == null)
return false;
System.out.print("StudentWriterStream.write");
while (it.hasNext()){
var student = it.next();
this.getWriter().write(student.getCode() + "," + student.getName()+"\n");
}
this.getWriter().close();
System.out.println(":Success");
return true;
}
}
WriterStream.java package
pack.Tools;
import java.io.FileWriter;
import java.io.IOException;
Package View
AddBookMenuItem.java
package pack.View;
import java.io.IOException;
CodeGenerator.generate(book);
handler.addBook(book);
System.out.println("\n\t<Operation Finished>");
Console.get_string("\tEnter <Any Key> to continue");
}
}
BorrowBookMenuItem.java
package pack.View;
import pack.Model.Book;
import pack.Model.BookHandler;
String caption;
switch (handler.borrowBook(book_code, stud_code)) {
case 1 -> caption = "<Student Code not found>"; case 2 ->
caption = "<Only 1 Book to Borrow per Student>"; case 3 -
> caption = "<Book Code not found>";
case 4 -> caption = "<Book is unavailable>";
default -> {
System.out.println("\n\t<Operation Finished>");
Console.get_string("\tEnter <Any Key> to continue");
return;
}
}
System.out.println("\n\t"+caption);
import java.util.Scanner;
System.out.print(prompt);
while (!scan.hasNextInt()){
System.out.println(error);
System.out.print(prompt);
scan.nextLine();
}
int ret = scan.nextInt();
scan.nextLine();
return ret;
}
MainMenu.java
package pack.View;
import pack.Model.BookHandler;
import java.io.IOException;
@Override
public void render(BookHandler handler) throws Exception {
while (true){
System.out.println("\n\n\t\t" +this.getTitle().toUpperCase() + "\n");
System.out.println(this);
int input;
while (true){
input = Console.get_int("\n\tEnter choice: ",
"\n\t<Please enter a valid input>"); if(input >= 0 &&
input <= getItemList().size()) break;
if(input == getItemList().size()){
System.out.println("\n");
return;
}
Console.clear();
getItemList().get(input).render(handler);
Console.clear();
}
Menu.java
package pack.View;
import pack.Model.BookHandler;
import java.util.ArrayList;
import java.util.List;
MenuItem.java
package pack.View;
System.out.println("\n\t<Operation Finished>");
Console.get_string("\tEnter <Any Key> to continue");
}
}
ReturnBookMenuItem.java
package pack.View;
import pack.Model.BookHandler;
if (handler.returnBorrowBook(stud_code) == 1)
System.out.println("\n\t<No book to be return>"); else
System.out.println("\n\t<Operation Finished>");
import pack.Model.BookHandler;
ShowBookMenuItem.java
package pack.View;
import pack.Model.BookHandler;
System.out.println("\n\t<Operation Finished>");
}
Console.get_string("\n\tEnter <Any Key> to continue");
}
}
ShowStudentMenuItem.java
package pack.View;
import pack.Model.BookHandler;
System.out.println("\n\t<Operation Finished>");
}
Console.get_string("\n\tEnter <Any Key> to continue");
}
}
SUMMARY
CLASS DIAGRAM