Skip to content
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 .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/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.

38 changes: 38 additions & 0 deletions Answers/40230112119/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
134 changes: 134 additions & 0 deletions Answers/40230112119/src/main/java/org/example/Admin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package org.example;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Admin extends User{
private String password;
public Admin(String name, int uniqueID, String phone, String password) {
super(name, uniqueID, phone);
this.password = password;
}
public Admin() {
super();
this.password = null;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() { return password; }

public void removeBook(ArrayList<Book> booksList, String title) {
for (int i = 0; i < booksList.size(); i++) {
if (title.equals(booksList.get(i))) {
booksList.remove(i);
break;
}
}
}
public void addNewUser(String[] cm) {
Scanner sc = new Scanner(System.in);
Library lib = new Library();
boolean flag = true;
do {
flag = true;
for (int i = 0; i < lib.getUserList().size(); i++) {
if (cm[3].equalsIgnoreCase(Integer.toString(lib.getUserList().get(i).getUniqueID()))) {
flag = false;
break;
}
}

if (!flag) {
System.out.println("This ID already exists. Enter another one. ");
cm[3] = sc.nextLine();
}
} while(!flag);

System.out.println("Enter their name: ");
String name = sc.nextLine();
String phone = null;
flag = true;
do {
System.out.println("Enter your phone: ");
phone = sc.nextLine();
String regex = "^(\\+98|0)?9\\d{9}$";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(phone);

if (m.matches()) {
flag = true;
} else {
flag = false;
System.out.println("Invalid phone number. Try again.");
}

} while (!flag);

String timeStamp = new SimpleDateFormat("yyyy.MM.dd HH:mm").format(new java.util.Date());
NormalUser newUser = new NormalUser(name, Integer.valueOf(cm[3]), phone, timeStamp);
lib.getUserList().add(newUser);
}
public boolean removeMember(int id) {
Library lib = new Library();
boolean result = false;
for (int i = 0; i < lib.getUserList().size(); i++) {
if (id == lib.getUserList().get(i).getUniqueID()) {
lib.getUserList().remove(i);
result = true;
return result;
}
}
return result;
}
public void addNewAdmin(){
Library lib = new Library();
Scanner sc = new Scanner(System.in);
String name;
boolean flag = true;
do {
flag = false;
System.out.println("Enter the name of the user: ");
name = sc.nextLine();
boolean user_found = false;
for (NormalUser i : lib.getUserList()) {
if (i.getName().equals(name)) {
flag = true;
user_found = true;
break;
}
}
if (user_found)
System.out.println("No user found. Try again.");
} while (!flag);

System.out.println("Enter a password for them: ");
String password = sc.nextLine();

flag = true;
int uniqueID = 0;
do {
Random id = new Random();
int tmpID = id.nextInt(9000) + 1000;

flag = true;

for(NormalUser i : lib.getUserList()) {
if (i.getUniqueID() == tmpID) {
flag = false;
break;
}
}

if (flag) {
uniqueID = tmpID; // Update uniqueID only if ID is unique
}
} while(!flag);

// lib.getAdminList().add()
}
}
43 changes: 43 additions & 0 deletions Answers/40230112119/src/main/java/org/example/Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.example;

public class Book {
private int bookID;
private String title;
private String author;
private boolean status;
private String desc;
public Book(int bookID, String title, String author, String desc) {
this.bookID = bookID;
this.title = title;
this.author = author;
this.status = true;
this.desc = desc;
}
public Book() {
this.bookID = -1;
this.title = null;
this.author = null;
this.status = true;
this.desc = null;
}
public void setBookID(int bookID) {
this.bookID = bookID;
}
public void setTitle(String title) {
this.title = title;
}
public void setAuthor(String author) {
this.author = author;
}
public void setStatus(boolean status) {
this.status = status;
}
public void setDesc(String desc) {
this.desc = desc;
}
public int getBookID() { return bookID; }
public String getTitle() { return title; }
public String getAuthor() { return author; }
public boolean getStatus() { return status; }
public String getDesc() { return desc; }
}
33 changes: 33 additions & 0 deletions Answers/40230112119/src/main/java/org/example/Database.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.example;

import java.sql.*;

public class Database {
static final String DB_URL = "jjdbc:mysql://localhost:3306/LMS";
static final String USER = "root";
static final String PASS = "lms613";
public void db(String table, int command) {
try {
Connection con = DriverManager.getConnection(DB_URL, USER, PASS);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM " + table);

switch(table) {
case "books":
switch(command) {
case 1: //update info
rs.moveToInsertRow();
rs.updateString("title","John");
rs.updateString("last","Paul");
rs.updateInt("age",40);
case 2:
}
}

}
catch(SQLException e) {
e.printStackTrace();
}
}
}

Loading