Spaces:
Running
Running
File size: 1,450 Bytes
89c5012 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
In the program, the class BankAccount is defined.
Define the following attributes for the class:
String-type accountNumber and owner
double type balance and interest
import java.util.Random;
public class Test{
public static void main(String[] args){
final Random r = new Random();
System.out.println("Testing bank account creation...");
BankAccount pt = new BankAccount("1234-567","Randy Rich", 1000000000, 10.5);
BankAccount pt2 = new BankAccount("555-444","Pat Poor", 7.50, 0.5);
System.out.println("Bank account 1: " + pt);
System.out.println("Bank account 2: " + pt2);
}
}
class BankAccount {
// ADD ATTRIBUTES HERE
String accountNumber;
String owner;
double balance;
double interest;
// CONSTRUCTOR
public BankAccount(String tn, String o, double s, double k) {
accountNumber = tn;
owner = o;
balance = s;
interest = k;
}
@Override
public String toString() {
return "Bank account [account number=" + accountNumber + ", owner=" + owner + ", balance=" + balance + ", interest="
+ interest + "]";
}
}
Testing bank account creation...
Bank account 1: Bank account [account number=1234-567, owner=Randy Rich, balance=1.0E9, interest=10.5]
Bank account 2: Bank account [account number=555-444, owner=Pat Poor, balance=7.5, interest=0.5]
|