Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mewo mad Aliniya #20

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Answers/40130212091/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Answers/40130212091/.idea/40130212091.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Answers/40130212091/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Answers/40130212091/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Answers/40130212091/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Answers/40130212091/Admin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

public class Admin extends User {

private String password, Id;
public Admin(String name ,String phoneNumber, String password){
super(name, phoneNumber);
this.password = password;
}

public String getPassword(){
return password;
}


}
40 changes: 40 additions & 0 deletions Answers/40130212091/Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

public class Book extends Library {
private int bookID;
private String title, author;
private boolean availabilityStatus;
private String description;

private int i = 100;

public Book(String name, String author, String subtitle){
this.title = name;
this.author = author;
this.description = subtitle;
this.availabilityStatus = true;
this.bookID = ++i;

}

public String getTitle(){
return title;
}

public String getAuthor(){
return author;
}

public boolean getAvailabilityStatus(){
return availabilityStatus;
}

public void setAvailabilityStatus(boolean c){
availabilityStatus = c;
}

public String getDescription() {
return description;
}


}
98 changes: 98 additions & 0 deletions Answers/40130212091/Library.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import java.util.ArrayList;

public class Library{
private String libraryName = "myLibrary";
private int capacity = 350 ;

private String operatingHours = "8:00 _ 21:00";


private ArrayList<Book> bookList = new ArrayList<>();
private ArrayList<NormalUser> userList = new ArrayList<>();
private ArrayList<Rent> rentList = new ArrayList<>();


public String getHours() {
return operatingHours;
}
public String getLibraryName(){
return libraryName;
}

public int getCapacity(){
return capacity;
}

public void addBook(String name, String author, String subtitle){
Book book = new Book(name, author, subtitle);
bookList.add(book);
}

public void addMember(String name, String phoneNumber){
NormalUser normalUser = new NormalUser( name, phoneNumber);
userList.add(normalUser);
}

public void rentBook(String bookName, String userName){
for (int i = 0; i < userList.size(); i++){
if (userList.get(i).getName() == userName){
for (int j = 0; j < bookList.size(); j++){
if (bookList.get(j).getTitle() == bookName){
if (bookList.get(j).getAvailabilityStatus()){
Rent rent = new Rent(userList.get(i), bookList.get(j));
rentList.add(rent);
System.out.println("successful");
return;
}
else {
System.out.println("Book Is Unavailable");
return;
}
}
}
System.out.println("book not found");
return;
}
}
System.out.println("user not found");
}

public void removeMember(String memberId){
for (int i = 0; i < userList.size(); i++){
if (userList.get(i).getId() == memberId){
userList.remove(i);
System.out.println("successful");
return;
}
}
System.out.println("member not found");
}

public void returnBook(String bookName){
for (int i = 0; i < bookList.size(); i++){
if(bookList.get(i).getTitle() == bookName){
bookList.get(i).setAvailabilityStatus(true);
for (int j = 0; j < rentList.size(); j++){
if (rentList.get(j).getBookObject().getTitle() == bookName){
rentList.remove(j);
System.out.println("successful");
return;
}
}
System.out.println("book not found");
}
}
System.out.println("book not found");
}


public void availableBooks(){
for (int i = 0; i < bookList.size(); i++){
if(bookList.get(i).getAvailabilityStatus()){
System.out.println(bookList.get(i).getTitle() + "\n");
}
}
}


}
64 changes: 64 additions & 0 deletions Answers/40130212091/MyApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

import java.util.Scanner;

public class MyApp {

public static void main(String[] args) {
Library library = new Library();
System.out.println("Hello welcome to " + library.getLibraryName());
System.out.println("capacity : " + library.getCapacity());
System.out.println("enter a command");

Scanner command = new Scanner(System.in);
String input;
while (true) {
System.out.println("~~~ ");
input = command.nextLine();
if (input.equalsIgnoreCase("exit")) {
break;
}
commandLine(input.split(" "), library);
}
command.close();
}

public static void commandLine(String[] order, Library library) {
try {
if (order[1].equals("lib") && order[2].equals("add") && order[3].equals("book")) {
library.addBook(order[4], order[5], order[6]);
} else if (order[1].equals("lib") && order[2].equals("add") && order[3].equals("member")) {
library.addMember(order[4], order[5]);
} else if (order[1].equals("lib") && order[2].equals("rent")) {
library.rentBook(order[4], order[5]);
} else if (order[1].equals("lib") && order[2].equals("get") && order[3].equals("hrs")) {
System.out.println(library.getHours());
} else if (order[1].equals("lib") && order[2].equals("get") && order[3].equals("books")) {
library.availableBooks();
} else if (order[1].equals("lib") && order[2].equals("remove") && order[3].equals("member")) {
library.removeMember(order[4]);

} else if (order[1].equals("lib") && order[2].equals("return")) {
library.returnBook(order[4]);
} else if (order[1].equals("lib") && order[2].equals("help")) {
System.out.println("lib add book <name> <author> <subtitle>: Add a new book to the library.\n" +
"lib get hrs: Retrieve library operating hours.\n" +
"lib rent <bookName>: Rent a book from the library.\n" +
"lib add member <studentID> <password>: Add a new member to the library (admin privilege required).\n" +
"lib rent <bookName> <memberName> <memberID>: Rent a book for a specific member.\n" +
"lib get available books: View available books for rental.\n" +
"lib remove member <memberID>: Remove a member from the library (admin privilege required).\n" +
"lib return <bookName>: Return a rented book to the library.\n" +
"lib add admin <AdminName> <PhoneNumber>: Add a new admin to the library\n" +
">>> ");
}
else{
throw new Exception();
}
} catch(
Exception e)

{
throw new RuntimeException("enter a correct command");
}
}
}
15 changes: 15 additions & 0 deletions Answers/40130212091/NormalUser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class NormalUser extends User {

private int Id;
private int j = 100;

public NormalUser(String name, String phoneNumber){
super(name, phoneNumber);
this.Id = ++j;
}

public String getId(){
return toString(Id);
}

}
29 changes: 29 additions & 0 deletions Answers/40130212091/Rent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.util.Date;
import java.util.HashMap;

public class Rent extends Library {
private NormalUser normalUserObject;
private Book bookObject;
private long rentalDate;
private int RentalID;
Date date = new Date();

HashMap<String, String> rent = new HashMap<>();
private int c = 1;

public Rent(NormalUser normalUser, Book book){
this.normalUserObject = normalUser;
this.bookObject = book;
this.rentalDate = date.getTime();
RentalID = ++c;
}

public User getnormalUserObject(){
return normalUserObject;
}

public Book getBookObject(){
return bookObject;
}

}
34 changes: 34 additions & 0 deletions Answers/40130212091/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

public class User extends Library{
private String name;
private String phoneNumber;

private int Id;


public User(String name, String phoneNumber){
this.name = name;
this.phoneNumber = phoneNumber;
}

public String getName(){
return name;
}

public String getPhoneNumber(){
return phoneNumber;
}

public String getId(){
String IdStr = toString(Id);
return IdStr;
}

String toString(int id) {
return toString(id);
}

public User() {

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Answers/40130212091/out/production/40130212091/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Answers/40130212091/out/production/40130212091/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.