We want to realize a program for managing credit card accounts. For each account, the following information is stored:
Part 1.
Write a class CCAccount
that implements the following methods:
CCAccount(String owner, String ccn, double me)
:
constructor that creates an object representing a credit card account whose
owner is owner
, whose credit card number is ccn
,
whose maximum allowed expenses is me
, and whose initial
expenses are 0.
String getOwner()
: that returns the name of the owner of
the account;
String getNumber()
: that returns the credit card number
for the account;
double getMaxExpenses()
: that returns the maximum allowed
expenses for the credit card account;
double getExpenses()
: that returns the current expenses for
the credit card account;
double spend(double a)
: if the amount of
Euro a
does not exceed the remaining allowed expenses (which
are calculated as the difference between the maximum allowed expenses and
the current expenses), then a
is added to the current
expenses, and the new remaining allowed expenses are returned. Otherwise
the credit card account is not changed, and -1 is returned;
double payBack()
: that sets the current expenses to 0, and
returns the current expenses (before they were set to 0);
String toString()
: that returns a string with all the
information about the credit card account.
Example program:
TestCCAccount.Java
Part 2.
Write a class UseCCAccount
, client of CCAccount
, that
contains the following public static method:
static double getMinRemainingExpenses(CCAccount a1, CCAccount
a2)
: that, given two credit card accounts a1
and a2
, returns the minimum among the remaining expenses
of a1
and a2
that is different from 0. More
precisely,
Example program:
TestUseCCAccount.java
Solutions:
CCAccount.java
,
UseCCAccount.java