Question: import java.util.Date; public class TestAccounts { public static void main ( String [ ] args ) { Account obj = new Account ( 1 1

import java.util.Date;
public class TestAccounts {
public static void main(String[] args){
Account obj = new Account(1122,20000);
obj.withdraw(2500);
obj.deposit(3000);
System.out.println("Balance -> : "+ obj.getBalance()+" S.R");
System.out.println("Account was created on -> : "+ obj.getDateCreated());
}
}
class Account {
private int id;
private double balance;
private Date dateCreated;
public Account(){
id =0;
balance =0.0;
dateCreated = null;
}
public Account(int id, double balance){
this.id = id;
this.balance = balance;
this.dateCreated = new Date();
}
public int getId(){
return id;
}
public double getBalance(){
return balance;
}
public void setId(int id){
this.id = id;
}
public void setBalance(double balance){
this.balance = balance;
}
public Date getDateCreated(){
return dateCreated;
}
public void withdraw(double amount){
this.balance -= amount;
}
public void deposit(double amount){
this.balance += amount;
}
}
class SavingAccount extends Account {
}
class CheckingAccount extends Account {
private double overdraftLimit;
public CheckingAccount(int id, double balance, double overdraftLimit){
super(id, balance);
this.overdraftLimit = overdraftLimit;
}
// CheckingAccount specific methods can be added here
@Override
public void withdraw(double amount){
if (balance - amount >=-overdraftLimit){
balance -= amount;
} else {
System.out.println("Withdrawal amount exceeds overdraft limit!");
}
}
@Override
public String toString(){
return "CheckingAccount{"+
"id="+ getId()+
", balance="+ getBalance()+
", dateCreated="+ getDateCreated()+
", overdraftLimit="+ overdraftLimit +
'}';
}
}
( How do I solve this code and can you solve the problems in it? Use Java language )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!