Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Bank Account Program - Transaction History
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JDL




PostPosted: Fri Oct 19, 2007 1:05 pm   Post subject: Bank Account Program - Transaction History

I am trying to build some sort of baking program for a school assignment. Iv meet most of the requirements but i need help logging transactions done during the active process. It does not need to save the information to a text file or anything. All it needs to do is keep a temporary memory of all transactions done. Here is what I have in terms of code.


MainProgram

code:

import java.util.*;

public class MainProgram {
   
    public static void main(String[] args) {

//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
        Scanner scanner;       
        Date today;
        String lineSeparator = System.getProperty("line.separator");
        today = new Date();                                                                      //this initilizes the date
        scanner = new Scanner(System.in);                                                                             //initializes the scanner so input is possible
        scanner.useDelimiter(lineSeparator);
        double transAmount;
        int transOption;
        int transNumber;
        boolean userWantsToQuit = false;
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------

        //create some bank account objects
        BankAccount b1 = new BankAccount("Bob ", 1001, 1000.0);
        BankAccount b2 = new BankAccount("Joe ", 1002, 0.0);
        BankAccount b3 = new BankAccount("Jack", 1003, 500.0);
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------         
                while (!userWantsToQuit){
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
                System.out.println("The Time Is: " + today);
                System.out.println("Welcome To The Bank Account Program.");
                System.out.println("There Are Three Registered Account Holders.");
                System.out.println("");
                System.out.println("");
                System.out.println("                Here Are The Account Inquiries");
                System.out.println("-------------------------------------------------------------------------------------");
                System.out.println(b1);
                System.out.println("-------------------------------------------------------------------------------------");
                System.out.println(b2);
                System.out.println("-------------------------------------------------------------------------------------");
                System.out.println(b3);
                System.out.println("-------------------------------------------------------------------------------------");
             System.out.println("");
             System.out.println("");
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------        
                System.out.println("Would You Like To Do:" );
                    System.out.println("-------------------------------------------------------------------------------------");
                System.out.println("Withdrawl                  (1)");
                System.out.println("Deposit                        (2)");
                System.out.println("Account Summery        (3)");
                System.out.println("History                        (4)");
                    System.out.println("-------------------------------------------------------------------------------------");
                                transOption = scanner.nextInt();
                System.out.println("");
                System.out.print("For Which Account - Enter In An Account Number: ");
                                transNumber = scanner.nextInt();                         
                System.out.println("");
                
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
                                        if(transNumber == b1.accountNumber && transOption == 1){
                                 System.out.println("How Much Will You Withdraw");
                                                transAmount = scanner.nextDouble();
                                                b1.withdraw(transAmount);
                      }
                      else if(transNumber == b1.accountNumber && transOption == 2){
                                System.out.println("How Much Will You Deposit");
                                                transAmount = scanner.nextDouble();
                         b1.deposit(transAmount);
                      }
                      else if(transNumber == b1.accountNumber && transOption == 3){
                         b1.summery(0);
                      }
                      else if(transNumber == b1.accountNumber && transOption == 4){
                                System.out.println("UNDER CONSTRUCTION");
                                                transAmount = scanner.nextDouble();
                         b1.deposit(transAmount);
                      }
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
                                        if(transNumber == b2.accountNumber && transOption == 1){
                                System.out.println("How Much Will You Withdraw");
                                                transAmount = scanner.nextDouble();
                            //b2.withdraw(transAmount);
                      }
                      else if(transNumber == b2.accountNumber && transOption == 2){
                                System.out.println("How Much Will You Deposit");
                                                transAmount = scanner.nextDouble();
                         //b2.deposit(transAmount);
                      }
                      else if(transNumber == b2.accountNumber && transOption == 3){
                         b2.summery(0);
                      }
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
                                        if(transNumber == b3.accountNumber && transOption == 1){
                                System.out.println("How Much Will You Withdraw");
                                                transAmount = scanner.nextDouble();
                            //b3.withdraw(transAmount);
                      }
                      else if(transNumber == b3.accountNumber && transOption == 2){
                                System.out.println("How Much Will You Deposit");
                                                transAmount = scanner.nextDouble();
                         //b3.deposit(transAmount);
                      }
                      else if(transNumber == b3.accountNumber && transOption == 3){
                         b3.summery(0);
                      }
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
                             System.out.println("");
                                System.out.println("After Transactions:");
                                System.out.println("===================");
                                System.out.println("-------------------------------------------------------------------------------------");
                                System.out.println(b1);
                                System.out.println("-------------------------------------------------------------------------------------");
                                System.out.println(b2);
                                System.out.println("-------------------------------------------------------------------------------------");
                                System.out.println(b3);
                                System.out.println("-------------------------------------------------------------------------------------");
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------     
                                        System.out.println("");
                                        System.out.print("Do You Want to Perform Another Transaction? [Y or N] ");
                                        String userResponse = scanner.next();
                                                if(userResponse.startsWith("Y") || userResponse.startsWith("y")){              //the user can end the application here
                                                        userWantsToQuit = false;
                                                }
                                                else{
                                                        userWantsToQuit = true;
                                                }
                }
                                        System.out.println("");
                                        System.out.println("GOODBYE");
   
    }
}




BankAccount

code:

import java.util.*;

public class BankAccount {
       
        private String owner; //name of the owner
        public int accountNumber; //account number, should be unique
        private double balance; //amount of money currently in the account
               
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------- 
        public BankAccount(String anOwnerName, int anAccountNumber, double openingBalance){
                owner = anOwnerName;
                accountNumber = anAccountNumber;
                balance = openingBalance;
        }
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
                               
        private void Transaction(String transactionType, double openingBalance){
                //print the transaction details
                System.out.println("Owner: " + owner + " ----- " + "Account: #" + accountNumber + " ----- " + "Transaction: " + transactionType + " ----- " + "Opening Balance: " + "$" + openingBalance + " ----- " + "Closing Balance: " + "$" + balance);
        }

//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
        public BankAccount summery(double anAmount){
               
                //adjust the balance and then return the object on behalf of which
                //this methods is being run.
                double openingBalance = balance;               
                balance = (balance);       
                Transaction("DEPOSIT ", openingBalance);
                return this; //needed for chaining
        }
               
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
       
        public BankAccount deposit(double anAmount){       
                //adjust the balance and then return the object on behalf of which
                //this methods is being run.
                double openingBalance = balance;               
                balance = (balance - 1.50) + anAmount;   
                Transaction("DEPOSIT ", openingBalance);
                return this; //needed for chaining
        }
       
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
       
        public BankAccount withdraw(double anAmount){
               
                //adjust the balance and then return the object on behalf of which
                //this methods is being run.
        double openingBalance = balance;
       
                balance = (balance - 1.50) - anAmount ;  
                Transaction("WITHDRAW", openingBalance);
              return this; //needed for chaining
        }
               
        public String toString(){
                return "Owner: " + owner + " ----- " + "Account: #" + accountNumber + " ----- " + "Balance: " + "$" + balance + " ----- " + " Service Charge: " + "$1.150";
        }
}
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
       


one of the requirements for this assignment is that I make a new class file which handles the transaction history. all help is appriciated
Sponsor
Sponsor
Sponsor
sponsor
HellblazerX




PostPosted: Sat Oct 20, 2007 10:54 am   Post subject: RE:Bank Account Program - Transaction History

Why not make Transaction a class of its own rather than just a method? That way you can store all your Transactions into a Collection.
Tony




PostPosted: Sat Oct 20, 2007 5:49 pm   Post subject: RE:Bank Account Program - Transaction History

so you make a Singleton class for Transactions, and as Hellblazer suggests - have all the new data be pushed onto a Collection.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: