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 4/Bonus Task/.gitignore b/Week 4/Bonus Task/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Week 4/Bonus Task/.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 4/Bonus Task/.idea/.gitignore b/Week 4/Bonus Task/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Week 4/Bonus Task/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Week 4/Bonus Task/.idea/misc.xml b/Week 4/Bonus Task/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/Week 4/Bonus Task/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 4/Bonus Task/.idea/modules.xml b/Week 4/Bonus Task/.idea/modules.xml new file mode 100644 index 0000000..5a71c8e --- /dev/null +++ b/Week 4/Bonus Task/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Week 4/Bonus Task/.idea/vcs.xml b/Week 4/Bonus Task/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Week 4/Bonus Task/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 4/Bonus Task/Bonus Task.iml b/Week 4/Bonus Task/Bonus Task.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Week 4/Bonus Task/Bonus Task.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Week 4/Bonus Task/src/Main.java b/Week 4/Bonus Task/src/Main.java new file mode 100644 index 0000000..3100b91 --- /dev/null +++ b/Week 4/Bonus Task/src/Main.java @@ -0,0 +1,25 @@ +import java.util.*; +public class Main { + public static void main(String[] args) { + StringManipulation sm = new StringManipulation(); + StringTokenizerManipulation stm = new StringTokenizerManipulation(); + + Scanner scanner = new Scanner(System.in); + String sentence = "Hello / World, Hello /word: Hello -World ?"; + String word = "World"; + + System.out.println("number of occurrences of " + word); + System.out.println("Using StringTokenizer Class: " + stm.wordCounts(sentence,word)); + System.out.println("Using String Class(Method 1): " + sm.wordCounts1(sentence,word)); + System.out.println("Using String Class(Method 1): " + sm.wordCounts2(sentence,word)); + + + + word = "Hello"; + System.out.println("\nnumber of occurrences of " + word); + System.out.println("Using StringTokenizer Class: " + stm.wordCounts(sentence,word)); + System.out.println("Using String Class(Method 1): " + sm.wordCounts1(sentence,word)); + System.out.println("Using String Class(Method 1): " + sm.wordCounts2(sentence,word)); + + } +} \ No newline at end of file diff --git a/Week 4/Bonus Task/src/StringManipulation.java b/Week 4/Bonus Task/src/StringManipulation.java new file mode 100644 index 0000000..8ecf11b --- /dev/null +++ b/Week 4/Bonus Task/src/StringManipulation.java @@ -0,0 +1,37 @@ +import java.util.HashMap; +import java.util.StringTokenizer; +public class StringManipulation { + + String removeSpecialLetters(String sentence){ + StringBuilder sb = new StringBuilder(sentence); + for(int i=0 ; i + + + + + \ No newline at end of file diff --git a/Week 4/Library System/.idea/modules.xml b/Week 4/Library System/.idea/modules.xml new file mode 100644 index 0000000..653b7be --- /dev/null +++ b/Week 4/Library System/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Week 4/Library System/.idea/sonarlint/issuestore/index.pb b/Week 4/Library System/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..e69de29 diff --git a/Week 4/Library System/.idea/sonarlint/securityhotspotstore/index.pb b/Week 4/Library System/.idea/sonarlint/securityhotspotstore/index.pb new file mode 100644 index 0000000..e69de29 diff --git a/Week 4/Library System/Library System.iml b/Week 4/Library System/Library System.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Week 4/Library System/Library System.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Week 4/Library System/src/Book.java b/Week 4/Library System/src/Book.java new file mode 100644 index 0000000..d2b1704 --- /dev/null +++ b/Week 4/Library System/src/Book.java @@ -0,0 +1,37 @@ +public class Book { + private String book_title , author_name; + private int book_id; + private double book_version; + private boolean isAvailable; + + public Book(String book_title,String author_name,int book_id,double book_version) { + this.book_title = book_title; + this.book_id = book_id; + this.author_name = author_name; + this.book_version = book_version; + this.isAvailable = true; + } + + public String getBook_title() { + return book_title; + } + + public String getAuthor_name() { + return author_name; + } + + public int getBook_id() { + return book_id; + } + + public double getBook_version() { + return book_version; + } + + public boolean isAvailable() { + return isAvailable; + } + public void setAvailable(boolean available){ + this.isAvailable = available; + } +} diff --git a/Week 4/Library System/src/Library.java b/Week 4/Library System/src/Library.java new file mode 100644 index 0000000..36536ae --- /dev/null +++ b/Week 4/Library System/src/Library.java @@ -0,0 +1,129 @@ +import java.util.ArrayList; + +public class Library { + private String library_name; + private int library_code; + private ArrayList books = new ArrayList<>() ; + private ArrayList users = new ArrayList<>(); + + public Library(String library_name,int library_code){ + this.library_name = library_name; + this.library_code = library_code; + } + public void addUser(User user){ + users.add(user); + System.out.println("User added successfully!"); + } + public void addBook(Book book){ + books.add(book); + System.out.println("Book added successfully!"); + } + + // This method removed a book from a collection of books by taking an integer parameter book_id. + // The method iterates through the collection of books to find the book with the matching book_id, + // removes it from the collection, and prints a success message. If the book_id is not found, + // the method prints an error message and exits the program. + public void removeBook(int book_id){ + for(Book book:books){ + if(book_id == book.getBook_id()){ + books.remove(book); + System.out.println("Book removed successfully!"); + return; + } + } + System.out.println("invalid book id!"); + System.exit(0); + } + + // This method called checkoutBook, which takes two integer arguments: user_id and book_id. + // The method iterates through the list of users to find the user with the specified user_id. It then checks + // if the book with the specified book_id is available to be borrowed. If the book is available, it is borrowed by the user, + // and a success message is printed to the console. If the book is not available, an error message is printed and the program exits + public void checkoutBook(int user_id,int book_id){ + for(User u : users){ + if(user_id == u.getUser_id()) { + for (Book book : books) + if (book_id == book.getBook_id() && book.isAvailable()) { + u.borrow_book(book); + System.out.println("Book checked out successfully!"); + return; + } + } + } + + System.out.println("Book unavailable for check out!"); + System.exit(0); + } + + // This method used to return a book borrowed by a user. It takes two parameters, user_id and book_id, + // and searches through the collection of users to find the user with the matching user_id. It then searches through + // the borrowed_books list of that user to find the book with the matching book_id. If the book is found, + // the user's return_book() method is called to return the book and a success message is printed. If the book is not found, + // a "Book not found!" message is printed and the program exits. + public void returnBook(int user_id,int book_id){ + for(User u : users){ + if(user_id == u.getUser_id()){ + for(Book book: u.getBorrowed_books()){ + if(book_id == book.getBook_id()){ + u.return_book(book); + System.out.println("Book returned successfully!"); + return; + } + } + } + } + System.out.println("Book not found!"); + System.exit(0); + } + // This method used to display a list of available books. + // It iterates through a collection of Book objects, checks if each book is available by calling the isAvailable() method, + // and prints the titles of available books to the console. + public void showAvailableBooks(){ + System.out.println("Available Books:"); + for(Book book : books){ + if(book.isAvailable()) + System.out.print( " " + book.getBook_title()); + } + System.out.println(); + } + + // This method takes a userId as an argument and displays the list of books borrowed by the user with the given userId, + // and then iterates over a list of users to find the user with the given userId. If the user is found and has borrowed books, + // the method prints the list of borrowed books for that user. Otherwise, the method prints a message indicating that the user has no borrowed books. + // If the user is not found in the list of users, the method prints a message indicating that the user was not found and exits the program. + public void showBorrowedBooks(int userId){ + for(User u: users){ + if(userId == u.getUser_id()){ + if(u.getBorrowed_books().size() > 0) { + System.out.println("Borrowed Books of user with id = " + userId); + for (Book book : u.getBorrowed_books()) { + System.out.println(book.getBook_id() + " " + book.getBook_title() + '\n'); + } + } else { + System.out.println("No Borrowed Books!"); + } + return; + } + } + System.out.println("User not found!"); + System.exit(0); + } + + // This method takes an integer book_id as an argument and displays the details of the corresponding book if it is found in the collection of books. + // and then iterates through the list of books and checks if the book_id matches the id of any book in the list. + // If a match is found, the details of the book (such as title, author, version, and availability) are printed to the console. + //If the book is not found in the list, the message "Book not found!" is printed to the console, and the program exits. + public void showBookDetails(int book_id){ + for(Book book : books){ + if(book_id == book.getBook_id()){ + System.out.println("Book Details:"); + System.out.println("Book Id: " + book.getBook_id() + "\nBook Title:" + book.getBook_title() + + "\nBook Author: " + book.getAuthor_name() + + "\nBook Version: " + book.getBook_version() + "\nBook Availability:" + book.isAvailable()); + return; + } + } + System.out.println("Book not found!"); + System.exit(0); + } +} diff --git a/Week 4/Library System/src/Main.java b/Week 4/Library System/src/Main.java new file mode 100644 index 0000000..702a40c --- /dev/null +++ b/Week 4/Library System/src/Main.java @@ -0,0 +1,44 @@ +public class Main { + public static void main(String[] args) { + Library library = new Library("FCIH Library", 12345); + + // add a new books to the library + library.addBook(new Book("Harry Potter", "J.K. Rowling", 1, 1.1)); + library.addBook(new Book("Anne of Green Gables", "Lucy Maud Montgomery", 2, 2.2)); + library.addBook(new Book("Anne of Avonlea", "Lucy Maud Montgomery", 3, 1.1)); + library.addBook(new Book("Anne of the Island", "Lucy Maud Montgomery", 4, 2.2)); + + // remove a book from the library + library.removeBook(2); + + User user1 = new User("Amira", 1); + library.addUser(user1); + + User user2 = new User("Nada", 2); + library.addUser(user2); + + User user3 = new User("Ali", 3); + library.addUser(user3); + + // check out a book + library.checkoutBook(1 , 3); + library.checkoutBook(1 , 4); + //library.checkoutBook(2 , 3); + library.checkoutBook(3 , 1); + + // return a book + library.returnBook(1 , 3); + + // display the list of available books + library.showAvailableBooks(); + + // display the book details of a specific book + library.showBookDetails(3); + + // display the list of borrowed books + library.showBorrowedBooks(1); + //library.showBorrowedBooks(2); + library.showBorrowedBooks(3); + + } +} \ No newline at end of file diff --git a/Week 4/Library System/src/User.java b/Week 4/Library System/src/User.java new file mode 100644 index 0000000..ecc5542 --- /dev/null +++ b/Week 4/Library System/src/User.java @@ -0,0 +1,45 @@ +import java.util.ArrayList; +public class User { + private String user_name; + private int user_id; + private ArrayList borrowed_books = new ArrayList<>(); + + public ArrayList getBorrowed_books() { + return borrowed_books; + } + + public User(String user_name,int user_id) { + this.user_name = user_name; + this.user_id = user_id; + } + public int getUser_id() { + return user_id; + } + + // This method for borrowing a book. The method takes a Book object and returns a boolean indicating if the book was successfully + // borrowed. It first checks if the book is available to be borrowed using the isAvailable() method. If it is available, + // the method sets its availability to false, adds it to a list of borrowed books and returns true. If the book is not available, + // the method returns false to indicate that the book could not be borrowed. + public boolean borrow_book(Book book){ + if(book.isAvailable()){ + book.setAvailable(false); + borrowed_books.add((book)); + return true; + } + return false; + } + + // This method for managing borrowed books that takes a Book object as an argument and returns a boolean value indicating whether the book was successfully returned or not. + // It iterates through a list of borrowed books to check if the book being returned is in the list. If found, it sets its availability to true, + // removes it from the list, and returns true. If not found, it returns false + public boolean return_book(Book book){ + for(Book borrowed:borrowed_books){ + if(borrowed == book){ + book.setAvailable(true); + borrowed_books.remove(book); + return true; + } + } + return false; + } +} diff --git a/Week 4/Task 1-Reverse String/.gitignore b/Week 4/Task 1-Reverse String/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Week 4/Task 1-Reverse String/.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 4/Task 1-Reverse String/.idea/.gitignore b/Week 4/Task 1-Reverse String/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Week 4/Task 1-Reverse String/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Week 4/Task 1-Reverse String/.idea/misc.xml b/Week 4/Task 1-Reverse String/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/Week 4/Task 1-Reverse String/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 4/Task 1-Reverse String/.idea/modules.xml b/Week 4/Task 1-Reverse String/.idea/modules.xml new file mode 100644 index 0000000..329053c --- /dev/null +++ b/Week 4/Task 1-Reverse String/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Week 4/Task 1-Reverse String/.idea/vcs.xml b/Week 4/Task 1-Reverse String/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Week 4/Task 1-Reverse String/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 4/Task 1-Reverse String/src/Main.java b/Week 4/Task 1-Reverse String/src/Main.java new file mode 100644 index 0000000..5dd8826 --- /dev/null +++ b/Week 4/Task 1-Reverse String/src/Main.java @@ -0,0 +1,41 @@ +import java.util.Scanner; +public class Main { + + // time complexity : O(n) + // space complexity : O(n) + static String reverseString(String s){ + char []chars = s.toCharArray(); + int begin = 0 , end = s.length()-1; + + while(begin < end){ + char temp = chars[begin]; + chars[begin]= chars[end]; + chars[end] = temp; + + begin++; + end--; + } + return new String(chars); + } + + // time complexity : O(n) + // space complexity : O(n) + static String reverseStringBuilder(String s){ + StringBuilder sb = new StringBuilder(); + for(int i=s.length()-1; i>=0; i--){ + sb.append(s.charAt(i)); + } + return sb.toString(); + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + String str = scanner.nextLine(); + + // use String class + System.out.println(reverseString(str)); + + // use StringBuilder class + System.out.println(reverseStringBuilder(str)); + } +} \ No newline at end of file diff --git a/Week 4/Task 1-Reverse String/task 1.iml b/Week 4/Task 1-Reverse String/task 1.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Week 4/Task 1-Reverse String/task 1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Week 4/Task 2-Check if a String is a Palindrome/.gitignore b/Week 4/Task 2-Check if a String is a Palindrome/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Week 4/Task 2-Check if a String is a Palindrome/.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 4/Task 2-Check if a String is a Palindrome/.idea/.gitignore b/Week 4/Task 2-Check if a String is a Palindrome/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Week 4/Task 2-Check if a String is a Palindrome/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Week 4/Task 2-Check if a String is a Palindrome/.idea/misc.xml b/Week 4/Task 2-Check if a String is a Palindrome/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/Week 4/Task 2-Check if a String is a Palindrome/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 4/Task 2-Check if a String is a Palindrome/.idea/modules.xml b/Week 4/Task 2-Check if a String is a Palindrome/.idea/modules.xml new file mode 100644 index 0000000..006ad36 --- /dev/null +++ b/Week 4/Task 2-Check if a String is a Palindrome/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Week 4/Task 2-Check if a String is a Palindrome/.idea/vcs.xml b/Week 4/Task 2-Check if a String is a Palindrome/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Week 4/Task 2-Check if a String is a Palindrome/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 4/Task 2-Check if a String is a Palindrome/Task 2.iml b/Week 4/Task 2-Check if a String is a Palindrome/Task 2.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Week 4/Task 2-Check if a String is a Palindrome/Task 2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Week 4/Task 2-Check if a String is a Palindrome/src/Main.java b/Week 4/Task 2-Check if a String is a Palindrome/src/Main.java new file mode 100644 index 0000000..4de71fe --- /dev/null +++ b/Week 4/Task 2-Check if a String is a Palindrome/src/Main.java @@ -0,0 +1,21 @@ +import java.util.Scanner; + +public class Main { + static void checkPalindrome(String str){ + str = str.toLowerCase(); + int begin = 0 , end = str.length()-1; + while(begin < end){ + if(str.charAt(begin) != str.charAt(end)){ + System.out.println("Not Palindrome"); + return; + } + begin++; end--; + } + System.out.println("Palindrome"); + } + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + String str = scanner.nextLine(); + checkPalindrome(str); + } +} \ No newline at end of file