Advertisement
gdog2u

Too many on loan

Apr 29th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. public void markOnLoan() throws IOException{
  2.         System.out.println("Items not on loan:  "+(items.size()-amountOnLoan)); //on start, should return just items.size();
  3.         try{
  4.             Object[] possible = new Object[items.size()-amountOnLoan];//gets all possible options to mark on loan
  5.             for(int i = 0; i < items.size();i++){
  6.                 if(items.get(i).getOnLoan() == false){
  7.                     possible[i] = items.get(i);
  8.                 }
  9.             }
  10.             Object temp = JOptionPane.showInputDialog(null,"Which Item would you like to loan out?", "Loan out item", 0, null, possible, possible[0]);
  11.             if(temp != null){
  12.                 String tempN = JOptionPane.showInputDialog(null, "Who did you loan this item too?");
  13.             if(tempN != null){
  14.                 String tempD = JOptionPane.showInputDialog(null, "When was this item loaned out?");
  15.                 if(tempD!=null){
  16.                     items.get(items.indexOf(temp)).markOnLoan(tempN, tempD);
  17.                     fileWriter(items);
  18.                     amountOnLoan = amountOnLoan + 1; //if the user hasn't pressed cancelby this point, should add 1 to the amount on loan
  19.                     }
  20.                 }
  21.             }
  22.         }catch(ArrayIndexOutOfBoundsException e){
  23.             JOptionPane.showMessageDialog(null, "No items to loan.", "Error", JOptionPane.ERROR_MESSAGE);
  24.         }
  25.         System.out.println("Items now on loan: " + amountOnLoan);
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement