diff --git a/README.md b/README.md deleted file mode 100644 index a974d78..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# JobHacker-System -This repo for JobHacker Community tasks. diff --git a/Week 3/Task 1-Bank System/.gitignore b/Week 3/Task 1-Bank System/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Week 3/Task 1-Bank System/.gitignore @@ -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 \ No newline at end of file diff --git a/Week 3/Task 1-Bank System/.idea/.gitignore b/Week 3/Task 1-Bank System/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Week 3/Task 1-Bank System/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Week 3/Task 1-Bank System/.idea/misc.xml b/Week 3/Task 1-Bank System/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/Week 3/Task 1-Bank System/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 3/Task 1-Bank System/.idea/modules.xml b/Week 3/Task 1-Bank System/.idea/modules.xml new file mode 100644 index 0000000..fd90d6e --- /dev/null +++ b/Week 3/Task 1-Bank System/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Week 3/Task 1-Bank System/.idea/vcs.xml b/Week 3/Task 1-Bank System/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Week 3/Task 1-Bank System/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 3/Task 1-Bank System/Bank System.iml b/Week 3/Task 1-Bank System/Bank System.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Week 3/Task 1-Bank System/Bank System.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Week 3/Task 1-Bank System/README.md b/Week 3/Task 1-Bank System/README.md new file mode 100644 index 0000000..15fc113 --- /dev/null +++ b/Week 3/Task 1-Bank System/README.md @@ -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 +
+ +- 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. \ No newline at end of file diff --git a/Week 3/Task 1-Bank System/src/Account.java b/Week 3/Task 1-Bank System/src/Account.java new file mode 100644 index 0000000..d5ac50f --- /dev/null +++ b/Week 3/Task 1-Bank System/src/Account.java @@ -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"); + } +} \ No newline at end of file diff --git a/Week 3/Task 1-Bank System/src/Bank.java b/Week 3/Task 1-Bank System/src/Bank.java new file mode 100644 index 0000000..cca37d5 --- /dev/null +++ b/Week 3/Task 1-Bank System/src/Bank.java @@ -0,0 +1,31 @@ +import java.util.ArrayList; +public class Bank { + ArrayListaccounts; + 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()); + } +} \ No newline at end of file diff --git a/Week 3/Task 1-Bank System/src/BankApplication.java b/Week 3/Task 1-Bank System/src/BankApplication.java new file mode 100644 index 0000000..1946327 --- /dev/null +++ b/Week 3/Task 1-Bank System/src/BankApplication.java @@ -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(); + } + } +} \ No newline at end of file diff --git a/Week 3/Task 1-Bank System/src/SavingsAccount.java b/Week 3/Task 1-Bank System/src/SavingsAccount.java new file mode 100644 index 0000000..f448074 --- /dev/null +++ b/Week 3/Task 1-Bank System/src/SavingsAccount.java @@ -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); + } +} \ No newline at end of file diff --git a/Week 3/Task 2-problem solving/Check if the Sentence Is Pangram.java b/Week 3/Task 2-problem solving/Check if the Sentence Is Pangram.java new file mode 100644 index 0000000..1a1ad97 --- /dev/null +++ b/Week 3/Task 2-problem solving/Check if the Sentence Is Pangram.java @@ -0,0 +1,32 @@ +import java.util.Hashtable; + +class Solution { + public boolean checkIfPangram(String sentence) { + Hashtable 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; + } +} \ No newline at end of file diff --git a/Week 3/Task 2-problem solving/Longest Common Prefix.java b/Week 3/Task 2-problem solving/Longest Common Prefix.java new file mode 100644 index 0000000..0bf3f57 --- /dev/null +++ b/Week 3/Task 2-problem solving/Longest Common Prefix.java @@ -0,0 +1,15 @@ +class Solution { + public String longestCommonPrefix(String[] strs) { + String result = ""; + + for(int i=0;i= strs[j].length() || c != strs[j].charAt(i)) return result; + + result += c; + } + return result; + } +} \ No newline at end of file diff --git a/Week 3/Task 2-problem solving/Two Sum.java b/Week 3/Task 2-problem solving/Two Sum.java new file mode 100644 index 0000000..abf77bf --- /dev/null +++ b/Week 3/Task 2-problem solving/Two Sum.java @@ -0,0 +1,42 @@ +import java.util.Hashtable; + +// using HashTable +class Solution { + public int[] twoSum(int[] nums, int target) { + Hashtable hashtable = new Hashtable <>(); + + for(int i=0;i< nums.length;i++){ + if(hashtable.containsKey(target - nums[i])){ + int [] indices = {hashtable.get(target - nums[i]),i}; + return indices; + } + hashtable.put(nums[i],i); + } + return new int[0]; + } +} + +// using Two Pointer +class Solution { + public int[] twoSum(int[] nums, int target) { + int n = nums.length; + int []ans = new int[2]; + + int i = 0 , j = i+1; + + while(i c = new Stack<>(); + + if(s.charAt(0)==')' || s.charAt(0)==']' || s.charAt(0)=='}') + return false; + + for(int i=0;i