|
| 1 | +/* |
| 2 | + * To change this license header, choose License Headers in Project Properties. |
| 3 | + * To change this template file, choose Tools | Templates |
| 4 | + * and open the template in the editor. |
| 5 | + */ |
| 6 | +package library; |
| 7 | + |
| 8 | +import java.util.*; |
| 9 | +import java.io.*; |
| 10 | + |
| 11 | +/** |
| 12 | + * |
| 13 | + * @author Minahil Imtiaz |
| 14 | + */ |
| 15 | +public class Borrower extends Users { |
| 16 | + |
| 17 | + private String address; |
| 18 | + private String telephone; |
| 19 | + private boolean fine_defaulter; |
| 20 | + private double fine; |
| 21 | + private ArrayList<Loan> BookLoans; |
| 22 | + |
| 23 | + Borrower() { |
| 24 | + super(); |
| 25 | + fine_defaulter = false; |
| 26 | + BookLoans = null; |
| 27 | + fine = 0.0; |
| 28 | + address = " "; |
| 29 | + telephone = " "; |
| 30 | + BookLoans = new ArrayList<>(); |
| 31 | + |
| 32 | + } |
| 33 | + |
| 34 | + Borrower(int user_id, String user_name, char gender, String telephone, String address, boolean fine_defaulter, double fine) { |
| 35 | + super(user_id, user_name, gender); |
| 36 | + this.fine_defaulter = fine_defaulter; |
| 37 | + this.fine = fine; |
| 38 | + this.address = address; |
| 39 | + this.telephone = telephone; |
| 40 | + BookLoans = new ArrayList<>(); |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public boolean GetFineStatus() { |
| 46 | +// return this.fine_defaulter; |
| 47 | + dbConnectivity db = new dbConnectivity(); |
| 48 | + return (db.GetFineStatus(this.GetId())); |
| 49 | + } |
| 50 | + |
| 51 | + public double GetFineAmout() { |
| 52 | +// return this.fine; |
| 53 | + dbConnectivity db = new dbConnectivity(); |
| 54 | + return (db.GetFineAmount(this.GetId())); |
| 55 | + |
| 56 | + } |
| 57 | + |
| 58 | + public String GetAddress() { |
| 59 | + return this.address; |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | + public String GetTelephone() { |
| 64 | + |
| 65 | + return this.telephone; |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public boolean SetFineStatus(boolean fine_defaulter) { |
| 70 | + this.fine_defaulter = fine_defaulter; |
| 71 | + dbConnectivity db = new dbConnectivity(); |
| 72 | + boolean result = db.SetFineStatus(this.GetId(), fine_defaulter); |
| 73 | + return result; |
| 74 | + } |
| 75 | + |
| 76 | + public boolean SetTelephone(String Telephone) { |
| 77 | + this.telephone = Telephone; |
| 78 | + dbConnectivity db = new dbConnectivity(); |
| 79 | + boolean result = db.SetTelephone(this.GetId(), this.telephone); |
| 80 | + return result; |
| 81 | + |
| 82 | + } |
| 83 | + |
| 84 | + |
| 85 | + public boolean SetAddress(String Address) { |
| 86 | + this.address = Address; |
| 87 | + dbConnectivity db = new dbConnectivity(); |
| 88 | + boolean result = db.SetAddress(this.GetId(), this.address); |
| 89 | + return result; |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public void SetFineAmount(double user_fine) { |
| 95 | + this.fine = user_fine; |
| 96 | + dbConnectivity db = new dbConnectivity(); |
| 97 | + boolean result = db.SetFineAmount(this.GetId(), user_fine); |
| 98 | + |
| 99 | + |
| 100 | + } |
| 101 | + |
| 102 | + public void SetName(String name) |
| 103 | + { |
| 104 | + super.SetName(name); |
| 105 | + dbConnectivity db = new dbConnectivity(); |
| 106 | + boolean result = db.SetName(this.GetId(), name); |
| 107 | + |
| 108 | + } |
| 109 | + |
| 110 | + |
| 111 | + public void SetGender(char g) |
| 112 | + { |
| 113 | + super.SetGender(g); |
| 114 | + dbConnectivity db = new dbConnectivity(); |
| 115 | + boolean result = db.SetGender(this.GetId(), g); |
| 116 | + |
| 117 | + } |
| 118 | + |
| 119 | + @Override |
| 120 | + public boolean AddLoanInfo(Loan LoanInfo) { |
| 121 | + |
| 122 | + BookLoans.add(LoanInfo); |
| 123 | + return true; |
| 124 | +// dbConnectivity db = new dbConnectivity (); |
| 125 | +// boolean result=db.AddLoanInfo(this.GetId(), LoanInfo); |
| 126 | +// return result; |
| 127 | + |
| 128 | + } |
| 129 | + |
| 130 | + public void AllLoansofUser(ArrayList<Loan> LoansofUser) { |
| 131 | + |
| 132 | + // this.BookLoans=LoansofUser; |
| 133 | + dbConnectivity db = new dbConnectivity(); |
| 134 | + this.BookLoans = db.LoadLoanListofSpecificUser(this.GetId()); |
| 135 | + } |
| 136 | + |
| 137 | + //helping function to update loan info |
| 138 | + @Override |
| 139 | + public void UpdateLoanInfo(Loan Update, int book_id) { |
| 140 | + |
| 141 | +// Iterator<Loan> itr = BookLoans.Iterator(BookLoans.size()); |
| 142 | +// while (itr.hasPrevious()) { |
| 143 | +// |
| 144 | +// Loan L = itr.previous(); |
| 145 | + for (int counter=BookLoans.size()-1 ; counter >=0; counter--){ |
| 146 | + Loan L = BookLoans.get(counter); |
| 147 | + |
| 148 | + if ((L.GetaBookId() == book_id)) { |
| 149 | + L.SetLoan(Update); |
| 150 | + break; |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + } |
| 155 | + |
| 156 | + //needed to be checked |
| 157 | + @Override |
| 158 | + public String ViewInformation(ArrayList<Loan> LoanList, int user_id) { |
| 159 | + |
| 160 | + |
| 161 | + String Resultant=""; |
| 162 | + Resultant=Resultant+super.PrintInformation(); |
| 163 | + Resultant+="Adress :" + address+" "; |
| 164 | + Resultant+="Telephone:" + telephone+" "; |
| 165 | + Resultant+="\n Loan Info \n"; |
| 166 | + |
| 167 | + if (BookLoans.isEmpty() == false) { |
| 168 | + for (int i=0;i< BookLoans.size();i++) { |
| 169 | + Loan L=BookLoans.get(i); |
| 170 | + Resultant+=L.PrintLoanInfo(); |
| 171 | + Resultant+="\n"; |
| 172 | + } |
| 173 | + } else { |
| 174 | + |
| 175 | + Resultant +="NO LOANS TILL YET!"; |
| 176 | + } |
| 177 | + |
| 178 | + return Resultant; |
| 179 | + |
| 180 | + } |
| 181 | + |
| 182 | +} |
0 commit comments