java - Library System: Borrowing -


i not know how borrowholding() in library menu have create. purpose of borrowholding() members able borrow books or videos.

this sample data of array:

member[0] = new standardmember("id", "name"); member[1] = new premiummember("id", "name"); holding[0] = new book("id", "title"); holding[1] = new video("id", "title", loanfee); 

this borrowholding() method in testlibrary class: (the array in testlibrary class too)

public static void borrowholding(){     string option;     option = input.next();  do{      scanner scan = new scanner(system.in);     int tempid = 0;     system.out.println("enter id: ");     string searchid = scan.next();      for(int = 0; < member.length; i++){          if(member[i].getid().equals(searchid)){                  tempid = i;              }         } 

so method, tried write code search through array find memberid wants borrow. not completed yet because believe not doing correctly

there member class contains

public class member{      public holding[] getcurrentholdings(){     }  } 

from name of method, used store holdings of members borrowed. if member 1 borrows book, book stored inside array, think. thinking of using arraylist method, not sure if make sense.

to borrow book or video, there conditions able borrow, not know how implement borrowholding(). 1 of condition in holding class.

public class holding{     public boolean borrowholding(){         if(status == true && isonloan() == false)             borrowdate = newdatetime(); //this time when book or video borrowed              return true;         }else             return false;      } } 

and there condition in member class member must have enough credit borrow. book loan fee cost $10 , video vary $4 or $6.

i think wrote few information not needed guess better less information.

my problem do borrowholding() method in librarymenu? how make if member wants borrow holding, holding go under member's array in member class

public class member{      public holding[] getcurrentholdings(){     }  } 

with condition holding class if met, , while executing borrowholding method, method member class able subtract member credit loan fee book or video. possible?

public class member{     private int credit = 30;     public int calculateremainingcredit(){          credit = credit - //(the loan fee book or video class)      } } 

if intentions add holding member class possible. suggest adding arraylist of holding's rather regular array because seems if size going changing.

public class member{     private arraylist<holding> currentholdings; // may need import arraylist     private int credit;      public void init(){ // goes in constructor          currentholdings = new arraylist<holding>();         credit=0;     }      public void addholding(holding newholding){ // adds new holding members array         currentholdings.add(newholding);         credit-=newholding.getfee(); // need add fee variable holding class;     } } 

and checking see whether or not member has enough "credit", can done in borrowholding() method right after identify index of array. recommend adding parameter of member borrowholding() method can access variables member.

if(member[i].getid().equals(searchid)){     tempid = i;     int tempholding; // index of whatever holding wanted (could scanner)      if (holding[tempholding].borrowholding(member[tempid])){ // check status         member[tempid].addholding(holding[tempholding]); // have passed req. can add holding     }      break; } 

hope answered question.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -