So once again I have a question about this program. I want to store transactions that are made in an arraylist and then have an option in the case menu where I can print out those that are stored. I have been researching online and have been unable to find a solution to this, so is this possible and how would I go about doing this? I also want to attach a timestamp to each transaction as well. Here is the code I have so far.
So my question is how would I add a timestamp to each withdrawal or deposit, and how would I store each transaction in array list?
import java.util.*;
public class BankAccount extends Money { //inheritence
static String name;
public static int acctNum;
public static double balance, amount;
BankAccount(String name, int accNo, double bal) {
this.name = name;
this.acctNum = accNo;
this.balance = bal;
}
void display() {
System.out.println("Your Name:" + name);
System.out.println("Your Account Number:" + acctNum);
System.out.println("Your Current Account Balance:" + Money.getBalance());
}
void displayBalance() {
System.out.println("Balance:" + balance);
}
}
import java.util.Scanner;
/**
*
* @author Ricky
*/
public class Money
{
public static int accountNumber;
public static double balance;
static double amount;
static String name;
public void setDeposit(double amount) {
balance = balance + amount;
if (amount < 0) {
System.out.println("Invalid");
}
}
public double getDeposit()
{
return 1;
}
public void setBalance(double b)
{
balance = b;
}
public static double getBalance()
{
return balance;
}
public void setWithdraw(double amount) {
if (balance < amount)
{
System.out.println("Not enough funds.");
}
else if(amount < 0) {
System.out.println("Invalid");
}
else {
balance = balance - amount;
}
}
public double getWithdraw()
{
return 1;
}
}
import java.util.*;
public class Client {
public static void main(String args[])
{
int n = 0;
int count;
String trans;
ArrayList<String> transaction= new ArrayList<String>(n);
Scanner input = new Scanner(System.in);
System.out.println("Welcome to First National Bank");
System.out.println("Please enter your name: ");
String cusName = input.nextLine();
System.out.println("You will now be assigned an account number.");
Random randomGenerator = new Random();
int accNo = randomGenerator.nextInt(100000); //random number
System.out.println("Your account number is: " + accNo);
System.out.println("Please enter your initial account balance: ");
Double balance = input.nextDouble();
BankAccount b1 = new BankAccount(cusName, accNo, balance);
b1.setBalance(balance);
int menu;
/*System.out.println("Menu");
System.out.println("1. Deposit Amount");
System.out.println("2. Withdraw Amount");
System.out.println("3. Display Information");
System.out.println("4. Exit");*/
boolean quit = false;
do {
System.out.println("*******Menu*******");
System.out.println("1. Deposit Amount"); // menu to take input from user
System.out.println("2. Withdraw Amount");
System.out.println("3. Display Information");
System.out.println("4. Exit");
System.out.print("Please enter your choice: ");
menu = input.nextInt();
switch (menu) {
case 1:
System.out.print("Enter depost amount:");
b1.setDeposit(input.nextDouble());
b1.getDeposit();
transaction.add(trans);
break;
case 2:
System.out.println("Current Account Balance=" + b1.getBalance());
System.out.print("Enter withdrawal amount:");
b1.setWithdraw(input.nextDouble());
b1.getWithdraw();
transaction.add(trans);
break;
// switch statments to do a loop
case 3:
b1.display();
break;
case 4:
quit = true;
break;
}
} while (!quit);
}
}
public class Date {
static Date time = new Date();
}