Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Algorithmic Trading Navigating The Digital Frontier

Authors: Alex Thompson

1st Edition

B0CHXR6CXX, 979-8223284987

More Books

Students also viewed these Databases questions

Question

Evaluate (r + 2t): f where r = i + 2j and t = j - k and f = i - j.

Answered: 1 week ago

Question

Define Management by exception

Answered: 1 week ago

Question

Explain the importance of staffing in business organisations

Answered: 1 week ago

Question

What are the types of forms of communication ?

Answered: 1 week ago

Question

Explain the process of MBO

Answered: 1 week ago