Hi All
I'm new to java. I am currently creating an account class and I am having a problem with the date format. How can I get the date and time to appear as year , month , day , time. The code is below
Code:import java.util.Calendar;
public class Account2
{
public int accountId;
protected double balance;
public int annualInterestRate;
Calendar c = Calendar.getInstance ();
// Constructor to initialize balance
public Account2( int accountNumber,double amount, int interestRate, Calendar dateCreated )
{
accountId = accountNumber;
balance = amount;
annualInterestRate = interestRate;
c.set(2010,2,7,12,01);
}
// Overloaded constructor for empty balance
public Account2()
{
balance = 0.0;
}
public void deposit( double amount )
{
balance += amount;
}
public double withdraw( double amount )
{
// See if amount can be withdrawn
if (balance >= amount)
{
balance -= amount;
return amount;
}
else
// Withdrawal not allowed
return 0.0;
}
public double getbalance()
{
return balance;
}
public int getaccountId ()
{
return accountId;
}
public double getMonthlyInterestRate() {
return annualInterestRate;
}
public Calendar getc (){
return c;}
}
/*
*
*
* Demonstration of Account2 class
*
*/
class AccountDemo
{
public static void main(String args[])
{
// Create an empty account
Account2 my_account = new Account2();
my_account.accountId = 1122;
my_account.balance = 20000;
my_account.c.set (2010,02,15,10,40) ;
// Deposit money
my_account.deposit(3000.00);
// Print current balance
System.out.println ("Current balance " +
my_account.getbalance());
// Withdraw money
my_account.withdraw(2500.00);
// Print remaining balance
System.out.println ("Remaining balance " +
my_account.getbalance());
// Print remaining balance
System.out.println ("Your account was created on" +
my_account.getc());
}
}
