The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
// Can you please fill this in
/* Accounting class
 Anderson, Franceschi
 */
Â
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
import javax.swing.JFrame;
import java.awt.Graphics;
import java.util.ArrayList;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;
import java.io.EOFException;
import java.io.FileNotFoundException;
Â
public class Accounting extends JFrame
{
 private BankAccount bankAccount;
Â
 public Accounting()
 {
  super("Reading objects from a file");
  bankAccount = new BankAccount(getBackground());
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setSize(300, 300);
  setVisible(true);
 }
Â
 public void balanceCheckBook()
 {
  //
  // ***** Student writes the body of this method *****
  //
  // Using a while loop, read the file transactions.obj
  // The file transactions.obj contains transaction objects
  //
  // You will need to call the animate method inside
  // the body of the loop that reads the objects
  //
  // The animate method takes two arguments:
  //  a Transaction object, representing the transaction
  //  a double, representing the new checkbook balance
  // So if these two variables are transaction and balance,
  // then the call to animate will be:
  //
  // animate(transaction, balance);
  //
  // You should make that call in the body of your while
  // loop, after you have updated the checkbook balance
  //
  // Student code starts here:
Â
  // Student code ends here.
 }
Â
 public void writeTransactions(ArrayList<Transaction> transactionList)
 {
  //
  // writing to file transactions.obj
  //
Â
  try
  {
   FileOutputStream fos = new FileOutputStream("transactions.obj");
   ObjectOutputStream oos = new ObjectOutputStream(fos);
Â
   Transaction tempTransaction;
   for (int i = 0; i < transactionList.size(); i++)
   {
    tempTransaction = (Transaction) transactionList.get(i);
    oos.writeObject(tempTransaction);
   }
   oos.close();
  }
  catch (IOException ioe)
  {
   System.out.println(ioe.toString());
   System.out.println(ioe.getMessage());
  }
 }
Â
 public void animate(Transaction currentTransaction, double currentBalance)
 {
  // set the currentTransaction data member in the bankAccount object
  bankAccount.setCurrentTransaction(currentTransaction);
Â
  // set the currentBalance data member in the bankAccount object
  bankAccount.updateBalance(currentBalance);
Â
  repaint();
  try
  {
   Thread.sleep(3000); // wait for the animation to finish
  }
  catch (Exception e)
  {
  }
 }
Â
 public void paint(Graphics g)
 {
  super.paint(g);
  if (bankAccount != null)
  {
   bankAccount.draw(g);
  }
 }
Â
 public static void main(String[] args)
 {
  Accounting app = new Accounting();
Â
  // Generate an ArrayList of Transaction objects to write to file Transaction.obj
  ArrayList<Transaction> transactionList = new ArrayList<Transaction>();
  Check c1 = new Check(-500.00);
  transactionList.add(c1);
  Deposit d1 = new Deposit(3000.00);
  transactionList.add(d1);
  Withdrawal w1 = new Withdrawal(-400.00);
  transactionList.add(w1);
  c1 = new Check(-300.00);
  transactionList.add(c1);
Â
  // write transactions as objects to file transaction.obj
  app.writeTransactions(transactionList);
Â
  // read transaction.obj, balance the checkbook
  app.balanceCheckBook();
 }
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly