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

40230112123 #41

Open
wants to merge 61 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
fa8e146
add book class to project
Hossein-math Apr 25, 2024
069d11c
some changes in algorithm of generate code
Hossein-math Apr 30, 2024
28b17c2
add project files
Hossein-math Apr 30, 2024
a586ae1
add basic version of users
Hossein-math Apr 30, 2024
6e5a478
add MyApp class
Hossein-math Apr 30, 2024
b4ca2a7
add Rent class
Hossein-math Apr 30, 2024
11a5df4
add Manual class
Hossein-math Apr 30, 2024
e2fa9d1
add library class
Hossein-math Apr 30, 2024
7402392
project file
Hossein-math May 9, 2024
464f7bd
delete UUID and add validate phoneNumber
Hossein-math May 9, 2024
56634b7
create class NormalUser
Hossein-math May 9, 2024
d14cf3d
add some commands
Hossein-math May 9, 2024
7928064
project file
Hossein-math May 9, 2024
6aa1cff
add option to save library in file
Hossein-math May 9, 2024
f84a994
add method add book and add user
Hossein-math May 9, 2024
c0e5e24
nothing
Hossein-math May 9, 2024
48624a3
add validate password
Hossein-math May 9, 2024
01fb444
change the regex in validation
Hossein-math May 10, 2024
716f555
delete uuid
Hossein-math May 10, 2024
1c0d0d8
change add normal user method to void
Hossein-math May 10, 2024
dec8188
nothing special
Hossein-math May 10, 2024
49def81
rearrange the code and add lib add member command
Hossein-math May 10, 2024
2fb7b5a
nothing special
Hossein-math May 10, 2024
0880efc
add command lib add book to CLI
Hossein-math May 10, 2024
7ba1bd5
project started 😎🖤🤍
Aryanoor Apr 22, 2024
9762bc6
add login method
Hossein-math Apr 25, 2024
97bf92a
add lib login and logout to CLI
Hossein-math May 10, 2024
a697bcd
change datatype of date and time
Hossein-math May 10, 2024
89e869f
delete methods that doesn't have any usage
Hossein-math May 10, 2024
f9be69d
handle time and date of register normal users
Hossein-math May 10, 2024
779a65f
change time and date of register normal users
Hossein-math May 10, 2024
20de136
add setUniqueID method
Hossein-math May 10, 2024
ba49d36
debug lib add book command
Hossein-math May 10, 2024
2300216
update gitignore
Hossein-math May 10, 2024
6bade73
save sql command in final string
Hossein-math May 10, 2024
2a5e7d3
save database information with final string
Hossein-math May 10, 2024
b1757c0
add uniqueIDUpdate method
Hossein-math May 10, 2024
c5ae50a
add removeUser and getAvailableBooks methods
Hossein-math May 10, 2024
8f17f5a
Change order of commands
Hossein-math May 10, 2024
1db5010
add getavailable and remove user commands
Hossein-math May 10, 2024
4a3f71a
add method UniqueIDUpdate
Hossein-math May 14, 2024
241e1e6
Nothing Special
Hossein-math May 14, 2024
cc5cbe4
add some feature
Hossein-math May 14, 2024
5104f81
add command whoami
Hossein-math May 14, 2024
1500459
add Updatable interface to project
Hossein-math May 15, 2024
b75b0a3
add getStatus method
Hossein-math May 15, 2024
e87fa24
add addRent method
Hossein-math May 15, 2024
7e3a4ca
add lib rent command to CLI
Hossein-math May 15, 2024
974c2ab
add update method
Hossein-math May 15, 2024
b41e6a1
add user.toString method
Hossein-math May 15, 2024
2b12c43
update .gitignore
Hossein-math May 15, 2024
2048767
add new constructor to book class
Hossein-math May 16, 2024
5b3b796
add returnBook method
Hossein-math May 16, 2024
0281db8
add return book command
Hossein-math May 16, 2024
0c3939e
add rentBook and update command
Hossein-math May 16, 2024
45d5694
add command lib get rented books
Hossein-math May 16, 2024
5105a6c
add command lib get rented books
Hossein-math May 16, 2024
fca3993
add new constructor
Hossein-math May 16, 2024
97e67cf
debug
Hossein-math May 16, 2024
a230053
add new constructor
Hossein-math May 16, 2024
a423282
debug
Hossein-math May 16, 2024
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
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.library.txt
/out/production/Library-Management-System/Admin.class
/out/production/Library-Management-System/Book.class
/out/production/Library-Management-System/Library.class
/out/production/Library-Management-System/Manual.class
/out/production/Library-Management-System/MyApp.class
/out/production/Library-Management-System/NormalUser.class
/out/production/Library-Management-System/Rent.class
/out/production/Library-Management-System/User.class
/out/production/Library-Management-System/Updatable.class
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

6 changes: 6 additions & 0 deletions .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 .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 .idea/vcs.xml

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

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

public class Admin extends User {
private final String password;

public Admin(String name, String phoneNumber, String password) throws IllegalArgumentException {
super(name, phoneNumber);

// validate password
if (!password.matches(".*\\d.*") && !password.matches(".*[a-z].*") &&
!password.matches(".*[A-Z].*") && !password.matches("[^(\"\\s)]*"))
throw new IllegalArgumentException("Password should contain at least one digit," +
"one capital and small letter\nand should not have \" character and white spaces.");

this.password = password;
}

// to verify the password
public boolean verify(String password) {
return this.password.equals(password);
}
}
105 changes: 105 additions & 0 deletions Answers/src/Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import java.sql.*;

public class Book implements Updatable {
private String title;
private String author;
private String description;
private int uniqueID; // unique id automatically generate in database
private boolean availabilityStatus = true;

// two arguments constructor
public Book(String title, String author) {
this.title = title;
this.author = author;
}

// three arguments constructor
public Book(String title, String author, String description) {
this.title = title;
this.author = author;
this.description = description;
}

public Book(int bookID) throws Exception {
final String SQL_COMMAND = "SELECT * FROM books WHERE BookID = ?;";

try (Connection connection = DriverManager.getConnection(MyApp.DB_URL, MyApp.DB_USERNAME,
MyApp.DB_PASSWORD);
PreparedStatement selectBook = connection.prepareStatement(SQL_COMMAND)){

selectBook.setInt(1, bookID);

ResultSet resultSet = selectBook.executeQuery();

if (resultSet.next()) {
this.uniqueID = bookID;
this.title = resultSet.getString("Title");
this.author = resultSet.getString("Author");
this.description = resultSet.getString("Description");
this.availabilityStatus = resultSet.getBoolean("AvailabilityStatus");
} else
throw new Exception("Book with ID = " + bookID + " not found.");
} catch (SQLException e) {
e.printStackTrace();
System.err.print("Connection to database failed! Terminating...");
System.exit(1);
}
}

@Override
public void update() {
final String SQL_COMMAND = "SELECT BookID, AvailabilityStatus FROM books WHERE Title = ? " +
"AND Author = ?";

try (Connection connection = DriverManager.getConnection(MyApp.DB_URL,
MyApp.DB_USERNAME, MyApp.DB_PASSWORD);
PreparedStatement selectID = connection.prepareStatement(SQL_COMMAND)) {

selectID.setString(1, this.title);
selectID.setString(2, this.author);

ResultSet resultSet = selectID.executeQuery();
if (resultSet.next()) {
this.uniqueID = resultSet.getInt("BookID");
this.availabilityStatus = resultSet.getBoolean("AvailabilityStatus");
}
} catch (SQLException sqlException) {
sqlException.printStackTrace();
System.err.print("Connection to database failed! Terminating...");
System.exit(1);
}
}

public void setStatus(boolean availabilityStatus) {
final String SQL_COMMAND = "UPDATE books SET AvailabilityStatus = ? WHERE BookID = ?;";

try (Connection connection = DriverManager.getConnection(MyApp.DB_URL, MyApp.DB_USERNAME,
MyApp.DB_PASSWORD);
PreparedStatement changeStatusCommand = connection.prepareStatement(SQL_COMMAND)){

changeStatusCommand.setBoolean(1, availabilityStatus);
changeStatusCommand.setInt(2, this.uniqueID);
changeStatusCommand.executeUpdate();

this.availabilityStatus = availabilityStatus;
} catch (SQLException e) {
e.printStackTrace();
System.err.print("Connection to database failed! Terminating...");
}
}
public String getTitle() {
return title;
}

public String getAuthor() {
return author;
}

public String getDescription() {
return description;
}

public int getUniqueID() {
return uniqueID;
}
}
Loading