Question

Write a console-based program to simulate the management of a bookstore. The program will provide the...

Write a console-based program to simulate the management of a bookstore. The program will provide the following functionalities: listing all books; searching for a book; purchasing books.

2. Functionalities The program will maintain a list of books. Each book has the following information: Title; Author; Category; Price; Number of copies

The program will provide the following functionalities:

2.1 List all books in bookstore.

2.2 Search for a book • Search for a book based on following criteria: (1) keyword in a book title; (2) author; or (3) book category; • The above search criteria are listed in a menu. Each menu item has an associated number; Select a criterion, provide argument (keyword, author, or category); complete search • Display search result;

2.3 Purchase books Simulate the following procedure to purchase books; • List books; • List shopping cart (current selected books to purchase); • Select a book whose number of copies is not zero; add it to shopping cart; update shopping cart and display; • Pay to complete the purchase. Update book list;

2.4 Terminate program

3. Design and Implementation

3.1 Book information will be saved in a group of arrays;

3.2 All functionalities are listed in a menu; each menu item has a number which identifies a function; the functionality is accessed by selecting that menu item number;

3.3 For each functionality, design sub-menu if needed;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The required Code is given Below.

BookStoreApp.java

package javaapplication7;
import java.util.*;

class Books
{
String Author, title,Category;
int price,copies;
Books(String titles,String author,int copy,int bookprice,String category)
{
Author=author;
title=titles;
copies=copy;
price=bookprice;
Category=category;
}
}

class BookStore
{
Books []books=new Books[10];
int purchaseCart[]=new int[10];
BookStore()
{
books[0]=new Books("Let us C","Yashwant Kanetkar",8,300,"TextBook");
books[1]=new Books("Data Communications & Networking","Forouzan Mc Graw Hill",7,300,"TextBook");
books[2]=new Books("Operating System ","Galvin Wiley",9,700,"Reference");
books[3]=new Books("Maths","NCERT",2,400,"TextBook");
books[4]=new Books("Effective Java","Joshua Bloch",4,600,"TextBook");
books[5]=new Books("Modern Operating Systems","Andrew S. Tanenbaum",6,600,"Reference");
books[6]=new Books("Programming In Ansi C","E. Balagurusamy",1,350,"TextBook");
books[7]=new Books("The Unix Programming","Brian Kernighan",3,500,"Reference");
books[8]=new Books("Artificial Intelligence: A Modern Approach","Peter Norvig",2,300,"TextBook");
books[9]=new Books("Object Oriented Programming With C++","E. Balagurusamy",6,750,"TextBook");

}
void listBooks()
{
System.out.printf("%-10s %-50s %-30s %-10s %-7s %-7s\n","BookNo","Title","Author","Category","Copies","Price");
System.out.println("--------------------------------------------------------------------------------------------------------------------");
for (int i=0; i<10; i++)
{
System.out.printf("%-10s %-50s %-30s %-10s %-7d %-7d\n",i+1,books[i].title,books[i].Author,books[i].Category,books[i].copies,books[i].price);
}

}
  

void listBooksbyAuthor()
{
Scanner inp=new Scanner(System.in);
String keyword;
int numOfBook=0;

System.out.print("Enter Athor Name : ");
keyword=inp.nextLine();

System.out.printf("%-10s %-50s %-30s %-10s %-7s %-7s\n","BookNo","Title","Author","Category","Copies","Price");
System.out.println("--------------------------------------------------------------------------------------------------------------------");

for (int i=0; i<10; i++)
{
boolean isPresent = books[i].Author.indexOf(keyword) !=-1? true: false;
if(isPresent==true)
{
System.out.printf("%-10s %-50s %-30s %-10s %-7d %-7d\n",i+1,books[i].title,books[i].Author,books[i].Category,books[i].copies,books[i].price);
numOfBook++;
}
}

if (numOfBook<=0)
System.out.println("No Related Books Found");

}
  
void listBooksbyKeyword()
{
Scanner inp=new Scanner(System.in);
String keyword;
int numOfBook=0;

System.out.print("Enter a keyword : ");
keyword=inp.nextLine();

System.out.printf("%-10s %-50s %-30s %-10s %-7s %-7s\n","BookNo","Title","Author","Category","Copies","Price");
System.out.println("--------------------------------------------------------------------------------------------------------------------");

for (int i=0; i<10; i++)
{
boolean isPresent = books[i].title.indexOf(keyword) !=-1? true: false; // check for matching pattern

if(isPresent==true) // if pattern exist
{
System.out.printf("%-10s %-50s %-30s %-10s %-7d %-7d\n",i+1,books[i].title,books[i].Author,books[i].Category,books[i].copies,books[i].price);
numOfBook++;
}
}

if (numOfBook<=0)
System.out.println("No Realted Books Found");

}

void listBooksbyCategory()
{
Scanner inp=new Scanner(System.in);
String keyword;
int numOfBook=0;

System.out.print("Enter Category (Reference/TextBook) : ");
keyword=inp.nextLine();

System.out.printf("%-10s %-50s %-30s %-10s %-7s %-7s\n","BookNo","Title","Author","Category","Copies","Price");
System.out.println("--------------------------------------------------------------------------------------------------------------------");

for (int i=0; i<10; i++)
{
boolean isPresent = books[i].Category.indexOf(keyword) !=-1? true: false;

if(isPresent==true)
{
System.out.printf("%-10s %-50s %-30s %-10s %-7d %-7d\n",i+1,books[i].title,books[i].Author,books[i].Category,books[i].copies,
books[i].price);
numOfBook++;
}
}

if (numOfBook<=0) // if no pattern matching
System.out.println("No Books Found");

}


void purchase() // purchase book method
{
listBooks(); // display the list before purchase

Scanner inp=new Scanner(System.in);
int BookNumber;
boolean purchase=false;

System.out.print("Enter BookNumber of book to purchase (0 to stop) : ");
BookNumber=inp.nextInt(); // enter BookNumber of book

while(BookNumber!=0) // loop until user input 0 to stop puchase
{
if (books[BookNumber-1].copies > purchaseCart[BookNumber-1]+1 ) // if suuffcient copies is availble
{
purchaseCart[BookNumber-1]++;
purchase=true;
}
else
System.out.println(" No copies not avaialable");


System.out.print("Enter Book Number of book to purchase (0 to stop) : "); // again iterate
BookNumber=inp.nextInt();

}

if(purchase==true) // if any books purchased
{
System.out.println("Pay to complete (1 yes / 0 No)"); // ask to pay or not
int pay=inp.nextInt();

displayCart();

if(pay==1)
{
// if paid then book inventory upadted copy nos and purchaseCart will be zero
for(int i=0; i<10; i++)
{
if (purchaseCart[i]>-0)
books[i].copies=books[i].copies-purchaseCart[i];

purchaseCart[i]=0;
}

System.out.println("Purchase success ");
}

else
{
System.out.println("Purchase cancel ");
for(int i=0; i<10; i++)
{
purchaseCart[i]=0; // on cancel purchase purchaseCart will be zero
}

}

}


}
void displayCart() // display the purcahse purchaseCart with total amount
{
System.out.println(" Your shopping Cart : ");

System.out.printf("%-10s %-50s %-30s %-10s %-7s %-7s\n","BookNo","Title","Author","Category","Copies","Price");
System.out.println("--------------------------------------------------------------------------------------------------------------------");

double tot=0;
for(int i=0; i<10; i++)
{
if (purchaseCart[i]>-0)
{
System.out.printf("%-10s %-50s %-30s %-10s %-7d %-7d\n",i+1,books[i].title,books[i].Author,books[i].Category,purchaseCart[i],books[i].price);
tot=tot+purchaseCart[i] * books[i].price;
}
}
System.out.println(" Total shopping Amount : "+ tot) ;
}
}


public class BookStoreApp
{
public static void main(String a[])
{
int choice;
BookStore store=new BookStore();
Scanner inp=new Scanner(System.in);
while(true)
{
System.out.println("Book store application");
System.out.println("1. List Books");
System.out.println("2. Search Books");
System.out.println("3. Purchase Books");
System.out.println("4. Exit");
System.out.print("Enter choice : ");
choice=inp.nextInt();
switch(choice)
{
case 1:
store.listBooks();
break;
case 2:
int choice2;
System.out.println("Search Book By ");
System.out.println("1. keyword");
System.out.println("2. Author");
System.out.println("3. Category");
System.out.print("Enter your choice : ");
choice2=inp.nextInt();
switch(choice2)
{
case 1:
store.listBooksbyKeyword();
break;
case 2:
store.listBooksbyAuthor();
break;
case 3:
store.listBooksbyCategory();
break;
default: System.out.println("Invalid choice!");
}
break;
case 3:
store.purchase();
break;
case 4 :
System.exit(0);
break;
default:
System.out.println("Invalid choice");

} //switch end

} // loop end

}

}


Output

Add a comment
Know the answer?
Add Answer to:
Write a console-based program to simulate the management of a bookstore. The program will provide the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program for the management of a bookstore in java, WITHOUT THE USE OF BOOK...

    Write a program for the management of a bookstore in java, WITHOUT THE USE OF BOOK CLASS, just arrays, strings, loops, etc. Overview; First menu 1. List all books 2. Search all books 3. Purchase books 4. Exit If option 1 is chosen: List all books by Title, Author, Price, Copies, Category within a group of arrays If option 2 is chosen: Search all books by Title, Author, Price, Copies, Category If option 3 is chosen: List books, List shopping...

  • Write a program for the management of a bookstore in Java Programming Language, WITHOUT THE USE...

    Write a program for the management of a bookstore in Java Programming Language, WITHOUT THE USE OF STUFF RELATING TO OBJECTS AND WHAT NOT, just arrays, strings, loops, etc. I'm in an intro to programming class so I haven't learned those techniques and am not allowed to use them. The books we just create Overview; Opening menu 1. List all books 2. Search all books 3. Purchase books 4. Exit If option 1 is chosen: List all books by Title,...

  • (JAVA NetBeans) Write programs in java Example 9.13~9.15 //Book.Java public class Book { private String title; private...

    (JAVA NetBeans) Write programs in java Example 9.13~9.15 //Book.Java public class Book { private String title; private String author; private double price; /** * default constructor */ public Book() { title = ""; author = ""; price = 0.0; } /** * overloaded constructor * * @param newTitle the value to assign to title * @param newAuthor the value to assign to author * @param newPrice the value to assign to price */ public Book(String newTitle, String newAuthor, double newPrice)...

  • design a C program to control the stock of books of a small bookstore. Part 1:...

    design a C program to control the stock of books of a small bookstore. Part 1: for the cout, it should be printf(" "); should write like that When a client orders a book, the system should check if the bookstore has the book in stock. If the bookstore keeps the title and there is enough stock for the order, the system should inform the price per copy to the client, as well as the total price of the purchase....

  • Write a C program to create a list of books details. The details of a book...

    Write a C program to create a list of books details. The details of a book include title, author, publisher, publishing year, no. of pages , price Perform the following with respect to the list of books created Display all the details of books written by a given author. Sort the details of books in the increasing order of price. Display the details of books published by a given publisher in a given year. Sort the list of books in...

  • For this question,  we want to implement the basic java classes to support the concept of an...

    For this question,  we want to implement the basic java classes to support the concept of an Online Store and a shopping cart. Consider an e-store with various types of items: books, flowers, gift cards, etc... and we like to be able to support the ability to handle a shopping cart that can contain various types of items. For this question you are asked to create the following classes: abstract class: “Item” every item has a unique item_id (a positive integer,...

  • JAVA Objective : • Learning how to write a simple class. • Learning how to use...

    JAVA Objective : • Learning how to write a simple class. • Learning how to use a prewritten class. • Understanding how object oriented design can aid program design by making it easier to incorporate independently designed pieces of code together into a single application. Instructions: • Create a project called Lab13 that contains three Java file called Book.java , Bookstore.java and TempleBookstore.java • I’ve provided a screenshot of how your project should look like. • Be sure to document...

  • Please provide a SQL Table diagram with their relationships based on the following prompt: Consider the...

    Please provide a SQL Table diagram with their relationships based on the following prompt: Consider the design of a database for an online store. Each item is identified by a unique item ID, a title, a description of the item, the date the item is posted, price, and a list of categories (each category is a single word in lower cases). Only registered users can post, buy, and review an item. Each registered user is identified by a user ID,...

  • This assignment requires using C++ language Your program will be creating 10 library books. Each library...

    This assignment requires using C++ language Your program will be creating 10 library books. Each library book will have title, author and publishing year. Each library book will be stored as a structure and your program will have an array of library books (an array of structures). You will create a corresponding array of book genres: Mystery, Romance, Fantasy, Technology, Children, etc. If the first element of the array is storing information about a book titled : "More about Paddington",...

  • Write a C++ program to manage a Point of Sale System for a Supermarket. The main...

    Write a C++ program to manage a Point of Sale System for a Supermarket. The main user is an employee at the Supermarket. Build Specifications (36 points) 1. The system should load a catalog of all items that the store sells. 2. A user can search the inventory: The user of the system can search the inventory by using the name of the item or by category. 3. A user can sell items once they are found. Or can sell...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT