We want to realize a program for managing the accounts of clients of a bank. For each account, the following information is stored:
Part 1.
Write a class Account
that implements the following methods:
Account(String o, double p)
: constructor that creates an
object representing a bank account whose owner is o
, whose
penalty is p
, whose initial balance is 0, and whose initial
number of performed operations is 0.
String getOwner()
: that returns the name of the owner of
the bank account;
double getPenalty()
: that returns the penalty of the bank
account;
double getBalance()
: that returns the balance of the bank
account;
int getNumOp()
: that returns the number of operations
performed on the bank account;
void deposit(double a)
: that deposits the amount of
money a
on the bank account, and increments the number of
operations by 1;
void withdraw(double a)
: that withdraws the amount of
money a
from the bank account, and increments the number of
operations by 1; if after the withdrawal the balance is negative (either
because it becomes negative, or because it already was negative), an
additional amount equal to the penalty is subtracted from the balance;
String toString()
: that returns a string with all the
information about the bank account.
Example program:
TestAccount.Java
Part 2.
Write a class UseAccount
, client of Account
, that
contains the following public static method:
static double getMinPositiveBalance(Account a1, Account a2)
: that, given two accounts a1
and a2
, returns the
minimum positive balance of a1
and a2
. More
precisely,
Example program:
TestUseAccount.java
Solutions:
Account.java
,
UseAccount.java