Account details Java Program
Get the Annual Interest Rate, Calculating Balance saving Details by complete date and time.
Java Code:
public class account {
private int aNumber;
private double balance;
private double annualInterestRate;
private java.util.Date dateCreated;
public account() {
dateCreated = new java.util.Date();
}
public account(int aNumber, double balance, double annualInterestRate){
this.aNumber = aNumber;
this.balance = balance;
this.annualInterestRate =
annualInterestRate;
dateCreated = new java.util.Date();
}
public int getAnumber(){
return aNumber;
}
public void setId(int aNumber){
this.aNumber = aNumber;
}
public void setBalance(double balance){
this.balance = balance;
}
public double getBalance(){
return balance;
}
public double
getAnnualInterestRate(){
return annualInterestRate;
}
public void
setAnnualInterestRate(double annualInterestRate){
if(annualInterestRate<=0){
this.annualInterestRate=0;
System.out.printf("change value to 0");
}
else{
this.annualInterestRate =
annualInterestRate;
}}
public double
getMonthlyInterest(){
return balance * (annualInterestRate / 1200);
}
public java.util.Date getDateCreated(){
return dateCreated;
}
public void withdraw(double amount){
if(amount<=0){
amount=0;
System.out.printf("change value to 0");
}
else
balance -= amount;
}
public void deposit(double amount){
if(amount<=0){
amount=0;
System.out.printf("change value to 0");
}
else
balance += amount;
}
}
public class main {
public static void main (String[]
args) {
account account = new account(5678, 30000, 1.5);
System.out.println(account.getAnumber());
System.out.println(account.getBalance());
System.out.println(account.getAnnualInterestRate());
System.out.println(account.getDateCreated());
account.withdraw(3500);
account.deposit(4000);
System.out.println(account.getAnumber());
System.out.println(account.getBalance());
System.out.println(account.getMonthlyInterest());
System.out.println(account.getDateCreated());
account.setAnnualInterestRate(3);
System.out.println(account.getAnumber());
System.out.println(account.getBalance());
System.out.println(account.getMonthlyInterest());
System.out.println(account.getDateCreated());
account.setAnnualInterestRate(-9);
System.out.println(account.getAnumber());
System.out.println(account.getBalance());
System.out.println(account.getMonthlyInterest());
System.out.println(account.getDateCreated());
account.deposit(-5000);
System.out.println(account.getAnumber());
System.out.println(account.getBalance());
System.out.println(account.getMonthlyInterest());
System.out.println(account.getDateCreated());
}
}
No comments:
Post a Comment