diff --git a/Answers/Admin.java b/Answers/Admin.java new file mode 100644 index 0000000..dd3f104 --- /dev/null +++ b/Answers/Admin.java @@ -0,0 +1,94 @@ +import java.util.Objects; +import java.util.Scanner; + +public class Admin implements C { + public Admin(){ + } + + + + + + public void Ad() { + Scanner input = new Scanner(System.in); + System.out.println("please enter the password: "); + int i = 3; + while(true) { + String s = input.nextLine(); + if (Objects.equals(s, "abc123")) break; + + else{ + System.out.println("you entered wrong password!");} + + } + try { + System.out.println("please enter one option" + "\n" + "1-add new member" + "\n" + "2-remove member" + "\n" + "for choosing option you need to write something like this : (lib add member) "); + String a = input.nextLine(); + if (Objects.equals(a, "lib remove member")) { + System.out.println("please enter the member ID"); + String R = input.nextLine(); + remove_member(R); + + } + if (Objects.equals(a, "lib add member")) { + System.out.println("please enter the Student ID and Password"); + String P = input.nextLine(); + String S = input.nextLine(); + add_member(S, P); + } + }catch(Exception e) { + System.out.println("Something went wrong"); + } + + + + } + + @Override + public void add_book(String name, String author, String subtitle) { + + } + + @Override + public void get_hrs() { + + } + + @Override + public void rent(String book_name) { + + } + + @Override + public void add_member(String std_id, String password) { + while(true){ + Scanner input = new Scanner(System.in); + password = input.nextLine(); + if(Objects.equals(password, "abc123"))break; + else System.out.println("password is wrong"); + } + + + + } + + @Override + public void rent(String book_name, String member_name, String member_id) { + + } + + @Override + public void available_book() { + + } + + @Override + public void remove_member(String member_id) { + + } + + @Override + public void return_book(String book_name) { + + } +} diff --git a/Answers/Book.java b/Answers/Book.java new file mode 100644 index 0000000..ae5aa0f --- /dev/null +++ b/Answers/Book.java @@ -0,0 +1,3 @@ +public class Book { + +} diff --git a/Answers/C.java b/Answers/C.java new file mode 100644 index 0000000..f634263 --- /dev/null +++ b/Answers/C.java @@ -0,0 +1,10 @@ +public interface C { + void add_book(String name , String author , String subtitle); + void get_hrs(); + void rent(String book_name); + void add_member(String std_id , String password); + void rent (String book_name , String member_name , String member_id); + void available_book(); + void remove_member(String member_id); + void return_book(String book_name); +} diff --git a/Answers/Library.java b/Answers/Library.java new file mode 100644 index 0000000..9c0787e --- /dev/null +++ b/Answers/Library.java @@ -0,0 +1,4 @@ +public class Library { + + +} diff --git a/Answers/MyApp.java b/Answers/MyApp.java new file mode 100644 index 0000000..423df5c --- /dev/null +++ b/Answers/MyApp.java @@ -0,0 +1,39 @@ +import java.util.Objects; +import java.util.Scanner; +import java.util.regex.Pattern; + +public class MyApp { + public static void main(String[] args) { + String x; + Admin admin = new Admin(); + NormalUser user = new NormalUser(); + Scanner input = new Scanner(System.in); + System.out.println("log in as Admin : 1" + "\n" + "log in as user : 2"); + x = input.nextLine(); + // || Pattern.matches("[9][0-9]{9}", phone) + while (true) { + + + + if(Pattern.matches("[12]{1}" , x)){ + if(Objects.equals(x, "1")){ + admin.Ad(); + } + if(Objects.equals(x, "2")){ + user.sing(); + } + } + else{ + System.out.println("wrong try again: "); + x = input.nextLine(); + } + + + + + + } + + } +} + diff --git a/Answers/NormalUser.java b/Answers/NormalUser.java new file mode 100644 index 0000000..5dba80c --- /dev/null +++ b/Answers/NormalUser.java @@ -0,0 +1,182 @@ +import jdk.management.jfr.FlightRecorderMXBean; + +import javax.swing.*; +import java.util.Objects; +import java.util.Random; +import java.util.Scanner; +import java.util.regex.Pattern; + +import static java.util.regex.Pattern.matches; + +public class NormalUser implements C { + public String[]Name = new String[20]; + public String[]User_ID = new String[20]; + public String[]phone_number = new String[20]; + public NormalUser() { + } + + public void sing() { + System.out.println("Welcome to our library"); + System.out.println("for sign in please enter: 1" + "\n" + "for sign up please enter : 2"); + Scanner input = new Scanner(System.in); + String AA = input.nextLine(); + while (true) { + if (Objects.equals(AA, "1")) { + Check(); + break; + } + if (Objects.equals(AA, "2")) + signup(); + else { + System.out.println("Wrong+"); + AA = input.nextLine(); + } + } + } + + public void signup() { + String phone; + Random random = new Random(); + System.out.println("please enter your name and phone number"); + Scanner input = new Scanner(System.in); + System.out.println("name:"); + String name = input.nextLine(); + System.out.println("phone number:"); + phone = input.nextLine(); + while (true) { + + if (Pattern.matches("[0][0-9]{10}", phone)) { + break; + } else { + System.out.println("wrong phone number please try again"); + phone = input.nextLine(); + } + } + + int ID = random.nextInt(1000); + String id = String.valueOf(ID); + User user = new User(); + user.save(name, phone, id); + } + + public void Check() { + int o = 0; + User user = new User(); + + System.out.println("please enter your ID"); + Scanner input = new Scanner(System.in); + String ID = input.nextLine(); + while(true) { + for (int k = 1; k < User_ID.length; k++) { + if (Objects.equals(User_ID[k], ID)) { + o = 1; + System.out.format("name :%s \nID :%s \nphone number:%s\n", Name[k], User_ID[k], phone_number[k]); + break; + } + } + if(o==1)break; + else{ + System.out.println("wrrrrrong"); + ID = input.nextLine(); + } + } + + + signin(); + + + } + + + + public void signin() { + + + Scanner input = new Scanner(System.in); + System.out.println("please enter one option" + "\n" + "1-add book" + "\n" + "2-get hrs" + "\n" + "3-rent" + "\n" + "4-Rent(for specific member) " + "\n" + "5-get available books" + "\n" + "6-return" + "\n" + "for choosing option you have to write something like this : (lib rent)"); + String A = input.nextLine(); + while (true) { + + + if (Objects.equals(A, "lib add book")) { + System.out.println("please enter name,author and subtitle"); + String N = input.nextLine(); + String Author = input.nextLine(); + String S = input.nextLine(); + add_book(N, Author, S); + } + if (Objects.equals(A, "lib get hrs")) { + get_hrs(); + } + if (Objects.equals(A, "lib rent")) { + System.out.println("please enter the book_name"); + String BN = input.nextLine(); + rent(BN); + } + if (Objects.equals(A, "lib Rent")) { + System.out.println("please enter the BookName,MemberName and MemberID"); + String BN = input.nextLine(); + String MN = input.nextLine(); + String MID = input.nextLine(); + rent(BN, MN, MID); + } + if (Objects.equals(A, "lib get available books")) { + available_book(); + } + if (Objects.equals(A, "lib return")) { + System.out.println("please enter BookName"); + String BN = input.nextLine(); + return_book(BN); + } else { + System.out.println("wrong+++"); + A = input.nextLine(); + + } + } + } + + + + @Override + public void add_book(String name, String author, String subtitle) { + + } + + @Override + public void get_hrs() { + System.out.println("8AM - 5PM"); + System.out.println("\n"); + signin(); + + } + + @Override + public void rent(String book_name) { + + } + + @Override + public void add_member(String std_id, String password) { + + } + + @Override + public void rent(String book_name, String member_name, String member_id) { + + } + + @Override + public void available_book() { + + } + + @Override + public void remove_member(String member_id) { + + } + + @Override + public void return_book(String book_name) { + + } +} diff --git a/Answers/Rent.java b/Answers/Rent.java new file mode 100644 index 0000000..7d8502d --- /dev/null +++ b/Answers/Rent.java @@ -0,0 +1,2 @@ +public class Rent { +} diff --git a/Answers/User.java b/Answers/User.java new file mode 100644 index 0000000..b379ed6 --- /dev/null +++ b/Answers/User.java @@ -0,0 +1,31 @@ +import com.sun.source.tree.NewArrayTree; + +import java.time.LocalDate; + +public class User { + NormalUser normalUser = new NormalUser(); + + int i = 1; + public User(){ + + + } + + public void save(String name , String phone , String ID ) { + while(true) { + normalUser.Name[i] = name; + normalUser.phone_number[i] = phone; + normalUser.User_ID[i] = ID; + System.out.format("user %d \nname : %s \nphone number : %s \nid: %s \n", i, normalUser.Name[i], normalUser.phone_number[i], normalUser.User_ID[i]); + LocalDate time =LocalDate.now(); + System.out.println("you have been signed up at" + " " + time + "\n" ); + i++; + break; + } + + normalUser.Check(); + } + + + +}