From c7ff587c3223370367e7e2b22edf82cb470bfc6a Mon Sep 17 00:00:00 2001 From: Amira20208045 Date: Mon, 17 Apr 2023 08:40:24 +0200 Subject: [PATCH 1/5] Task 1 added --- Bank System/.gitignore | 29 ++++++ Bank System/.idea/.gitignore | 3 + Bank System/.idea/misc.xml | 6 ++ Bank System/.idea/modules.xml | 8 ++ Bank System/.idea/vcs.xml | 6 ++ Bank System/Bank System.iml | 11 ++ Bank System/README.md | 30 ++++++ Bank System/src/Account.java | 36 +++++++ Bank System/src/Bank.java | 30 ++++++ Bank System/src/BankApplication.java | 148 +++++++++++++++++++++++++++ Bank System/src/SavingsAccount.java | 11 ++ README.md | 2 - 12 files changed, 318 insertions(+), 2 deletions(-) create mode 100644 Bank System/.gitignore create mode 100644 Bank System/.idea/.gitignore create mode 100644 Bank System/.idea/misc.xml create mode 100644 Bank System/.idea/modules.xml create mode 100644 Bank System/.idea/vcs.xml create mode 100644 Bank System/Bank System.iml create mode 100644 Bank System/README.md create mode 100644 Bank System/src/Account.java create mode 100644 Bank System/src/Bank.java create mode 100644 Bank System/src/BankApplication.java create mode 100644 Bank System/src/SavingsAccount.java delete mode 100644 README.md diff --git a/Bank System/.gitignore b/Bank System/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/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/Bank System/.idea/.gitignore b/Bank System/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Bank System/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Bank System/.idea/misc.xml b/Bank System/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/Bank System/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Bank System/.idea/modules.xml b/Bank System/.idea/modules.xml new file mode 100644 index 0000000..fd90d6e --- /dev/null +++ b/Bank System/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Bank System/.idea/vcs.xml b/Bank System/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Bank System/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Bank System/Bank System.iml b/Bank System/Bank System.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Bank System/Bank System.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Bank System/README.md b/Bank System/README.md new file mode 100644 index 0000000..15fc113 --- /dev/null +++ b/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/Bank System/src/Account.java b/Bank System/src/Account.java new file mode 100644 index 0000000..4373a79 --- /dev/null +++ b/Bank System/src/Account.java @@ -0,0 +1,36 @@ +public class Account { + private long accountNumber; + private String accountHolderName; + private double balance; + + public Account(long accountNumber, String accountHolderName,double balance) { + this.accountNumber = accountNumber; + this.accountHolderName = accountHolderName; + this.balance = balance; + } + + public long 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/Bank System/src/Bank.java b/Bank System/src/Bank.java new file mode 100644 index 0000000..4d089df --- /dev/null +++ b/Bank System/src/Bank.java @@ -0,0 +1,30 @@ +import java.util.ArrayList; +public class Bank { + ArrayListaccounts = new ArrayList<>(); + Bank(){ + } + public void addAccount(SavingsAccount account) { + accounts.add(account); + System.out.println("Account added successfully!"); + } + + public SavingsAccount findAccount(long accountNumber) { + for (SavingsAccount account: accounts) + if (account.getAccountNumber() == 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/Bank System/src/BankApplication.java b/Bank System/src/BankApplication.java new file mode 100644 index 0000000..686dc93 --- /dev/null +++ b/Bank System/src/BankApplication.java @@ -0,0 +1,148 @@ +import java.util.*; + +public class BankApplication { + static Bank bank = new Bank(); + static Scanner scanner; + static long 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.nextLong(); + 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.nextLong(); + 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/Bank System/src/SavingsAccount.java b/Bank System/src/SavingsAccount.java new file mode 100644 index 0000000..60ddf87 --- /dev/null +++ b/Bank System/src/SavingsAccount.java @@ -0,0 +1,11 @@ +public class SavingsAccount extends Account { + private double interestRate = 0.05; // assume the interest rate = %5 + + public SavingsAccount(long 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/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. From 0718e5dfe446dbd98f24a858c368850f1309d338 Mon Sep 17 00:00:00 2001 From: Amira20208045 Date: Mon, 17 Apr 2023 11:12:21 +0200 Subject: [PATCH 2/5] task 2 added --- .../.gitignore | 0 .../.idea/.gitignore | 0 .../.idea/misc.xml | 0 .../.idea/modules.xml | 0 .../.idea/vcs.xml | 0 .../Bank System.iml | 0 {Bank System => Task 1-Bank System}/README.md | 0 .../src/Account.java | 0 .../src/Bank.java | 0 .../src/BankApplication.java | 0 .../src/SavingsAccount.java | 0 .../Check if the Sentence Is Pangram.java | 15 ++++++++ .../Longest Common Prefix.java | 15 ++++++++ Task 2-problem solving/Two Sum.java | 16 +++++++++ Task 2-problem solving/Valid Parentheses.java | 36 +++++++++++++++++++ 15 files changed, 82 insertions(+) rename {Bank System => Task 1-Bank System}/.gitignore (100%) rename {Bank System => Task 1-Bank System}/.idea/.gitignore (100%) rename {Bank System => Task 1-Bank System}/.idea/misc.xml (100%) rename {Bank System => Task 1-Bank System}/.idea/modules.xml (100%) rename {Bank System => Task 1-Bank System}/.idea/vcs.xml (100%) rename {Bank System => Task 1-Bank System}/Bank System.iml (100%) rename {Bank System => Task 1-Bank System}/README.md (100%) rename {Bank System => Task 1-Bank System}/src/Account.java (100%) rename {Bank System => Task 1-Bank System}/src/Bank.java (100%) rename {Bank System => Task 1-Bank System}/src/BankApplication.java (100%) rename {Bank System => Task 1-Bank System}/src/SavingsAccount.java (100%) create mode 100644 Task 2-problem solving/Check if the Sentence Is Pangram.java create mode 100644 Task 2-problem solving/Longest Common Prefix.java create mode 100644 Task 2-problem solving/Two Sum.java create mode 100644 Task 2-problem solving/Valid Parentheses.java diff --git a/Bank System/.gitignore b/Task 1-Bank System/.gitignore similarity index 100% rename from Bank System/.gitignore rename to Task 1-Bank System/.gitignore diff --git a/Bank System/.idea/.gitignore b/Task 1-Bank System/.idea/.gitignore similarity index 100% rename from Bank System/.idea/.gitignore rename to Task 1-Bank System/.idea/.gitignore diff --git a/Bank System/.idea/misc.xml b/Task 1-Bank System/.idea/misc.xml similarity index 100% rename from Bank System/.idea/misc.xml rename to Task 1-Bank System/.idea/misc.xml diff --git a/Bank System/.idea/modules.xml b/Task 1-Bank System/.idea/modules.xml similarity index 100% rename from Bank System/.idea/modules.xml rename to Task 1-Bank System/.idea/modules.xml diff --git a/Bank System/.idea/vcs.xml b/Task 1-Bank System/.idea/vcs.xml similarity index 100% rename from Bank System/.idea/vcs.xml rename to Task 1-Bank System/.idea/vcs.xml diff --git a/Bank System/Bank System.iml b/Task 1-Bank System/Bank System.iml similarity index 100% rename from Bank System/Bank System.iml rename to Task 1-Bank System/Bank System.iml diff --git a/Bank System/README.md b/Task 1-Bank System/README.md similarity index 100% rename from Bank System/README.md rename to Task 1-Bank System/README.md diff --git a/Bank System/src/Account.java b/Task 1-Bank System/src/Account.java similarity index 100% rename from Bank System/src/Account.java rename to Task 1-Bank System/src/Account.java diff --git a/Bank System/src/Bank.java b/Task 1-Bank System/src/Bank.java similarity index 100% rename from Bank System/src/Bank.java rename to Task 1-Bank System/src/Bank.java diff --git a/Bank System/src/BankApplication.java b/Task 1-Bank System/src/BankApplication.java similarity index 100% rename from Bank System/src/BankApplication.java rename to Task 1-Bank System/src/BankApplication.java diff --git a/Bank System/src/SavingsAccount.java b/Task 1-Bank System/src/SavingsAccount.java similarity index 100% rename from Bank System/src/SavingsAccount.java rename to Task 1-Bank System/src/SavingsAccount.java diff --git a/Task 2-problem solving/Check if the Sentence Is Pangram.java b/Task 2-problem solving/Check if the Sentence Is Pangram.java new file mode 100644 index 0000000..105ed81 --- /dev/null +++ b/Task 2-problem solving/Check if the Sentence Is Pangram.java @@ -0,0 +1,15 @@ +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); + } +} \ No newline at end of file diff --git a/Task 2-problem solving/Longest Common Prefix.java b/Task 2-problem solving/Longest Common Prefix.java new file mode 100644 index 0000000..0bf3f57 --- /dev/null +++ b/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/Task 2-problem solving/Two Sum.java b/Task 2-problem solving/Two Sum.java new file mode 100644 index 0000000..b9dcaee --- /dev/null +++ b/Task 2-problem solving/Two Sum.java @@ -0,0 +1,16 @@ +import java.util.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]; + } +} \ No newline at end of file diff --git a/Task 2-problem solving/Valid Parentheses.java b/Task 2-problem solving/Valid Parentheses.java new file mode 100644 index 0000000..f1ac8f8 --- /dev/null +++ b/Task 2-problem solving/Valid Parentheses.java @@ -0,0 +1,36 @@ +class Solution { + public boolean isValid(String s) { + Stack c = new Stack<>(); + + if(s.charAt(0)==')' || s.charAt(0)==']' || s.charAt(0)=='}') + return false; + + for(int i=0;i Date: Sun, 6 Aug 2023 00:58:28 +0300 Subject: [PATCH 3/5] changes requested done --- Task 1-Bank System/src/Account.java | 6 +-- Task 1-Bank System/src/Bank.java | 7 +-- Task 1-Bank System/src/BankApplication.java | 7 +-- Task 1-Bank System/src/SavingsAccount.java | 4 +- Task 2-problem solving/.idea/misc.xml | 6 +++ Task 2-problem solving/.idea/modules.xml | 8 ++++ Task 2-problem solving/.idea/vcs.xml | 6 +++ Task 2-problem solving/.idea/workspace.xml | 45 +++++++++++++++++++ .../Check if the Sentence Is Pangram.java | 17 +++++++ .../Task 2-problem solving.iml | 11 +++++ Task 2-problem solving/Two Sum.java | 26 +++++++++++ 11 files changed, 132 insertions(+), 11 deletions(-) create mode 100644 Task 2-problem solving/.idea/misc.xml create mode 100644 Task 2-problem solving/.idea/modules.xml create mode 100644 Task 2-problem solving/.idea/vcs.xml create mode 100644 Task 2-problem solving/.idea/workspace.xml create mode 100644 Task 2-problem solving/Task 2-problem solving.iml diff --git a/Task 1-Bank System/src/Account.java b/Task 1-Bank System/src/Account.java index 4373a79..d5ac50f 100644 --- a/Task 1-Bank System/src/Account.java +++ b/Task 1-Bank System/src/Account.java @@ -1,15 +1,15 @@ public class Account { - private long accountNumber; + private String accountNumber; private String accountHolderName; private double balance; - public Account(long accountNumber, String accountHolderName,double balance) { + public Account(String accountNumber, String accountHolderName,double balance) { this.accountNumber = accountNumber; this.accountHolderName = accountHolderName; this.balance = balance; } - public long getAccountNumber() { + public String getAccountNumber() { return accountNumber; } diff --git a/Task 1-Bank System/src/Bank.java b/Task 1-Bank System/src/Bank.java index 4d089df..cca37d5 100644 --- a/Task 1-Bank System/src/Bank.java +++ b/Task 1-Bank System/src/Bank.java @@ -1,16 +1,17 @@ import java.util.ArrayList; public class Bank { - ArrayListaccounts = new ArrayList<>(); + ArrayListaccounts; Bank(){ + accounts = new ArrayList<>(); } public void addAccount(SavingsAccount account) { accounts.add(account); System.out.println("Account added successfully!"); } - public SavingsAccount findAccount(long accountNumber) { + public SavingsAccount findAccount(String accountNumber) { for (SavingsAccount account: accounts) - if (account.getAccountNumber() == accountNumber) return account; + if (account.getAccountNumber().equals(accountNumber)) return account; return null; } diff --git a/Task 1-Bank System/src/BankApplication.java b/Task 1-Bank System/src/BankApplication.java index 686dc93..1946327 100644 --- a/Task 1-Bank System/src/BankApplication.java +++ b/Task 1-Bank System/src/BankApplication.java @@ -3,7 +3,7 @@ public class BankApplication { static Bank bank = new Bank(); static Scanner scanner; - static long accountNumber; + static String accountNumber; static String accountHolderName; static double balance , amount; @@ -54,7 +54,7 @@ static void CaseCustomer() { // 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.nextLong(); + accountNumber = scanner.next(); SavingsAccount account = bank.findAccount(accountNumber); if (account == null) { @@ -62,6 +62,7 @@ static void CaseCustomer() { continue; } + while (true) { System.out.println("---------------------------------------------"); System.out.println("Select an option"); @@ -125,7 +126,7 @@ static void CaseEmployee() { switch (choice){ case 1: System.out.print("Enter account number: "); - accountNumber = scanner.nextLong(); + accountNumber = scanner.nextLine(); scanner.nextLine(); // consume newline System.out.print("Enter account holder name: "); accountHolderName = scanner.nextLine(); diff --git a/Task 1-Bank System/src/SavingsAccount.java b/Task 1-Bank System/src/SavingsAccount.java index 60ddf87..f448074 100644 --- a/Task 1-Bank System/src/SavingsAccount.java +++ b/Task 1-Bank System/src/SavingsAccount.java @@ -1,7 +1,7 @@ public class SavingsAccount extends Account { - private double interestRate = 0.05; // assume the interest rate = %5 + private final double interestRate = 0.05; // assume the interest rate = %5 - public SavingsAccount(long accountNumber, String accountHolderName, double balance) { + public SavingsAccount(String accountNumber, String accountHolderName, double balance) { super(accountNumber, accountHolderName, balance); } diff --git a/Task 2-problem solving/.idea/misc.xml b/Task 2-problem solving/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /dev/null +++ b/Task 2-problem solving/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Task 2-problem solving/.idea/modules.xml b/Task 2-problem solving/.idea/modules.xml new file mode 100644 index 0000000..d67fb34 --- /dev/null +++ b/Task 2-problem solving/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Task 2-problem solving/.idea/vcs.xml b/Task 2-problem solving/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Task 2-problem solving/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Task 2-problem solving/.idea/workspace.xml b/Task 2-problem solving/.idea/workspace.xml new file mode 100644 index 0000000..b1bd908 --- /dev/null +++ b/Task 2-problem solving/.idea/workspace.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + 1691269709813 + + + + \ No newline at end of file diff --git a/Task 2-problem solving/Check if the Sentence Is Pangram.java b/Task 2-problem solving/Check if the Sentence Is Pangram.java index 105ed81..1a1ad97 100644 --- a/Task 2-problem solving/Check if the Sentence Is Pangram.java +++ b/Task 2-problem solving/Check if the Sentence Is Pangram.java @@ -12,4 +12,21 @@ public boolean checkIfPangram(String sentence) { 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/Task 2-problem solving/Task 2-problem solving.iml b/Task 2-problem solving/Task 2-problem solving.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/Task 2-problem solving/Task 2-problem solving.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Task 2-problem solving/Two Sum.java b/Task 2-problem solving/Two Sum.java index b9dcaee..abf77bf 100644 --- a/Task 2-problem solving/Two Sum.java +++ b/Task 2-problem solving/Two Sum.java @@ -1,5 +1,6 @@ import java.util.Hashtable; +// using HashTable class Solution { public int[] twoSum(int[] nums, int target) { Hashtable hashtable = new Hashtable <>(); @@ -12,5 +13,30 @@ public int[] twoSum(int[] nums, int target) { 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 Date: Sun, 6 Aug 2023 00:59:55 +0300 Subject: [PATCH 4/5] changes requested done --- Task 2-problem solving/.idea/misc.xml | 6 --- Task 2-problem solving/.idea/modules.xml | 8 ---- Task 2-problem solving/.idea/vcs.xml | 6 --- Task 2-problem solving/.idea/workspace.xml | 45 ------------------- .../Task 2-problem solving.iml | 11 ----- 5 files changed, 76 deletions(-) delete mode 100644 Task 2-problem solving/.idea/misc.xml delete mode 100644 Task 2-problem solving/.idea/modules.xml delete mode 100644 Task 2-problem solving/.idea/vcs.xml delete mode 100644 Task 2-problem solving/.idea/workspace.xml delete mode 100644 Task 2-problem solving/Task 2-problem solving.iml diff --git a/Task 2-problem solving/.idea/misc.xml b/Task 2-problem solving/.idea/misc.xml deleted file mode 100644 index 639900d..0000000 --- a/Task 2-problem solving/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Task 2-problem solving/.idea/modules.xml b/Task 2-problem solving/.idea/modules.xml deleted file mode 100644 index d67fb34..0000000 --- a/Task 2-problem solving/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Task 2-problem solving/.idea/vcs.xml b/Task 2-problem solving/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/Task 2-problem solving/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Task 2-problem solving/.idea/workspace.xml b/Task 2-problem solving/.idea/workspace.xml deleted file mode 100644 index b1bd908..0000000 --- a/Task 2-problem solving/.idea/workspace.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - 1691269709813 - - - - \ No newline at end of file diff --git a/Task 2-problem solving/Task 2-problem solving.iml b/Task 2-problem solving/Task 2-problem solving.iml deleted file mode 100644 index b107a2d..0000000 --- a/Task 2-problem solving/Task 2-problem solving.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file From 33bd73904176160b901b1e5ff0972559991e8449 Mon Sep 17 00:00:00 2001 From: amira921 Date: Fri, 11 Aug 2023 18:43:13 +0300 Subject: [PATCH 5/5] group in one folder --- {Task 1-Bank System => Week 3/Task 1-Bank System}/.gitignore | 0 .../Task 1-Bank System}/.idea/.gitignore | 0 {Task 1-Bank System => Week 3/Task 1-Bank System}/.idea/misc.xml | 0 .../Task 1-Bank System}/.idea/modules.xml | 0 {Task 1-Bank System => Week 3/Task 1-Bank System}/.idea/vcs.xml | 0 {Task 1-Bank System => Week 3/Task 1-Bank System}/Bank System.iml | 0 {Task 1-Bank System => Week 3/Task 1-Bank System}/README.md | 0 .../Task 1-Bank System}/src/Account.java | 0 {Task 1-Bank System => Week 3/Task 1-Bank System}/src/Bank.java | 0 .../Task 1-Bank System}/src/BankApplication.java | 0 .../Task 1-Bank System}/src/SavingsAccount.java | 0 .../Task 2-problem solving}/Check if the Sentence Is Pangram.java | 0 .../Task 2-problem solving}/Longest Common Prefix.java | 0 .../Task 2-problem solving}/Two Sum.java | 0 .../Task 2-problem solving}/Valid Parentheses.java | 0 15 files changed, 0 insertions(+), 0 deletions(-) rename {Task 1-Bank System => Week 3/Task 1-Bank System}/.gitignore (100%) rename {Task 1-Bank System => Week 3/Task 1-Bank System}/.idea/.gitignore (100%) rename {Task 1-Bank System => Week 3/Task 1-Bank System}/.idea/misc.xml (100%) rename {Task 1-Bank System => Week 3/Task 1-Bank System}/.idea/modules.xml (100%) rename {Task 1-Bank System => Week 3/Task 1-Bank System}/.idea/vcs.xml (100%) rename {Task 1-Bank System => Week 3/Task 1-Bank System}/Bank System.iml (100%) rename {Task 1-Bank System => Week 3/Task 1-Bank System}/README.md (100%) rename {Task 1-Bank System => Week 3/Task 1-Bank System}/src/Account.java (100%) rename {Task 1-Bank System => Week 3/Task 1-Bank System}/src/Bank.java (100%) rename {Task 1-Bank System => Week 3/Task 1-Bank System}/src/BankApplication.java (100%) rename {Task 1-Bank System => Week 3/Task 1-Bank System}/src/SavingsAccount.java (100%) rename {Task 2-problem solving => Week 3/Task 2-problem solving}/Check if the Sentence Is Pangram.java (100%) rename {Task 2-problem solving => Week 3/Task 2-problem solving}/Longest Common Prefix.java (100%) rename {Task 2-problem solving => Week 3/Task 2-problem solving}/Two Sum.java (100%) rename {Task 2-problem solving => Week 3/Task 2-problem solving}/Valid Parentheses.java (100%) diff --git a/Task 1-Bank System/.gitignore b/Week 3/Task 1-Bank System/.gitignore similarity index 100% rename from Task 1-Bank System/.gitignore rename to Week 3/Task 1-Bank System/.gitignore diff --git a/Task 1-Bank System/.idea/.gitignore b/Week 3/Task 1-Bank System/.idea/.gitignore similarity index 100% rename from Task 1-Bank System/.idea/.gitignore rename to Week 3/Task 1-Bank System/.idea/.gitignore diff --git a/Task 1-Bank System/.idea/misc.xml b/Week 3/Task 1-Bank System/.idea/misc.xml similarity index 100% rename from Task 1-Bank System/.idea/misc.xml rename to Week 3/Task 1-Bank System/.idea/misc.xml diff --git a/Task 1-Bank System/.idea/modules.xml b/Week 3/Task 1-Bank System/.idea/modules.xml similarity index 100% rename from Task 1-Bank System/.idea/modules.xml rename to Week 3/Task 1-Bank System/.idea/modules.xml diff --git a/Task 1-Bank System/.idea/vcs.xml b/Week 3/Task 1-Bank System/.idea/vcs.xml similarity index 100% rename from Task 1-Bank System/.idea/vcs.xml rename to Week 3/Task 1-Bank System/.idea/vcs.xml diff --git a/Task 1-Bank System/Bank System.iml b/Week 3/Task 1-Bank System/Bank System.iml similarity index 100% rename from Task 1-Bank System/Bank System.iml rename to Week 3/Task 1-Bank System/Bank System.iml diff --git a/Task 1-Bank System/README.md b/Week 3/Task 1-Bank System/README.md similarity index 100% rename from Task 1-Bank System/README.md rename to Week 3/Task 1-Bank System/README.md diff --git a/Task 1-Bank System/src/Account.java b/Week 3/Task 1-Bank System/src/Account.java similarity index 100% rename from Task 1-Bank System/src/Account.java rename to Week 3/Task 1-Bank System/src/Account.java diff --git a/Task 1-Bank System/src/Bank.java b/Week 3/Task 1-Bank System/src/Bank.java similarity index 100% rename from Task 1-Bank System/src/Bank.java rename to Week 3/Task 1-Bank System/src/Bank.java diff --git a/Task 1-Bank System/src/BankApplication.java b/Week 3/Task 1-Bank System/src/BankApplication.java similarity index 100% rename from Task 1-Bank System/src/BankApplication.java rename to Week 3/Task 1-Bank System/src/BankApplication.java diff --git a/Task 1-Bank System/src/SavingsAccount.java b/Week 3/Task 1-Bank System/src/SavingsAccount.java similarity index 100% rename from Task 1-Bank System/src/SavingsAccount.java rename to Week 3/Task 1-Bank System/src/SavingsAccount.java diff --git a/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 similarity index 100% rename from Task 2-problem solving/Check if the Sentence Is Pangram.java rename to Week 3/Task 2-problem solving/Check if the Sentence Is Pangram.java diff --git a/Task 2-problem solving/Longest Common Prefix.java b/Week 3/Task 2-problem solving/Longest Common Prefix.java similarity index 100% rename from Task 2-problem solving/Longest Common Prefix.java rename to Week 3/Task 2-problem solving/Longest Common Prefix.java diff --git a/Task 2-problem solving/Two Sum.java b/Week 3/Task 2-problem solving/Two Sum.java similarity index 100% rename from Task 2-problem solving/Two Sum.java rename to Week 3/Task 2-problem solving/Two Sum.java diff --git a/Task 2-problem solving/Valid Parentheses.java b/Week 3/Task 2-problem solving/Valid Parentheses.java similarity index 100% rename from Task 2-problem solving/Valid Parentheses.java rename to Week 3/Task 2-problem solving/Valid Parentheses.java