Skip to content

Commit 0b06172

Browse files
committed
A simple program that implements the use of class,object and constructors
1 parent 0b08948 commit 0b06172

13 files changed

+104
-0
lines changed

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/OOP.iml

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MPESADemo.java

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class MPESAAccount {
2+
// Fields (attributes)
3+
String accountHolderName;
4+
String phoneNumber;
5+
double balance;
6+
7+
// Constructor to initialize the MPESA account
8+
public MPESAAccount(String name, String number, double initialBalance) {
9+
accountHolderName = name;
10+
phoneNumber = number;
11+
balance = initialBalance;
12+
}
13+
14+
// Method to display balance
15+
public void checkBalance() {
16+
System.out.println("Account Holder: " + accountHolderName);
17+
System.out.println("Phone Number: " + phoneNumber);
18+
System.out.println("Current Balance: KES " + balance);
19+
}
20+
}
21+
22+
public class MPESADemo {
23+
public static void main(String[] args) {
24+
// Creating objects for MPESA accounts
25+
MPESAAccount johnAccount = new MPESAAccount("John Doe", "0700000001", 5000.00);
26+
MPESAAccount maryAccount = new MPESAAccount("Mary Jane", "0700000002", 3000.00);
27+
28+
// Check balance for both accounts
29+
System.out.println("John's Account Details:");
30+
johnAccount.checkBalance(); // Accessing method using object
31+
32+
System.out.println("\nMary's Account Details:");
33+
maryAccount.checkBalance(); // Accessing method using object
34+
}
35+
}

out/production/OOP/.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/production/OOP/.idea/OOP.iml

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/production/OOP/.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/production/OOP/.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/production/OOP/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/production/OOP/MPESAAccount.class

1.31 KB
Binary file not shown.

out/production/OOP/MPESADemo.class

878 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)