SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 2 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 30 Oct 2017 My Price 9.00

Using a while loop, read the file transactions.obj

// 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();

 }

}

Answers

(5)
Status NEW Posted 30 Oct 2017 12:10 PM My Price 9.00

-----------  ----------- 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

Not Rated(0)