![]() |
![]() |
|
home—info—lects—labs—exams—hws
textbook—tutor/PIs—java.lang docs—java.util docs
Due May.01 (Fri) 17:00, under your professor's door.
class Foo {
private int n = 77;
private static double r = 2.3;
public static final String MOTTO = "Do unto others, before they do unto you.";
}
|
System.out.println( "Start:" );
for (int i=0; i<3; ++i) {
for (int j=0; j<5; ++j) {
System.out.println( "i=" + i + ", j=" + j );
}
System.out.println(""); // A blank line.
}
System.out.println( "Done." );
|
public class BankAccount {
private static int totalAccts = 0;
private int acctNum;
private double balance;
BankAccount( double initBal ) {
this.balance = initBal;
this.acctNum = 100 + totalAccts;
++totalAccts;
}
void deposit( double amt ) {
this.balance += amt;
}
// Other methods omitted...
}
public class BankAccountTester {
public static void main( String[] args ) {
BankAccount b1 = new BankAccount( 500 );
BankAccount b2 = new BankAccount( 600 );
BankAccount b3 = new BankAccount( 700 );
// Location A.
}
}
|
(5pts)
As a promotional offer,
the bank has decided:
if a customer happens to deposit an amount equal to their account number,
then the bank will add an additional $n,
where n is how many customers they have —
that is, n is the number of BankAccounts objects that have been constructed.1
(For example, at Location A,
if $100 is deposited into b0,
then its resulting balance would be $603: $500 + $100 + the bonus $3.)
Your task: Modify deposit so that it uses this promotional scheme.
1
Note that this scheme scales well:
it encourages large deposits,
and it only costs the bank much money if they already have lots of customers.
… Though there is one loophole that could be costly:
a customer might repeatedly deposit-then-withdraw money over and over again,
to repeatedly get the bonus.
Hopefully the bank has other safeguards to discourage people from this
(e.g. by charging a fee for excessive transactions,
or allowing only one promo-bonus per customer per day, etc.).
That's not part of this problem, though.
↩
home—info—lects—labs—exams—hws
textbook—tutor/PIs—java.lang docs—java.util docs
| ©2009, Ian Barland, Radford University Last modified 2009.May.01 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarland |
![]() |