-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPESADemo.java
More file actions
35 lines (30 loc) · 1.2 KB
/
MPESADemo.java
File metadata and controls
35 lines (30 loc) · 1.2 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
class MPESAAccount {
// Fields (attributes)
String accountHolderName;
String phoneNumber;
double balance;
// Constructor to effectively initialize the MPESA account
public MPESAAccount(String name, String number, double initialBalance) {
accountHolderName = name;
phoneNumber = number;
balance = initialBalance;
}
// Method to display balance
public void checkBalance() {
System.out.println("Account Holder: " + accountHolderName);
System.out.println("Phone Number: " + phoneNumber);
System.out.println("Current Balance: KES " + balance);
}
}
public class MPESADemo {
public static void main(String[] args) {
// Creating objects for MPESA accounts
MPESAAccount johnAccount = new MPESAAccount("John Doe", "0700000001", 5000.00);
MPESAAccount maryAccount = new MPESAAccount("Mary Jane", "0700000002", 3000.00);
// Check balance for both accounts
System.out.println("John's Account Details:");
johnAccount.checkBalance(); // Accessing method using object
System.out.println("\nMary's Account Details:");
maryAccount.checkBalance(); // Accessing method using object
}
}