Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

29 changes: 29 additions & 0 deletions Week 3/Task 1-Bank System/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
3 changes: 3 additions & 0 deletions Week 3/Task 1-Bank System/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Week 3/Task 1-Bank System/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Week 3/Task 1-Bank System/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Week 3/Task 1-Bank System/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Week 3/Task 1-Bank System/Bank System.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
30 changes: 30 additions & 0 deletions Week 3/Task 1-Bank System/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Task 1

### **To follow the requirements, I assumed the following:**
- The application comprises two distinct views:
1. Customer can access these features:
- Deposit money
- Withdraw money
- View balance
- Calculate Interest

2. Employee can access this feature:
- open a savings account

- I divided the code in main function into sub-functions:
1. home: user can choose the account(Customer or Employee)
2. CaseEmployee: provides employee's feature
3. CaseCustomer: provides customer's features
<br>

- Since the application has two views and no files or database requested, if the customer or employee wants to exit the application, all saved accounts will be removed. When any user wants to exit, the application redirects to the home function again and will not close the application.

- There are no accounts saved so the employee may enter some accounts first.

- The customer cannot access its features before validating the account number.

- The customer has 3 attempts to enter the account number correctly, and if he fails to do so, the application redirects him to the home function.

- If the user selects invalid options from the menu, the application will display a message and redirect to the menu again.

- The application handles invalid data types entered by the user.
36 changes: 36 additions & 0 deletions Week 3/Task 1-Bank System/src/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
public class Account {
private String accountNumber;
private String accountHolderName;
private double balance;

public Account(String accountNumber, String accountHolderName,double balance) {
this.accountNumber = accountNumber;
this.accountHolderName = accountHolderName;
this.balance = balance;
}

public String getAccountNumber() {
return accountNumber;
}

public String getAccountHolderName() {
return accountHolderName;
}

public double getBalance() {
return balance;
}

public void deposit(double amount) {
balance += amount;
}

public void withdraw(double amount) {
if (balance < amount) {
System.out.println("Insufficient balance, your balance: "+ balance +"\nwithdraw less amount!");
return;
}
balance -= amount;
System.out.println("$" + amount + " withdrawn successfully");
}
}
31 changes: 31 additions & 0 deletions Week 3/Task 1-Bank System/src/Bank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.util.ArrayList;
public class Bank {
ArrayList<SavingsAccount>accounts;
Bank(){
accounts = new ArrayList<>();
}
public void addAccount(SavingsAccount account) {
accounts.add(account);
System.out.println("Account added successfully!");
}

public SavingsAccount findAccount(String accountNumber) {
for (SavingsAccount account: accounts)
if (account.getAccountNumber().equals(accountNumber)) return account;
return null;
}

public void deposit(SavingsAccount account, double amount) {
account.deposit(amount);
System.out.println("$" + amount + " deposited successfully");
}

public void withdraw(SavingsAccount account, double amount) {
account.withdraw(amount);
}

public void displayBalance(SavingsAccount account) {
System.out.println("Account holder: " + account.getAccountHolderName());
System.out.println("Account balance: $" + account.getBalance());
}
}
149 changes: 149 additions & 0 deletions Week 3/Task 1-Bank System/src/BankApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import java.util.*;

public class BankApplication {
static Bank bank = new Bank();
static Scanner scanner;
static String accountNumber;
static String accountHolderName;
static double balance , amount;

public static void main(String[] args) {
Home();
}
static void Home(){
scanner = new Scanner(System.in);
System.out.println("---------------------------------------------");
System.out.println("Welcome to The Bank Application!");

try{
while (true) {
System.out.println("---------------------------------------------");
System.out.println("Select an option");
System.out.println("1. Customer");
System.out.println("2. Employee");
System.out.println("---------------------------------------------");
System.out.print("Enter option: ");
int choice = scanner.nextInt();
System.out.println("---------------------------------------------");

switch (choice) {
case 1:
CaseCustomer();
break;
case 2:
CaseEmployee();
break;
default:
System.out.println("!! Enter a Valid Choice !!");
System.out.println("---------------------------------------------");
}
}
} catch (InputMismatchException e){
System.out.println("---------------------------------------------");
System.out.println("You entered invalid input, try again!");
Home();
}
}
static void CaseCustomer() {
scanner = new Scanner(System.in);
try{
System.out.println("Welcome Customer!");
System.out.println("---------------------------------------------");

// The customer has to enter the account number first to be verified and if found, the customer can interact with the application.
// The customer has 3 attempts to verify the account number.
for(int i=0;i<3;i++){
System.out.print("Enter your account number: ");
accountNumber = scanner.next();
SavingsAccount account = bank.findAccount(accountNumber);

if (account == null) {
System.out.println("Account not found, try again!");
continue;
}


while (true) {
System.out.println("---------------------------------------------");
System.out.println("Select an option");
System.out.println("1. Deposit money");
System.out.println("2. Withdraw money");
System.out.println("3. View balance");
System.out.println("4. Calculate Interest");
System.out.println("5. Exit");
System.out.println("---------------------------------------------");
System.out.print("Enter option: ");
int choice = scanner.nextInt();
System.out.println("---------------------------------------------");

switch (choice){
case 1:
System.out.print("Enter deposit amount: ");
amount = scanner.nextDouble();
bank.deposit(account, amount);
break;
case 2:
System.out.print("Enter withdraw amount: ");
amount = scanner.nextDouble();
bank.withdraw(account, amount);
break;
case 3:
bank.displayBalance(account);
break;
case 4:
new SavingsAccount(account.getAccountNumber(),account.getAccountHolderName(),account.getBalance()).calculateInterest();
case 5:
Home();
default:
System.out.println("Enter a valid option");
System.out.println("---------------------------------------------");
}
}
}
System.out.println("You have exceeded the maximum number of attempts, try again later!");
Home();
} catch (InputMismatchException e){
System.out.println("You entered invalid input, try again!");
CaseCustomer();
}
}

static void CaseEmployee() {
scanner = new Scanner(System.in);
try{
System.out.println("Welcome Employee!");

while (true) {
System.out.println("---------------------------------------------");
System.out.println("Select an option");
System.out.println("1. Open a savings account");
System.out.println("2. Exit");
System.out.println("---------------------------------------------");
System.out.print("Enter option: ");
int choice = scanner.nextInt();
System.out.println("---------------------------------------------");

switch (choice){
case 1:
System.out.print("Enter account number: ");
accountNumber = scanner.nextLine();
scanner.nextLine(); // consume newline
System.out.print("Enter account holder name: ");
accountHolderName = scanner.nextLine();
System.out.print("Enter balance: ");
balance = scanner.nextDouble();
bank.addAccount(new SavingsAccount(accountNumber,accountHolderName,balance));
break;
case 2:
Home();
default:
System.out.println("Enter a valid option");
System.out.println("---------------------------------------------");
}
}
} catch (InputMismatchException e){
System.out.println("You entered invalid input, try again!");
CaseEmployee();
}
}
}
11 changes: 11 additions & 0 deletions Week 3/Task 1-Bank System/src/SavingsAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class SavingsAccount extends Account {
private final double interestRate = 0.05; // assume the interest rate = %5

public SavingsAccount(String accountNumber, String accountHolderName, double balance) {
super(accountNumber, accountHolderName, balance);
}

public void calculateInterest() {
System.out.println("The Interest Rate = " + getBalance() * interestRate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.Hashtable;

class Solution {
public boolean checkIfPangram(String sentence) {
Hashtable<Character,Integer> alphabet = new Hashtable<>();

for(int i=0 ;i< sentence.length();i++){
int count = 1;
if (alphabet.containsKey(sentence.charAt(i))) count += alphabet.get(sentence.charAt(i));
alphabet.put(sentence.charAt(i), count);
}

return (alphabet.size() == 26);
}
}

// using frequency array
class Solution {
public boolean checkIfPangram(String sentence) {
int len = sentence.length();
if(len<25) return false;

int[] freqArray = new int[26];
for (int i = 0; i < len; i++)
freqArray[sentence.charAt(i) - 'a']++;

for(int i=0;i<26;i++)
if(freqArray[i]==0) return false;

return true;
}
}
15 changes: 15 additions & 0 deletions Week 3/Task 2-problem solving/Longest Common Prefix.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public String longestCommonPrefix(String[] strs) {
String result = "";

for(int i=0;i<strs[0].length();i++){
char c = strs[0].charAt(i);

for(int j=1;j<strs.length;j++)
if (i >= strs[j].length() || c != strs[j].charAt(i)) return result;

result += c;
}
return result;
}
}
Loading