OOPS CASE STUDY 2

Sept. 27, 2019, 6:58 a.m. | OOPS in Java


Faculty Name

Mr. P. N. Ramesh

Course Code / Title

CS8392&Object Oriented Programming

Focus Area

OOPS based Design and Development of Solutions

Learning Outcome

Design a OOP based application for the given requirements

Teaching Pedagogy

Case Study & Discussion

Knowledge Level

K3


Instructions to Students:

1.      Read the Problem Description carefully and understand the Scenario and Class Diagram.

2.      Read the implementation details and understand the requirements you need to implement.

3.   Library.java file contains all the necessary classes and the classes are partially coded to implement the given scenario.

Guidelines:

1.      You should only code your program at the space mentioned as “//Replace Your Code”.

2.      Your Code should satisfy the requirements specified in the Implementation Details.

3.      Don’t add additional methods in any class.

NOTE: NOT adhering to the above instructions and guidelines may lead to drastic reduction in your score even if the code is executing without any errors

Problem Description:

Karpagam Institute of Technology is incepted with the vision of providing cutting edge technical education and to create proficient engineers. Karpagam Institute of Technology has a Central Library with 50000 Volumes including Books and Journals. 2000 students and 200 Faculty Members are using the Library for Reference and to enhance their knowledge.Now Management of the institution decided to computerize the Central library to manage the Library transaction for improving reliability and simplicity. As part of it, now we are developing a Module to maintain book issue details. 

Business Rules:

1.      Any Member of Library could only avail specified number of books (E.g. 5) at a time.

          2.      A Book can be availed by only one member at a time. 

Our Module should satisfy the above requirements along with the functional requirements to achieve reliability.


 Rules:

1.      1.  Don’t add additional instance variable in the given class.

 2.  Do Type conversions wherever it is necessary.

 3.  Don’t make change in the Library Class.

Implementation Details:           

Member Class

Ø  This Class Contains Constructor to initialize the Data Members MemberID, MemberName and MemberType.     

Ø      Ø  This Class contains Getter Method for all the Instance Members.

Book Class

This Class is coded already for you.

Ø  This Method is a Constructor Method to initialize the BookId, Title, Publisher, Author and Edition.

Ø  Use Super class Constructor to initialize the super class data members BookId, Title and Publisher.

Journal Class

This Class Inherits the Class Book

Journal(String,int,int) method:       

Ø  This Method is a Constructor Method to initialize BookId, Title, Publisher, Editor, Volume and Issue.

Ø  Use Super class Constructor to initialize the super class data members BookId, Title and Publisher.

LibraryDb Class

ValidateMemberEligibility(int):int method:

Ø  Issuebook(int,int):void method:

  Ø  This method accepts Memberid of a member and Bookid of a Book.

Ø     Ø This method finds the index of Memberid in the Members[] array through linear search.

·                       ·         Then, find the Number of Books taken by the member using the same index in the Bookstaken[] array.

               ·         If it is 5 then return 1, else return 0;

Ø     Ø If the Memberid is not find in the Members[] array, then return 0. 

VaidateBookAvailability(int):int method:

Ø This method accepts Bookid of a book.

Ø  This method finds the index of Bookid in the Books[] array through linear search.

          ·         Then, find the Book availability using the same index in the BookStatus[] array.

          ·         If it is 0 then return 0, else return 1;

Ø  If the Bookid is not find in the Books[] array, then return 0.

Issuebook(int,int):void method:

Ø  This method accepts Memberid of a member and Bookid of a Book. 

Ø  This method finds the index of the member through linear search and updates the value of same index        in Bookstaken[] array by increasing 1.

Ø  This method finds the index of the book through linear search and update the value of same index in

           BookStatus[] array by 0. 

Transaction Class

Transaction (Member,Book) method: 

Ø  This method is a constructor method that initializes the member and book objects.

BorrowBook() method:

Ø  This method is used to borrow a book from Library.

Ø  This method invoke validateMemberEligibility() method of LibraryDb, if valid

          o   Invoke validateBookAvailability() method of LibraryDb, if valid

                        ·         This method gets current date as Borrow date from system.

                        ·         This method calculates return date by adding 14 days from Borrow date.

                        ·         This method displays Borrow date and Return date as follows

 Borrow date:dd/MM/yyyy

Return date:dd/MM/yyyy

                        ·         This method invoke issue book() method of LibraryDb to update the Number of bookstaken[] and BookStatus[].

Demo Class:

Ø  This Class is a Starter Class.

Ø   Code is already provided for you.

Ø  You can modify the class for testing purpose.

Ø  This class will not be evaluated.

This Code includes solution for the above question. The code below comment line // write your code here is the solution.

      Solution Code:

importjava.text.DateFormat;

importjava.text.SimpleDateFormat;

importjava.util.*;

//Member Class

class Member

{

 privateintiMemberId;

 private String sMemberName;

 private String sMemberType;

 staticint counter=2000;

 Member(String sMemberName, String sMemberType )

{

 this.iMemberId = ++counter;

 this.sMemberName = sMemberName;

 this.sMemberType = sMemberType;

 }

 publicintgetMemberId()

{

 returniMemberId;

 }

 public String getMemberName()

{

 returnsMemberName;

 }

 public String getMemberType()

 {

 returnsMemberType;

  }

  }

//Book Class

class Book {

privateintiBookId;

private String sTitle;

private String sPublisher;

staticint counter = 1000;

Book(String sTitle, String sPublisher)

{

this.iBookId = ++counter;

this.sTitle = sTitle;

this.sPublisher = sPublisher;     

}

publicintgetiBookId() {

returniBookId;

}

public String getsTitle() {

returnsTitle;

}

public String getsPublisher() {

 returnsPublisher;

}

}

//TextBook Class

classTextBook extends Book {

private String sAuthor;

privateintiEdition;

TextBook(String sTitle, String sPublisher,StringsAuthor, intiEdition)

{

super(sTitle,sPublisher);

this.sAuthor = sAuthor;

this.iEdition = iEdition;

}

public String getsAuthor() {

 returnsAuthor;

}

publicintgetiEdition() {

 returniEdition;

}

}

//Journal Class

class Journal extends Book {

private String sEditor;

privateintiVolume;

privateintiIssue;

 Journal(String sTitle, String sPublisher,StringsEditor, intiVolume, intiIssue)

{

 super(sTitle,sPublisher);

 this.sEditor =sEditor;

  this.iVolume = iVolume;

  this.iIssue = iIssue;

}

 public String getsEditor() {

  returnsEditor;

}

 publicintgetiVolume() {

  returniVolume;

}

 publicintgetiIssue() {

 returniIssue;

}

 }

 //LibraryDB class

classLibraryDb {

private static int[] Members = {2001,2002,2003,2004,2005};

private static int[] BooksTaken = {3,5,2,3,5};

private static int[] Books = {1001,1002,1003,1004,1005};

private static int[] BookStatus = {1,1,0,1,0};

public static intvalidateMemberEligiblity(intiMemberId)

{

//write your code here

 for (intiCount = 0; iCount<5; iCount++)

 {

  if(Members[iCount] == iMemberId)

  {

  if(BooksTaken[iCount]==5)

   {

     return 0;

   }

   else

   {

    return 1;

    }

    }      

    }

     return 0;

   }

 public static intvalidateBookAvailability(intiBookId)

{

//write your code here

  for (intiCount = 0; iCount<5; iCount++)

{

if(Books[iCount] == iBookId)

{

if(BookStatus[iCount]==0)

 {

return 0;

 }

 else

 {

 return 1;

 }

 }

 }

 return 0;

}

  public static void issueBook(intiMemberId, intiBookId)

{

//write your code here

 for (intiCount = 0; iCount<5; iCount++)

 {

  if(Members[iCount] == iMemberId)

   {         

   BooksTaken[iCount] +=1;

   }   

   }

    for (intiCount = 0; iCount<5; iCount++)

   {

    if(Books[iCount] == iBookId)

   {

   BookStatus[iCount] = 0;

}

}

}

}

//Transaction Class

class Transaction {

private Book bObj;

private Member mObj;

privateintiTransId;

private Date dBorrow;

private Date dReturn;

staticintiCounter =10000;

Transaction(Member mObj, Book bObj)

{

iTransId = ++iCounter;

this.bObj = bObj;

 this.mObj = mObj;

}

 public void borrowBook()

{

//write your code here

DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

Calendar cal = Calendar.getInstance();

if(LibraryDb.validateMemberEligiblity(mObj.getMemberId()) == 1)

{

if(LibraryDb.validateBookAvailability(bObj.getiBookId()) == 1)

{

dBorrow= new Date();

cal.setTime(dBorrow);

cal.add(Calendar.DATE,14);

Date dReturn = cal.getTime();

 System.out.println("Issue Date:"+ formatter.format(dBorrow));

 System.out.println( "Return Date:" + formatter.format(dReturn));

  LibraryDb.issueBook(mObj.getMemberId(),bObj.getiBookId());

   }

 else

 {

System.out.println("Book is not Available");

 }

}

else

{

System.out.println("Member Cannot Take Book");

}

}

}

//Demo Class

class Demo {

 public static void main(String[] args) {

 Member mObj = new Member("Ramesh","Faculty");

 Book bObj = new TextBook("Operating systems","TATA","Ramakrishnan",3);

 Transaction tObj = new Transaction(mObj,bObj);

  tObj.borrowBook();

  Member mObj1 = new Member("Ram","Student");

  Book bObj1 = new TextBook("Computer Networks","Pearson","Forozan",3);

  Transaction tObj1 = new Transaction(mObj1,bObj1);

   tObj1.borrowBook();

}

}

 

}                                                  


Comments

Related Posts