Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

class Account: balance = 0.0; transactions = []; def __init__(self, balance): se

ID: 3619851 • Letter: C

Question

class Account:
        balance = 0.0;
        transactions = [];
        def __init__(self, balance):
                self.balance = balance;
        def deposit(self, amt):
                self.balance = self.balance + amt
                t = Transaction("Deposit",self.balance);
                self.transactions.append(t);
                print "Balance:" + str(self.balance);
        def withdraw(self,amt):
                self.balance = self.balance - amt
                t = Transaction("Withdraw",self.balance);
                self.transactions.append(t);
                print "Balance:" + str(self.balance);
        def displayTransactions(self):
                for key in self.transactions:
                        key.showTransaction();
        def getbalance(self):
                return self.balance

foo = Account(10000)
b = 1
print "Welcome to the Petty Cash System!"
print "Primary account balance for an account:10000"
while(b != 3):
    print "Please make a selection by typing one of the following options."
    print "1.Deposit balance #: 1"
    print"2.Withdraw balance #: 2"
    print "3.Show transactions #: 3"
    print "4.exit the Database type the #: 4"
    b = input(':')
    if b == 1:
        print "Enter the Deposit:"
        n = raw_input(':')
        foo.deposit(int(n));
    if b == 2:
        print "Enter the Withdraw:"
        n = raw_input(':')
        foo.withdraw(int(n));
    if b == 3:
        foo.displayTransactions();
    if b == 4:
        break;

Explanation / Answer

import shelve
import string
import datetime
class Transaction:
        DateOfTransaction = datetime.datetime(1900,1,1).today();
        TypeOfTransaction = "";
        FinalBalance = "";
        def __init__(self, TypeOfTransaction,FinalBalance):
                self.TypeOfTransaction =TypeOfTransaction;
                self.FinalBalance = FinalBalance;
        def showTransaction(self):
                if(self.TypeOfTransaction!="View transactions"):
                        print str(self.DateOfTransaction) + "    "+self.TypeOfTransaction + "         " +str(self.FinalBalance);
        def showRequest(self):
                print str(self.DateOfTransaction) + "    "+self.TypeOfTransaction + "         " +str(self.FinalBalance);
class Account:
        balance = 0.0;
        transactions = [];
        HistoricalDates = [];
        DateOfTransaction = datetime.datetime(1900,1,1).today();
        def __init__(self, balance):
                self.balance = balance;
        def deposit(self, amt):
                self.balance = self.balance + amt
                t = Transaction("Deposit",self.balance);
                self.DateOfTransaction = datetime.datetime(1900,1,1).today();
                self.transactions.append(t);
                self.HistoricalDates.append(self.DateOfTransaction);
                print "Balance:" + str(self.balance);
        def withdraw(self,amt):
                self.balance = self.balance - amt
                t = Transaction("Withdraw",self.balance);
                self.DateOfTransaction = datetime.datetime(1900,1,1).today();
                self.HistoricalDates.append(self.DateOfTransaction);
                self.transactions.append(t);
                print "Balance:" + str(self.balance);
        def displayTransactions(self):
                self.DateOfTransaction = datetime.datetime(1900,1,1).today();
                t = Transaction("View transactions",self.balance);
                self.transactions.append(t);
                self.HistoricalDates.append(self.DateOfTransaction);
                for key in self.transactions:
                        key.showTransaction();
        def viewRequests(self):
                print "Date of transaction" + "    "+"Type of transaction" + "         " +"Final balance";
                for key in self.transactions:
                        key.showRequest();
        def getbalance(self):
                return self.balance

foo = Account(10000)
b = 1
print "Welcome to the Petty Cash System!"
print "Primary account balance for an account:10000"
while(b != 5):
   print "Please make a selection by typing one of the following options."
   print "1.Deposit balance #: 1"
   print"2.Withdraw balance #: 2"
   print "3.Show transactions #: 3"
   print "4.Show requets #: 4"
   print "5.exit the Database type the #: 5"
   b = input(':')
   if b == 1:
       print "Enter the Deposit:"
       n = raw_input(':')
       foo.deposit(int(n));
   if b == 2:
       print "Enter the Withdraw:"
       n = raw_input(':')
       foo.withdraw(int(n));
   if b == 3:
       foo.displayTransactions();
   if b == 4:
       foo.viewRequests();
   if b == 5:
       break;