Adding a date/time stamp

Starting time and ending time

Page 1 of 1

3 Replies - 3820 Views - Last Post: 28 April 2010 - 01:16 PM Rate Topic: -----

#1 draftcopy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 21-February 10

Adding a date/time stamp

Posted 28 April 2010 - 01:07 PM

Hello... I have a question regarding adding a date/time stamp that shows the time logged-in and logged-out in an ATM simulation. I can get the ending time, but the way I have the code now, the starting time is the same as the ending time. Not sure how to correct this. Help appreciated and code in question starts at line 81.

import javax.swing.*;              // imports dialog boxes 
import java.text.NumberFormat;     // imports number formatting
import java.text.DateFormat;       // imports date
import java.util.Date; 

public class AtmSimulation {
  private Account acct1;  	    // declare Account instanced variable
  
  private NumberFormat dollars = NumberFormat.getCurrencyInstance(); 
    
  // no-argument  constructor processes the ATM transactions
  public AtmSimulation()  {
  	      
    // create new acct1 object
    //                <===== provide YOUR NAME as the 1st argument
     acct1 = new Account("Christopher Casale", 12345, 200);   	
  	 
     String menu = "Bank of Java  ATM \n"+
    		  "Choose from the following list\n\n" +
                  "1.  Balance Inquiry\n" +
                  "2.  Deposit\n" +
                  "3.  Withdrawl Quick $50\n" +
                  "4.  Withdrawl\n" +
                  "5.  Quit\n" +
                  "Enter your choice: 1, 2, 3, 4, 5";   
    String input;  
    int choice; 
    
    System.out.println( "Bank of Java ATM :  transaction log for account #: 12345, Christopher M. Casale." );
    System.out.println( "This ATM charges an automatic $1 fee for withdrawals!!\n");
    
    do    {
      input = JOptionPane.showInputDialog (menu);
      choice = Integer.parseInt(input);
    
      switch (choice)  {  
        case 1:  atmBalance(); break; 
        case 2:  atmDeposit(); break;
        case 3:  atmQuick50(); break;
        case 4:  atmWithdraw(); break;
        case 5:  atmQuit(); break;   
      }   
    } while (choice != 5);
    
  } // end AtmSimulation constructor
 
  public void atmBalance()  {
     System.out.println ("\nBalance: " + acct1.toString() + "\n");
  } 

  public void atmDeposit()   { 
     String input=JOptionPane.showInputDialog("Deposit Amount?: ");
     double amount=Double.parseDouble(input);
     System.out.println("Depositing: "+ dollars.format( amount ));  	
  	 acct1.deposit(amount);
  }
  
  // withdraws $50 + $1 fee
  public void atmQuick50() {
  	// finish this method
  	System.out.println("Withdraw Quick $50: "+ dollars.format( 51 ));
  	acct1.withdraw(50, 1);
  }
  
  // add atmWithdraw method here
  public void atmWithdraw() {
  	// finish this method
  	String input=JOptionPane.showInputDialog("Withdrawl amount?: ");
  	double amount=Double.parseDouble(input);
  	
  	if (amount <= 300) {
  		
  		System.out.println("Withdraw: " + dollars.format(amount + 1 ));
  		acct1.withdraw(amount, 1);
  	} else {
  		System.out.println("Maximum limit is $300 !");
  		
  	}
  }
  
  public void atmQuit()   {
  	DateFormat dateTime = DateFormat.getDateTimeInstance();
  	System.out.println("Bank of Java ATM transaction log-in started at: " + dateTime.format( new Date() ));
  	System.out.println("Bank of Java ATM transaction log completed on: " + dateTime.format( new Date() )); 
    // finish this method   
  }
  
  // create the application object - calls the AtmSimulation constructor  
  public static void main(String [] args)   {  	  	
     AtmSimulation application = new AtmSimulation();
  }  
}      // end AtmSimulation class



Is This A Good Question/Topic? 0
  • +

Replies To: Adding a date/time stamp

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: Adding a date/time stamp

Posted 28 April 2010 - 01:11 PM

The reason for this is b/c the start and end times are both invoked in the quit() method, so the Date objects are assigned two very close timestamps. You may want to create a Date object when the program is initialized for your startTime, and display it in the quit() method.
Was This Post Helpful? 0
  • +
  • -

#3 draftcopy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 21-February 10

Re: Adding a date/time stamp

Posted 28 April 2010 - 01:15 PM

You know... I didn't even think of that. Thanks for bringing that simple solution to my attention. lol
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: Adding a date/time stamp

Posted 28 April 2010 - 01:16 PM

Not a problem. Glad I could help! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1