public void buyItemFromUser(User buyer, User seller, Item currentItem) // PRE: buyer, seller, currentItem must be initialized // POST: Purchases item from the store and has stores it into inventory. { int buyer_balance; // The new balance of the buyer int seller_balance; // The new balance of the seller String str; // First query String str2; // Second query String str3; // Third query buyer_balance = buyer.getBalance() - currentItem.getPrice(); seller_balance = seller.getBalance() + currentItem.getPrice(); if (buyer_balance > 0) // If the buyer wont go negative { str = String.format( "Update users set balance = (%d) where user_name = '%s'", buyer_balance, buyer.getUserName()); str2 = String.format( "Update users set balance = (%d) where user_name = '%s'", seller_balance, seller.getUserName()); str3 = String.format( "Update items set owner_id = (%d) where item_name = '%s'", buyer.getUserId(), currentItem.getItemName()); updateTables(str, str2, str3); } else { // Prompt the user with an error JOptionPane.showMessageDialog( null, "You will go bankrupt if you try buying that, try selling some items."); } }