-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment1p3.java
More file actions
45 lines (40 loc) · 1.44 KB
/
Assignment1p3.java
File metadata and controls
45 lines (40 loc) · 1.44 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
39
40
41
42
43
44
45
import java.util.Scanner;
class BankAccount {
private String name;
private String accountNumber;
private double balance;
public BankAccount(String name, String accountNumber, double balance) {
this.name = name;
this.accountNumber = accountNumber;
this.balance = balance;
}
public void deposit(double amount) {
balance += amount;
System.out.println("Deposit successful! Current Balance: " + balance);
}
public void withdraw(double amount) {
if (amount > balance) {
System.out.println("Error: Insufficient funds. Current Balance: " + balance);
} else {
balance -= amount;
System.out.println("Withdrawal successful! Current Balance: " + balance);
}
}
}
public class Assignment1p3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Create Account:");
System.out.print("Name: ");
String name = sc.nextLine();
System.out.print("Account Number: ");
String accountNumber = sc.nextLine();
System.out.print("Initial Balance: ");
double initialBalance = sc.nextDouble();
BankAccount account = new BankAccount(name, accountNumber, initialBalance);
System.out.print("Deposit: ");
account.deposit(sc.nextDouble());
System.out.print("Withdraw: ");
account.withdraw(sc.nextDouble());
}
}