An account has the properties account number, balance, annual,interest rate, and date created, and methods to deposit and withdraw.Create two sub classes for checkings and savings account.Checkings account has an overdraft limit, but a savings account
cannot be overdrawn.
One problem that i'm having is that when I withdraw x amount of money from the balance, the balance doesn't store it's new value.When i try to deposit x amount of money, the deposit isn't added to the existing balance.
The other issue is that after i withdraw 500 from my balance 1000, the balance is -500.
I look over the setwithDraw() and the calculations seem right. I'm confused of why the balance is negative.
Here is the results that I'm getting.
Balance 1000.0
Withdraw 500.0
Checking balance after withdraw: -500.0
Deposited 300.0
Savings balance after deposit: 300.0
Account class
import java.util.Date;
import javax.swing.JOptionPane;
public class Account
{
int id = 0;
double balance = 0;
double annualInterestRate = 0;
java.util.Date dateCreated = new java.util.Date();
Account()
{
//balance = 1000;
//balance = b;
//annualInterestRate = aI;
//id = i;
//setbalance(b);
//setannualInterestRate(aI);
}
public void setid(int i)
{
id = i;
}
public void setbalance(double b)
{
balance = b;
}
public void setannualInterestRate(double a)
{
annualInterestRate = a;
}
public int getid()
{
return id;
}
public double getbalance()
{
return balance;
}
public double getannualInterestRate()
{
return annualInterestRate;
}
public String dateCreated()
{
String output = "The date created " + dateCreated.toString();
return output;
}
//need to modify
public double getmonthlyInterestRate()
{
return annualInterestRate / 12;
}
public void printInfo()
{
String output = "Customer id: " + getid() +
"\nThe monthly interest rate: " + getmonthlyInterestRate() +
"\nOrginal balance: " + balance +
"\nThe balance: " + getbalance() +
"\n" + dateCreated();
System.out.println(output);
//JOptionPane.showMessageDialog(null, output);
}
}
Checkings class
public class Checkings extends Account
{
double withDraw = 0;
Checkings()//double a
{
//super(a);
//withDraw = w;
//setwithDraw(w);
}
public void setwithDraw(double w)
{
/*if(w > balance)
{
System.out.println("Can't withdraw a value greater " +
" than your balance!");
System.exit(0);
}
else*/
withDraw = w;
balance -= w;
}
public double getwithDraw()
{
return withDraw;
}
public void print()
{
String output = "Withdraw " + withDraw +
"\nChecking balance after withdraw: " + balance;
System.out.println(output);
}
}
Savings Class
public class Savings extends Account
{
double deposit = 0;
Savings()//double s
{
//super(s);
//deposit = s;
//setdeposit(s);
}
public void setdeposit(double d)
{
/*if(d > balance)
{
System.out.println("Can't deposit a value greater than " +
" your balance");
System.exit(0);
}
else*/
deposit = d;
balance += d;
}
public double getdeposit()
{
return deposit;
}
public void print()
{
String output = "Deposited " + deposit +
"\nSavings balance after deposit: " + balance;
System.out.println(output);
}
}
Main class
public class Main
{
public static void main(String[] args)
{
Account a = new Account();
a.setbalance(1000);
Checkings c = new Checkings();
Savings s = new Savings();
System.out.println("Balance " + a.getbalance());
c.setwithDraw(500);
c.print();
System.out.println();
s.setdeposit(300);
s.print();
}
}