Code2pdf 6765d89379d19
Code2pdf 6765d89379d19
Scanner;
System.out.println("â•”â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â
System.out.println("â•‘ Welcome to FCDS book Store! â•‘");
System.out.println("╚â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â
System.out.println("");
//Declaration
int arrSize;
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
do{
System.out.print("Pleas Enter the maximum number of books the library can hold: ");
arrSize = input.nextInt();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}while(arrSize<=0); //valdition to avoid user input 0 or negative number
System.out.println("");
System.out.println("");
int[]bookID = new int[arrSize];
bookID[0]=0;
String[]bookTitles = new String[arrSize];
String[]bookDescription = new String[arrSize];
boolean[]bookIssued = new boolean[arrSize];
int bookCount = 0;
int nextID=0;
while(true){
System.out.println("â•”â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
System.out.println("â•‘1. Add a Book â•‘");
System.out.println("â•‘----------------------------------------------â•‘");
System.out.println("â•‘2. Search for a Book (by Title or ID) â•‘");
System.out.println("â•‘----------------------------------------------â•‘");
System.out.println("â•‘3. Issue a Book (by ID) â•‘");
System.out.println("â•‘----------------------------------------------â•‘");
System.out.println("â•‘4. Return a Book (by ID) â•‘");
System.out.println("â•‘----------------------------------------------â•‘");
System.out.println("â•‘5. Delete a Book (by ID) â•‘");
System.out.println("â•‘----------------------------------------------â•‘");
System.out.println("â•‘6. Edit Book Details (Title/Description by ID)â•‘");
System.out.println("â•‘----------------------------------------------â•‘");
System.out.println("â•‘7. Veiw All Books â•‘");
System.out.println("â•‘----------------------------------------------â•‘");
System.out.println("â•‘8. Exit â•‘");
System.out.println("╚â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
System.out.print("Enter your choice: ");
int choise=input.nextInt();
System.out.println("");
switch (choise){
case 1:
if (bookCount >= arrSize) {
System.out.println("==========================================");
System.out.println("You have no enough space in your library");
System.out.println("==========================================");
System.out.println("");
} else {
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.print("Enter book title: ");
input.nextLine();
String title = input.nextLine();
System.out.print("Enter book description: ");
String description = input.nextLine();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("");
bookTitles[bookCount] = title;
bookDescription[bookCount] = description;
bookIssued[bookCount] = false;
bookID[bookCount] = nextID;
nextID++;
bookCount++;
System.out.println("==========================================");
System.out.println(" Book added successfully");
System.out.println("==========================================");
System.out.println("");
}
break;
case 2:
if (bookCount == 0) {
System.out.println("==========================================");
System.out.println(" No available books!");
System.out.println("==========================================");
System.out.println();
break;
}
String SearchBookByTitle = null;
int SearchBookByID = -1;
int TypeOfSearch;
do{
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Choose (1) if you want search by name");
System.out.println("Choose (2) if you want search by id ");
System.out.print("choice:");
TypeOfSearch = input.nextInt();
input.nextLine();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println();
switch (TypeOfSearch) {
case 1:
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.print("Enter book title:");
SearchBookByTitle = input.nextLine();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println();
break;
case 2:
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
do{
System.out.print("Enter book ID:");
SearchBookByID = input.nextInt();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println();}while (SearchBookByID<0);
break;
default:
System.out.println("==========================================");
System.out.println(" wrong input ");
System.out.println("==========================================");
System.out.println();
break;
}
}while (TypeOfSearch<0) ;
if (index4 != -1) {
System.out.println("â•”â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
System.out.println("â•‘ ID â•‘ Title â•‘ Description â•‘ Availability â•‘");
System.out.println("#------------------------------------------------------------------------------------------------#");
System.out.printf("â•‘ %d â•‘ %-35s â•‘ %-35s â•‘ %-9s â•‘\n", bookID[index4], bookTitles[index4], bookDescription[index4], !bookIssued
System.out.println("╚â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
} else {
System.out.println("==========================================");
System.out.println("Book does not exist or wrong input");
System.out.println("==========================================");
System.out.println();
}
break;
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.print("Enter Book ID to issue: ");
int issuedID = input.nextInt();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println();
int index=-1;
for(int i=0;i<bookID.length;++i){
if(bookID[i]==issuedID){
index=i;
break;
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.print("Enter Book ID to return: ");
int returnedID = input.nextInt();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println();
int index2=-1;
for(int i=0;i<bookID.length;++i){
if(bookID[i]==returnedID){
index2=i;
break;
}
if (index2 >= 0 && index2 < bookCount && bookDescription[index2] != null) {
if (bookIssued[index2]) {
bookIssued[index2] = false;
System.out.println("==========================================");
System.out.println(" Book Returned Successfully");
System.out.println("==========================================");
System.out.println();
} else {
System.out.println("==========================================");
System.out.println(" Book was not issued");
System.out.println("==========================================");
System.out.println();
}
} else {
System.out.println("==========================================");
System.out.println(" Invalid or deleted book");
System.out.println("==========================================");
System.out.println();
}
break;
case 5:
if (bookCount == 0) {
System.out.println("==========================================");
System.out.println(" No books available to delete!");
System.out.println("==========================================");
System.out.println();
break;
}
int index3=-1;
for(int i=0;i<bookID.length;++i){
if(bookID[i]==deleteID){
index3=i;
break;
if (choice.equalsIgnoreCase("yes")) {
// shift the elements
for (int i = index3; i < bookCount - 1; i++) {
bookTitles[i] = bookTitles[i + 1];
bookDescription[i] = bookDescription[i + 1];
bookIssued[i] = bookIssued[i + 1];
bookID[i]=bookID[i+1];
}
bookCount--;
System.out.println("==========================================");
System.out.println("Book deleted successfully and list updated!");
System.out.println("==========================================");
System.out.println();
} else {
System.out.println("==========================================");
System.out.println(" Book deletion canceled.");
System.out.println("==========================================");
System.out.println();
}
break;
case 6:
if (bookCount == 0) {
System.out.println("==========================================");
System.out.println(" No books available to edit!");
System.out.println("==========================================");
System.out.println();
break;
}
System.out.println("===================================Avalible books===================================");
System.out.println("â•”â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
System.out.println("â•‘ ID â•‘ Title â•‘ Descreption â•‘ Avalabilty â•‘");
System.out.println("#------------------------------------------------------------------------------------------------#");
for (int i = 0; i < bookID.length; i++) {
if(bookDescription[i]!=null){
System.out.printf("â•‘ %d â•‘ %-35s â•‘ %-35s â•‘ %-9s â•‘\n", bookID[i], bookTitles[i], bookDescription[i], !bookIssued[i]);
}
}
System.out.println("╚â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.print("select the book's id you want to edit :");
int updateID;
updateID=input.nextInt();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println();
if (edit == 1) {
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.print("Enter the new title: ");
String newTitle = input.nextLine();
bookTitles[index5] = newTitle;
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Title updated successfully.");
System.out.println();
} else if (edit == 2) {
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.print("Enter the new description: ");
String newDescription = input.nextLine();
bookDescription[index5] = newDescription;
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Description updated successfully.");
System.out.println();
} else {
System.out.println("==========================================");
System.out.println(" Please enter a valid option.");
System.out.println("==========================================");
System.out.println();
}
} else {
System.out.println("==========================================");
System.out.println(" Invalid ID. Book not found.");
System.out.println("==========================================");
System.out.println();
}
break;
case 7:
if (bookCount == 0) {
System.out.println("==========================================");
System.out.println(" No books in the library!");
System.out.println("==========================================");
System.out.println();
} else {
System.out.println("===================================Avalible books===================================");
System.out.println("â•”â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
System.out.println("â•‘ ID â•‘ Title â•‘ Descreption â•‘ Avalabilty â•‘");
System.out.println("#------------------------------------------------------------------------------------------------#");
for (int i = 0; i < bookID.length; i++) {
if(bookDescription[i]!=null){
System.out.printf("â•‘ %d â•‘ %-35s â•‘ %-35s â•‘ %-9s â•‘\n", bookID[i], bookTitles[i], bookDescription[i], !bookIssued[i
}
}
System.out.println("╚â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
}
break;
case 8:
input.close();
System.exit(0);
break;
default: