Browse Source

Book class commented

Book.java
- Added comments for Book.java
- Added getter for id
- Added setter for title
- Removed the need of ‘status’ in constructor
- overdueFine(int[]) not commented as it needs to be updated

BookFactory.java
- need for (String status) is removed
master
BinHong Lee 8 years ago
parent
commit
26c455b64d
3 changed files with 46 additions and 6 deletions
  1. +34
    -4
      Book.java
  2. +7
    -2
      BookFactory.java
  3. +5
    -0
      Main.java

+ 34
- 4
Book.java View File

@@ -1,24 +1,36 @@
/*
* Written by : Bin Hong Lee
* Last edited : 4/27/2016
*/

class Book class Book
{ {
//Declaring variable storages
//Book title
private String title; private String title;
//Book ID
private int id; private int id;
//( AVAILABLE || RENTED || RESERVED || NOT AVAILABLE) //( AVAILABLE || RENTED || RESERVED || NOT AVAILABLE)
private String status; private String status;
//Book due date
private int[] dueDate = new int[3]; private int[] dueDate = new int[3];


public Book(int id, String status)
//Constructor without book title
public Book(int id)
{ {
this.id = id; this.id = id;
this.status = status;
this.status = "NOT AVAILABLE";
} }


public Book(String title, int id, String status)
//Constructor with book title
public Book(String title, int id)
{ {
this.title = title; this.title = title;
this.id = id; this.id = id;
this.status = status;
this.status = "AVAILABLE";
} }


//Getters and setters
public String getTitle() public String getTitle()
{ {
if (title!=null) if (title!=null)
@@ -34,26 +46,44 @@ class Book
return status; return status;
} }


public int getId()
{
return id;
}

public void setTitle(String title)
{
this.title = title;
}

//Call to rent book, return if renting is successful
public boolean rent(int[] dueDate) public boolean rent(int[] dueDate)
{ {
//Check if the book is available to be rented
if(status != "AVAILABLE") if(status != "AVAILABLE")
{ {
return false; return false;
} }


//Update the due date of the book
this.dueDate = dueDate; this.dueDate = dueDate;
//Update book status
status = "RENTED"; status = "RENTED";
return true; return true;
} }


//Call to return the book
public void returned() public void returned()
{ {
//Update book status
status = "AVAILABLE"; status = "AVAILABLE";
} }


//Calculate the overdue fine
public double overdueFine(int[] currentDay) public double overdueFine(int[] currentDay)
{ {
double fine; double fine;

if(currentDay[0] > dueDate[0] || currentDay[1] > (dueDate[1] + 1)) if(currentDay[0] > dueDate[0] || currentDay[1] > (dueDate[1] + 1))
{ {
return 5; return 5;


+ 7
- 2
BookFactory.java View File

@@ -1,3 +1,8 @@
/*
* Written by : Bin Hong Lee
* Last edited : 4/27/2016
*/

import java.util.*; import java.util.*;


class BookFactory class BookFactory
@@ -12,7 +17,7 @@ class BookFactory


public void newBook() public void newBook()
{ {
Book temp = new Book(id, "NOT AVAILABLE");
Book temp = new Book(id);
books.add(temp); books.add(temp);


id++; id++;
@@ -20,7 +25,7 @@ class BookFactory


public void newBook(String title) public void newBook(String title)
{ {
Book temp = new Book(title, id, "NOT AVAILABLE");
Book temp = new Book(title, id);
books.add(temp); books.add(temp);


id++; id++;


+ 5
- 0
Main.java View File

@@ -1,3 +1,8 @@
/*
* Written by : Bin Hong Lee
* Last edited : 4/27/2016
*/

class Main class Main
{ {
static BookFactory books = new BookFactory(); static BookFactory books = new BookFactory();


Loading…
Cancel
Save