From 5cfceb8cbee21b65a192c91a1122e38cc7ae4535 Mon Sep 17 00:00:00 2001 From: Amira20208045 Date: Wed, 26 Apr 2023 09:51:33 +0200 Subject: [PATCH 1/5] Week4 Tasks added --- Bonus Task/.gitignore | 29 +++++++++++++++++++ Bonus Task/.idea/.gitignore | 3 ++ Bonus Task/.idea/misc.xml | 6 ++++ Bonus Task/.idea/modules.xml | 8 +++++ Bonus Task/Bonus Task.iml | 11 +++++++ Bonus Task/src/Main.java | 20 +++++++++++++ Library Management System | 1 + README.md | 2 -- Task 1-Reverse String/.gitignore | 29 +++++++++++++++++++ Task 1-Reverse String/.idea/.gitignore | 3 ++ Task 1-Reverse String/.idea/misc.xml | 6 ++++ Task 1-Reverse String/.idea/modules.xml | 8 +++++ Task 1-Reverse String/.idea/vcs.xml | 6 ++++ Task 1-Reverse String/src/Main.java | 23 +++++++++++++++ Task 1-Reverse String/task 1.iml | 11 +++++++ .../.gitignore | 29 +++++++++++++++++++ .../.idea/.gitignore | 3 ++ .../.idea/misc.xml | 6 ++++ .../.idea/modules.xml | 8 +++++ .../.idea/vcs.xml | 6 ++++ .../Task 2.iml | 11 +++++++ .../src/Main.java | 21 ++++++++++++++ 22 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 Bonus Task/.gitignore create mode 100644 Bonus Task/.idea/.gitignore create mode 100644 Bonus Task/.idea/misc.xml create mode 100644 Bonus Task/.idea/modules.xml create mode 100644 Bonus Task/Bonus Task.iml create mode 100644 Bonus Task/src/Main.java create mode 160000 Library Management System delete mode 100644 README.md create mode 100644 Task 1-Reverse String/.gitignore create mode 100644 Task 1-Reverse String/.idea/.gitignore create mode 100644 Task 1-Reverse String/.idea/misc.xml create mode 100644 Task 1-Reverse String/.idea/modules.xml create mode 100644 Task 1-Reverse String/.idea/vcs.xml create mode 100644 Task 1-Reverse String/src/Main.java create mode 100644 Task 1-Reverse String/task 1.iml create mode 100644 Task 2-Check if a String is a Palindrome/.gitignore create mode 100644 Task 2-Check if a String is a Palindrome/.idea/.gitignore create mode 100644 Task 2-Check if a String is a Palindrome/.idea/misc.xml create mode 100644 Task 2-Check if a String is a Palindrome/.idea/modules.xml create mode 100644 Task 2-Check if a String is a Palindrome/.idea/vcs.xml create mode 100644 Task 2-Check if a String is a Palindrome/Task 2.iml create mode 100644 Task 2-Check if a String is a Palindrome/src/Main.java diff --git a/Bonus Task/.gitignore b/Bonus Task/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/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/Bonus Task/.idea/.gitignore b/Bonus Task/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Bonus Task/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Bonus Task/.idea/misc.xml b/Bonus Task/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/Bonus Task/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Bonus Task/.idea/modules.xml b/Bonus Task/.idea/modules.xml new file mode 100644 index 0000000..5a71c8e --- /dev/null +++ b/Bonus Task/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Bonus Task/Bonus Task.iml b/Bonus Task/Bonus Task.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Bonus Task/Bonus Task.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Bonus Task/src/Main.java b/Bonus Task/src/Main.java new file mode 100644 index 0000000..41600ae --- /dev/null +++ b/Bonus Task/src/Main.java @@ -0,0 +1,20 @@ +import java.util.*; +public class Main { + static int stringTokenizer(String sentence, String word){ + StringTokenizer st = new StringTokenizer(sentence); + int count = 0; + while (st.hasMoreElements()) { + if (word.equals(st.nextToken())) count++; + } + return count; + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + String sentence = "Hello / World, Hello /word: Hello -World ?"; + String word = "World"; + System.out.println("number of occurrences: " + stringTokenizer(sentence,word)); + word = "Hello"; + System.out.println("number of occurrences: " + stringTokenizer(sentence,word)); + } +} \ No newline at end of file diff --git a/Library Management System b/Library Management System new file mode 160000 index 0000000..cc8c0e8 --- /dev/null +++ b/Library Management System @@ -0,0 +1 @@ +Subproject commit cc8c0e8f1c3e4ed9b00ac793d1ef167ab49ab1ac 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/Task 1-Reverse String/.gitignore b/Task 1-Reverse String/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/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/Task 1-Reverse String/.idea/.gitignore b/Task 1-Reverse String/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Task 1-Reverse String/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Task 1-Reverse String/.idea/misc.xml b/Task 1-Reverse String/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/Task 1-Reverse String/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Task 1-Reverse String/.idea/modules.xml b/Task 1-Reverse String/.idea/modules.xml new file mode 100644 index 0000000..329053c --- /dev/null +++ b/Task 1-Reverse String/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Task 1-Reverse String/.idea/vcs.xml b/Task 1-Reverse String/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Task 1-Reverse String/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Task 1-Reverse String/src/Main.java b/Task 1-Reverse String/src/Main.java new file mode 100644 index 0000000..cfbb32a --- /dev/null +++ b/Task 1-Reverse String/src/Main.java @@ -0,0 +1,23 @@ +import java.util.Scanner; +public class Main { + + 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); + } + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + String str = scanner.nextLine(); + System.out.println(reverseString(str)); + } +} \ No newline at end of file diff --git a/Task 1-Reverse String/task 1.iml b/Task 1-Reverse String/task 1.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Task 1-Reverse String/task 1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Task 2-Check if a String is a Palindrome/.gitignore b/Task 2-Check if a String is a Palindrome/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/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/Task 2-Check if a String is a Palindrome/.idea/.gitignore b/Task 2-Check if a String is a Palindrome/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Task 2-Check if a String is a Palindrome/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Task 2-Check if a String is a Palindrome/.idea/misc.xml b/Task 2-Check if a String is a Palindrome/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/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/Task 2-Check if a String is a Palindrome/.idea/modules.xml b/Task 2-Check if a String is a Palindrome/.idea/modules.xml new file mode 100644 index 0000000..006ad36 --- /dev/null +++ b/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/Task 2-Check if a String is a Palindrome/.idea/vcs.xml b/Task 2-Check if a String is a Palindrome/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/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/Task 2-Check if a String is a Palindrome/Task 2.iml b/Task 2-Check if a String is a Palindrome/Task 2.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/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/Task 2-Check if a String is a Palindrome/src/Main.java b/Task 2-Check if a String is a Palindrome/src/Main.java new file mode 100644 index 0000000..4de71fe --- /dev/null +++ b/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 From 5c0d1e8002040172fd97028f5cdbf1cae9fb2018 Mon Sep 17 00:00:00 2001 From: Amira20208045 Date: Wed, 26 Apr 2023 10:08:49 +0200 Subject: [PATCH 2/5] Task 2 updated --- Library Management System | 1 - Library System/.gitignore | 29 ++++ Library System/.idea/.gitignore | 8 ++ Library System/.idea/misc.xml | 6 + Library System/.idea/modules.xml | 8 ++ .../.idea/sonarlint/issuestore/index.pb | 0 .../sonarlint/securityhotspotstore/index.pb | 0 Library System/Library System.iml | 11 ++ Library System/src/Book.java | 37 +++++ Library System/src/Library.java | 129 ++++++++++++++++++ Library System/src/Main.java | 44 ++++++ Library System/src/User.java | 45 ++++++ 12 files changed, 317 insertions(+), 1 deletion(-) delete mode 160000 Library Management System create mode 100644 Library System/.gitignore create mode 100644 Library System/.idea/.gitignore create mode 100644 Library System/.idea/misc.xml create mode 100644 Library System/.idea/modules.xml create mode 100644 Library System/.idea/sonarlint/issuestore/index.pb create mode 100644 Library System/.idea/sonarlint/securityhotspotstore/index.pb create mode 100644 Library System/Library System.iml create mode 100644 Library System/src/Book.java create mode 100644 Library System/src/Library.java create mode 100644 Library System/src/Main.java create mode 100644 Library System/src/User.java diff --git a/Library Management System b/Library Management System deleted file mode 160000 index cc8c0e8..0000000 --- a/Library Management System +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cc8c0e8f1c3e4ed9b00ac793d1ef167ab49ab1ac diff --git a/Library System/.gitignore b/Library System/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Library 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/Library System/.idea/.gitignore b/Library System/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/Library System/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Library System/.idea/misc.xml b/Library System/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/Library System/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Library System/.idea/modules.xml b/Library System/.idea/modules.xml new file mode 100644 index 0000000..653b7be --- /dev/null +++ b/Library System/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Library System/.idea/sonarlint/issuestore/index.pb b/Library System/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..e69de29 diff --git a/Library System/.idea/sonarlint/securityhotspotstore/index.pb b/Library System/.idea/sonarlint/securityhotspotstore/index.pb new file mode 100644 index 0000000..e69de29 diff --git a/Library System/Library System.iml b/Library System/Library System.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Library System/Library System.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Library System/src/Book.java b/Library System/src/Book.java new file mode 100644 index 0000000..d2b1704 --- /dev/null +++ b/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/Library System/src/Library.java b/Library System/src/Library.java new file mode 100644 index 0000000..36536ae --- /dev/null +++ b/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/Library System/src/Main.java b/Library System/src/Main.java new file mode 100644 index 0000000..702a40c --- /dev/null +++ b/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/Library System/src/User.java b/Library System/src/User.java new file mode 100644 index 0000000..ecc5542 --- /dev/null +++ b/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; + } +} From 1d6a63d7faa6557061aaf1929ff4fbe9f3d66657 Mon Sep 17 00:00:00 2001 From: Amira20208045 Date: Tue, 9 May 2023 19:45:54 +0300 Subject: [PATCH 3/5] reverse string using StringBuilder added --- Task 1-Reverse String/src/Main.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Task 1-Reverse String/src/Main.java b/Task 1-Reverse String/src/Main.java index cfbb32a..5dd8826 100644 --- a/Task 1-Reverse String/src/Main.java +++ b/Task 1-Reverse String/src/Main.java @@ -1,6 +1,8 @@ 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; @@ -15,9 +17,25 @@ static String reverseString(String s){ } 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 From 92b717035f121d0734a9b8c7b1208ec71277e054 Mon Sep 17 00:00:00 2001 From: Amira20208045 Date: Tue, 9 May 2023 20:47:52 +0300 Subject: [PATCH 4/5] String methods added --- Bonus Task/.idea/vcs.xml | 6 +++ Bonus Task/src/Main.java | 27 ++++++++------ Bonus Task/src/StringManipulation.java | 37 +++++++++++++++++++ .../src/StringTokenizerManipulation.java | 13 +++++++ 4 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 Bonus Task/.idea/vcs.xml create mode 100644 Bonus Task/src/StringManipulation.java create mode 100644 Bonus Task/src/StringTokenizerManipulation.java diff --git a/Bonus Task/.idea/vcs.xml b/Bonus Task/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Bonus Task/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Bonus Task/src/Main.java b/Bonus Task/src/Main.java index 41600ae..3100b91 100644 --- a/Bonus Task/src/Main.java +++ b/Bonus Task/src/Main.java @@ -1,20 +1,25 @@ import java.util.*; public class Main { - static int stringTokenizer(String sentence, String word){ - StringTokenizer st = new StringTokenizer(sentence); - int count = 0; - while (st.hasMoreElements()) { - if (word.equals(st.nextToken())) count++; - } - return count; - } - 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: " + stringTokenizer(sentence,word)); + + 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("number of occurrences: " + stringTokenizer(sentence,word)); + 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/Bonus Task/src/StringManipulation.java b/Bonus Task/src/StringManipulation.java new file mode 100644 index 0000000..8ecf11b --- /dev/null +++ b/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 Date: Fri, 11 Aug 2023 18:48:00 +0300 Subject: [PATCH 5/5] group in one folder --- {Bonus Task => Week 4/Bonus Task}/.gitignore | 0 {Bonus Task => Week 4/Bonus Task}/.idea/.gitignore | 0 {Bonus Task => Week 4/Bonus Task}/.idea/misc.xml | 0 {Bonus Task => Week 4/Bonus Task}/.idea/modules.xml | 0 {Bonus Task => Week 4/Bonus Task}/.idea/vcs.xml | 0 {Bonus Task => Week 4/Bonus Task}/Bonus Task.iml | 0 {Bonus Task => Week 4/Bonus Task}/src/Main.java | 0 {Bonus Task => Week 4/Bonus Task}/src/StringManipulation.java | 0 .../Bonus Task}/src/StringTokenizerManipulation.java | 0 {Library System => Week 4/Library System}/.gitignore | 0 {Library System => Week 4/Library System}/.idea/.gitignore | 0 {Library System => Week 4/Library System}/.idea/misc.xml | 0 {Library System => Week 4/Library System}/.idea/modules.xml | 0 .../Library System}/.idea/sonarlint/issuestore/index.pb | 0 .../Library System}/.idea/sonarlint/securityhotspotstore/index.pb | 0 {Library System => Week 4/Library System}/Library System.iml | 0 {Library System => Week 4/Library System}/src/Book.java | 0 {Library System => Week 4/Library System}/src/Library.java | 0 {Library System => Week 4/Library System}/src/Main.java | 0 {Library System => Week 4/Library System}/src/User.java | 0 .../Task 1-Reverse String}/.gitignore | 0 .../Task 1-Reverse String}/.idea/.gitignore | 0 .../Task 1-Reverse String}/.idea/misc.xml | 0 .../Task 1-Reverse String}/.idea/modules.xml | 0 .../Task 1-Reverse String}/.idea/vcs.xml | 0 .../Task 1-Reverse String}/src/Main.java | 0 .../Task 1-Reverse String}/task 1.iml | 0 .../Task 2-Check if a String is a Palindrome}/.gitignore | 0 .../Task 2-Check if a String is a Palindrome}/.idea/.gitignore | 0 .../Task 2-Check if a String is a Palindrome}/.idea/misc.xml | 0 .../Task 2-Check if a String is a Palindrome}/.idea/modules.xml | 0 .../Task 2-Check if a String is a Palindrome}/.idea/vcs.xml | 0 .../Task 2-Check if a String is a Palindrome}/Task 2.iml | 0 .../Task 2-Check if a String is a Palindrome}/src/Main.java | 0 34 files changed, 0 insertions(+), 0 deletions(-) rename {Bonus Task => Week 4/Bonus Task}/.gitignore (100%) rename {Bonus Task => Week 4/Bonus Task}/.idea/.gitignore (100%) rename {Bonus Task => Week 4/Bonus Task}/.idea/misc.xml (100%) rename {Bonus Task => Week 4/Bonus Task}/.idea/modules.xml (100%) rename {Bonus Task => Week 4/Bonus Task}/.idea/vcs.xml (100%) rename {Bonus Task => Week 4/Bonus Task}/Bonus Task.iml (100%) rename {Bonus Task => Week 4/Bonus Task}/src/Main.java (100%) rename {Bonus Task => Week 4/Bonus Task}/src/StringManipulation.java (100%) rename {Bonus Task => Week 4/Bonus Task}/src/StringTokenizerManipulation.java (100%) rename {Library System => Week 4/Library System}/.gitignore (100%) rename {Library System => Week 4/Library System}/.idea/.gitignore (100%) rename {Library System => Week 4/Library System}/.idea/misc.xml (100%) rename {Library System => Week 4/Library System}/.idea/modules.xml (100%) rename {Library System => Week 4/Library System}/.idea/sonarlint/issuestore/index.pb (100%) rename {Library System => Week 4/Library System}/.idea/sonarlint/securityhotspotstore/index.pb (100%) rename {Library System => Week 4/Library System}/Library System.iml (100%) rename {Library System => Week 4/Library System}/src/Book.java (100%) rename {Library System => Week 4/Library System}/src/Library.java (100%) rename {Library System => Week 4/Library System}/src/Main.java (100%) rename {Library System => Week 4/Library System}/src/User.java (100%) rename {Task 1-Reverse String => Week 4/Task 1-Reverse String}/.gitignore (100%) rename {Task 1-Reverse String => Week 4/Task 1-Reverse String}/.idea/.gitignore (100%) rename {Task 1-Reverse String => Week 4/Task 1-Reverse String}/.idea/misc.xml (100%) rename {Task 1-Reverse String => Week 4/Task 1-Reverse String}/.idea/modules.xml (100%) rename {Task 1-Reverse String => Week 4/Task 1-Reverse String}/.idea/vcs.xml (100%) rename {Task 1-Reverse String => Week 4/Task 1-Reverse String}/src/Main.java (100%) rename {Task 1-Reverse String => Week 4/Task 1-Reverse String}/task 1.iml (100%) rename {Task 2-Check if a String is a Palindrome => Week 4/Task 2-Check if a String is a Palindrome}/.gitignore (100%) rename {Task 2-Check if a String is a Palindrome => Week 4/Task 2-Check if a String is a Palindrome}/.idea/.gitignore (100%) rename {Task 2-Check if a String is a Palindrome => Week 4/Task 2-Check if a String is a Palindrome}/.idea/misc.xml (100%) rename {Task 2-Check if a String is a Palindrome => Week 4/Task 2-Check if a String is a Palindrome}/.idea/modules.xml (100%) rename {Task 2-Check if a String is a Palindrome => Week 4/Task 2-Check if a String is a Palindrome}/.idea/vcs.xml (100%) rename {Task 2-Check if a String is a Palindrome => Week 4/Task 2-Check if a String is a Palindrome}/Task 2.iml (100%) rename {Task 2-Check if a String is a Palindrome => Week 4/Task 2-Check if a String is a Palindrome}/src/Main.java (100%) diff --git a/Bonus Task/.gitignore b/Week 4/Bonus Task/.gitignore similarity index 100% rename from Bonus Task/.gitignore rename to Week 4/Bonus Task/.gitignore diff --git a/Bonus Task/.idea/.gitignore b/Week 4/Bonus Task/.idea/.gitignore similarity index 100% rename from Bonus Task/.idea/.gitignore rename to Week 4/Bonus Task/.idea/.gitignore diff --git a/Bonus Task/.idea/misc.xml b/Week 4/Bonus Task/.idea/misc.xml similarity index 100% rename from Bonus Task/.idea/misc.xml rename to Week 4/Bonus Task/.idea/misc.xml diff --git a/Bonus Task/.idea/modules.xml b/Week 4/Bonus Task/.idea/modules.xml similarity index 100% rename from Bonus Task/.idea/modules.xml rename to Week 4/Bonus Task/.idea/modules.xml diff --git a/Bonus Task/.idea/vcs.xml b/Week 4/Bonus Task/.idea/vcs.xml similarity index 100% rename from Bonus Task/.idea/vcs.xml rename to Week 4/Bonus Task/.idea/vcs.xml diff --git a/Bonus Task/Bonus Task.iml b/Week 4/Bonus Task/Bonus Task.iml similarity index 100% rename from Bonus Task/Bonus Task.iml rename to Week 4/Bonus Task/Bonus Task.iml diff --git a/Bonus Task/src/Main.java b/Week 4/Bonus Task/src/Main.java similarity index 100% rename from Bonus Task/src/Main.java rename to Week 4/Bonus Task/src/Main.java diff --git a/Bonus Task/src/StringManipulation.java b/Week 4/Bonus Task/src/StringManipulation.java similarity index 100% rename from Bonus Task/src/StringManipulation.java rename to Week 4/Bonus Task/src/StringManipulation.java diff --git a/Bonus Task/src/StringTokenizerManipulation.java b/Week 4/Bonus Task/src/StringTokenizerManipulation.java similarity index 100% rename from Bonus Task/src/StringTokenizerManipulation.java rename to Week 4/Bonus Task/src/StringTokenizerManipulation.java diff --git a/Library System/.gitignore b/Week 4/Library System/.gitignore similarity index 100% rename from Library System/.gitignore rename to Week 4/Library System/.gitignore diff --git a/Library System/.idea/.gitignore b/Week 4/Library System/.idea/.gitignore similarity index 100% rename from Library System/.idea/.gitignore rename to Week 4/Library System/.idea/.gitignore diff --git a/Library System/.idea/misc.xml b/Week 4/Library System/.idea/misc.xml similarity index 100% rename from Library System/.idea/misc.xml rename to Week 4/Library System/.idea/misc.xml diff --git a/Library System/.idea/modules.xml b/Week 4/Library System/.idea/modules.xml similarity index 100% rename from Library System/.idea/modules.xml rename to Week 4/Library System/.idea/modules.xml diff --git a/Library System/.idea/sonarlint/issuestore/index.pb b/Week 4/Library System/.idea/sonarlint/issuestore/index.pb similarity index 100% rename from Library System/.idea/sonarlint/issuestore/index.pb rename to Week 4/Library System/.idea/sonarlint/issuestore/index.pb diff --git a/Library System/.idea/sonarlint/securityhotspotstore/index.pb b/Week 4/Library System/.idea/sonarlint/securityhotspotstore/index.pb similarity index 100% rename from Library System/.idea/sonarlint/securityhotspotstore/index.pb rename to Week 4/Library System/.idea/sonarlint/securityhotspotstore/index.pb diff --git a/Library System/Library System.iml b/Week 4/Library System/Library System.iml similarity index 100% rename from Library System/Library System.iml rename to Week 4/Library System/Library System.iml diff --git a/Library System/src/Book.java b/Week 4/Library System/src/Book.java similarity index 100% rename from Library System/src/Book.java rename to Week 4/Library System/src/Book.java diff --git a/Library System/src/Library.java b/Week 4/Library System/src/Library.java similarity index 100% rename from Library System/src/Library.java rename to Week 4/Library System/src/Library.java diff --git a/Library System/src/Main.java b/Week 4/Library System/src/Main.java similarity index 100% rename from Library System/src/Main.java rename to Week 4/Library System/src/Main.java diff --git a/Library System/src/User.java b/Week 4/Library System/src/User.java similarity index 100% rename from Library System/src/User.java rename to Week 4/Library System/src/User.java diff --git a/Task 1-Reverse String/.gitignore b/Week 4/Task 1-Reverse String/.gitignore similarity index 100% rename from Task 1-Reverse String/.gitignore rename to Week 4/Task 1-Reverse String/.gitignore diff --git a/Task 1-Reverse String/.idea/.gitignore b/Week 4/Task 1-Reverse String/.idea/.gitignore similarity index 100% rename from Task 1-Reverse String/.idea/.gitignore rename to Week 4/Task 1-Reverse String/.idea/.gitignore diff --git a/Task 1-Reverse String/.idea/misc.xml b/Week 4/Task 1-Reverse String/.idea/misc.xml similarity index 100% rename from Task 1-Reverse String/.idea/misc.xml rename to Week 4/Task 1-Reverse String/.idea/misc.xml diff --git a/Task 1-Reverse String/.idea/modules.xml b/Week 4/Task 1-Reverse String/.idea/modules.xml similarity index 100% rename from Task 1-Reverse String/.idea/modules.xml rename to Week 4/Task 1-Reverse String/.idea/modules.xml diff --git a/Task 1-Reverse String/.idea/vcs.xml b/Week 4/Task 1-Reverse String/.idea/vcs.xml similarity index 100% rename from Task 1-Reverse String/.idea/vcs.xml rename to Week 4/Task 1-Reverse String/.idea/vcs.xml diff --git a/Task 1-Reverse String/src/Main.java b/Week 4/Task 1-Reverse String/src/Main.java similarity index 100% rename from Task 1-Reverse String/src/Main.java rename to Week 4/Task 1-Reverse String/src/Main.java diff --git a/Task 1-Reverse String/task 1.iml b/Week 4/Task 1-Reverse String/task 1.iml similarity index 100% rename from Task 1-Reverse String/task 1.iml rename to Week 4/Task 1-Reverse String/task 1.iml diff --git a/Task 2-Check if a String is a Palindrome/.gitignore b/Week 4/Task 2-Check if a String is a Palindrome/.gitignore similarity index 100% rename from Task 2-Check if a String is a Palindrome/.gitignore rename to Week 4/Task 2-Check if a String is a Palindrome/.gitignore diff --git a/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 similarity index 100% rename from Task 2-Check if a String is a Palindrome/.idea/.gitignore rename to Week 4/Task 2-Check if a String is a Palindrome/.idea/.gitignore diff --git a/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 similarity index 100% rename from Task 2-Check if a String is a Palindrome/.idea/misc.xml rename to Week 4/Task 2-Check if a String is a Palindrome/.idea/misc.xml diff --git a/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 similarity index 100% rename from Task 2-Check if a String is a Palindrome/.idea/modules.xml rename to Week 4/Task 2-Check if a String is a Palindrome/.idea/modules.xml diff --git a/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 similarity index 100% rename from Task 2-Check if a String is a Palindrome/.idea/vcs.xml rename to Week 4/Task 2-Check if a String is a Palindrome/.idea/vcs.xml diff --git a/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 similarity index 100% rename from Task 2-Check if a String is a Palindrome/Task 2.iml rename to Week 4/Task 2-Check if a String is a Palindrome/Task 2.iml diff --git a/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 similarity index 100% rename from Task 2-Check if a String is a Palindrome/src/Main.java rename to Week 4/Task 2-Check if a String is a Palindrome/src/Main.java