-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoneyTransfer.java
More file actions
38 lines (32 loc) · 1.23 KB
/
Copy pathMoneyTransfer.java
File metadata and controls
38 lines (32 loc) · 1.23 KB
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
package BankAccounts;
import java.util.Scanner;
class MoneyTransfer {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
try {
System.out.print("Enter amount: ");
double amount = sc.nextDouble();
System.out.print("Enter account number: ");
long accountNumber = sc.nextLong();
FinancialTransaction c = new FinancialTransaction();
c.processTransaction(amount, accountNumber);
} catch (java.util.InputMismatchException e) {
System.out.println("Invalid input: Please enter a valid number for transaction amount.");
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
}
class FinancialTransaction {
public void processTransaction(double amount, long accountNumber) {
if (amount <= 0) {
throw new IllegalArgumentException(
"Error processing transaction: Transaction amount must be positive."
);
}
System.out.println(
"Transaction successful: Amount Rs." + amount +
" transferred to account " + accountNumber
);
}
}