im making a program a class file with two method a check in and a checkout method. the program calls for this: the balance on your account is 0 then you check out 10 books and then check in 6 the balance should be printed after each situation. after my object i made goes through the checked out method how do i take that number and use it as the balance for the next method? Im stuck!! heres my code:
public class LibraryAccount { private int bookBal; private int bookIn;// books checked in variable private int bookOut;// books checked out variable // constructor public LibraryAccount(int bookBal, int bookIn, int bookOut) { this.bookBal=bookBal; this.bookIn=bookIn; this.bookOut=bookOut; } // Get bookBal public int getBookBal(){ return bookBal; } // Set bookBal public void setBookBal(int tempBookBal){ bookBal = tempBookBal; } // Get bookIn public int getBookIn(){ return bookIn; } // Set bookIn public void setBookIn(int tempBookIn){ bookIn = tempBookIn; } // Get bookOut public int getBookOut(){ return bookOut; } // Set bookOut public void setBookOut(int tempBookOut){ bookOut = tempBookOut; } public int checkIn(){ int yourBal=this.bookBal+this.bookIn; return yourBal; } public int checkOut(){ int yourBal2=bookBal-bookOut; return yourBal2; }}
main class:
public class LibraryAccountDemo { public static void main(String[] args) { int bookBal=0; int bookIn=6;// books checked in variable int bookOut=10;// books checked out variable LibraryAccount myAccount = new LibraryAccount(bookBal,bookIn, bookOut); System.out.println("Your initially have a balance of " + bookBal); System.out.println("After checking out "+ bookOut+ " books you have " + myAccount.checkOut()); System.out.println("After checking in "+ bookIn+ " books you have " + (myAccount.checkOut()+myAccount.checkIn())); } }