-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCustomer.java
56 lines (45 loc) · 1.49 KB
/
Customer.java
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
package banking;
public class Customer {
private static int baseNumber = 1000;
private String firstName;
private String lastName;
private int custNumber;
private int numberOfAccounts;
private int currentAccountNumber = 0;
private Account[] accounts;
Customer(String f, String l) {
this.firstName = f;
this.lastName = l;
this.numberOfAccounts = 1;
accounts = new Account[numberOfAccounts];
}
public boolean setAccount(Account newAccount) {
if (currentAccountNumber < numberOfAccounts) {
accounts[currentAccountNumber] = newAccount;
currentAccountNumber++;
return true;
} else {
return false;
}
}
public Account getAccount(int accountNumber) throws Exception {
if (accountNumber < numberOfAccounts) {
return accounts[accountNumber];
} else {
throw new Exception("неправильный номер счета!");
}
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public int getNumOfAccounts () {
return numberOfAccounts;
}
@Override
public String toString() {
return "\n"+ firstName + " " + lastName + "\n===\n номер клиента: " + custNumber + "\n количество счетов: " + numberOfAccounts;
}
}