0% found this document useful (0 votes)
13 views6 pages

Code2pdf 6765d89379d19

Uploaded by

bdalh200
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

Code2pdf 6765d89379d19

Uploaded by

bdalh200
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

import java.util.

Scanner;

public class Programing {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

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;

System.out.println(" Welcome to the Library Management System! ");


System.out.println("");

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) ;

int index4 = -1;


for (int i = 0; i < bookID.length; ++i) {
if (bookTitles[i] != null &&
(bookID[i] == SearchBookByID || bookTitles[i].equals(SearchBookByTitle))) {
index4 = i;
break;
}
}

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;

case 3: // Issue a Book


if (bookCount == 0) {
System.out.println("==========================================");
System.out.println(" No available books!");
System.out.println("==========================================");
System.out.println();
break;
}
System.out.println("=================================== Available Books ===================================");
System.out.println("â•”â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â
System.out.println("â•‘ ID â•‘ Title â•‘ Description â•‘ Availability â•‘");
System.out.println("#------------------------------------------------------------------------------------------------#");
for (int i = 0; i < bookID.length; i++) {
if (bookTitles[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("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;

if (index >= 0 && index < bookID.length && bookTitles[index] != null) {


if (!bookIssued[index]) {
bookIssued[index] = true;
System.out.println("==========================================");
System.out.println(" Book Issued Successfully");
System.out.println("==========================================");
System.out.println();
} else {
System.out.println("==========================================");
System.out.println(" Book is already 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 4: // Return a Book


if (bookCount == 0) {
System.out.println("==========================================");
System.out.println(" No available books!");
System.out.println("==========================================");
System.out.println();
break;
}
System.out.println("=================================== Issued Books ===================================");
System.out.println("â•”â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â
System.out.println("â•‘ ID â•‘ Title â•‘ Description â•‘ Availability â•‘");
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("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;
}

// show all books


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("╚â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•​â•

// enter the id you want to delete


System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.print("Enter book ID to delete: ");
int deleteID = input.nextInt();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println();

int index3=-1;
for(int i=0;i<bookID.length;++i){
if(bookID[i]==deleteID){
index3=i;
break;

// check valditaion of the id


if (index3 < 0 || index3 >= bookCount || bookTitles[index3] == null) {
System.out.println("Invalid book ID!");
break;
}

// confirm the delete


System.out.print("Are you sure you want to delete this book? (yes/no): ");
input.nextLine();
String choice = input.nextLine();
System.out.println();

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];
}

// delete last element


bookTitles[bookCount - 1] = null;
bookDescription[bookCount - 1] = null;
bookIssued[bookCount - 1] = false;
bookID[bookCount-1]=0;

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();

int index5 = -1; // Initialize with -1 to indicate no match


for (int i = 0; i < bookID.length; ++i) {
if (bookID[i] == updateID) {
index5 = i;
break;
}
}

if (index5 != -1) { // Check if a valid index was found


System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
input.nextLine();
System.out.println("What do you want to edit?");
System.out.println("1. Title");
System.out.println("2. Description");
System.out.print("Enter 1 or 2: ");
int edit = input.nextInt();
input.nextLine();
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:

System.out.println("Enter a valid number");


}
}
}

You might also like