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 cart (current selected books), If book has zero copies display "This book is not in stock", otherwise Update shopping cart and display "Pay to complete the purchase", update book list
If option 4 is chosen: terminate program
please do like
Answer:
Code:
import java.util.Scanner;
import java.util.ArrayList;
public class MyBookstore {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
Bookstore myBkStore = new Bookstore();
int y = 0;
int user_choice = 2;
boolean quit = false;
do {
//display menu to
user
//ask user for his
choice and validate it (make sure it is between 1 and 6)
System.out.println();
System.out.println("1)
Add a book to the stock");
System.out.println("2)
Sell a book in stock");
System.out.println("3)
List the titles of all the books in stock (in the Bookstore
object)");
System.out.println("4)
List all the information about the books in stock (in the Bookstore
object)");
System.out.println("5)
Print out the gross income of the bookstore");
System.out.println("6)
Quit");
System.out.println();
System.out.print("Enter
choice [1-6]: ");
user_choice =
s.nextInt();
switch (user_choice)
{
case 1: System.out.println("Enter a book title");
String bt =
s.next();
//stores title of book user enters in
if (myBkStore.inStock(title, y))
{
System.out.println("How many more to add to the stock");
y = s.nextInt();
myBkStore.addBookQuantity(bt, y);
}
else
{
System.out.println("Enter the amount of pages of the book:
");
int pages = s.nextInt();
System.out.println("Enter the price of the book: ");
double price = s.nextDouble();
System.out.println("Enter the quantity to add: ");
int quant = s.nextInt();
//myBkStore.Book(bt, pages, price, quant);
myBkStore.addNewBook(book);
}
break;
case 2: System.out.println("Enter book title to buy: ");
String bookT = s.next();
myBkStore.sellBook(title, y);
break;
case 3: myBkStore.listTitles();
break;
case 4: myBkStore.listBooks();
break;
case 5: myBkStore.getIncome();
break;
case 6: System.out.println("Thanks for coming");
quit = true;
break;
default: System.out.println("\nInvalid Choice");
}
}
while (!quit);
}
static class Bookstore {
private Book[] books; // all the books in this bookstore
private int totalBooks; // the number of books in this
bookstore
private double grossIncome; //the gross income
of the bookstore (will be incremented when books are sold)
// Constructor: A new Bank object initially doesn’t contain any
accounts.
public Bookstore() {
books = new Book[100];
totalBooks = 0;
grossIncome = 0;
}
// Creates a new bank account using the customer name and the
opening balance given as parameters
// and returns the account number of this new account. It also adds
this account into the account list
// of the Bank calling object.
public void addNewBook(Book b) {
if(totalBooks < books.length) {
books[totalBooks] =
b;
totalBooks++;
}
else
{
System.out.println("\nSorry, cannot add book to stock.");
}
}
public void addBookQuantity(String title, int quantity) {
for (int i =0; i<totalBooks; i++) {
if (title ==
books[i].getTitle() ) {
books[i].addQuantity(quantity);
System.out.println("Quantity added successfully");
return;
}
}
}
public boolean inStock (String title, int quantity) {
for (int i =0; i<totalBooks; i++) {
if (title.equals(books[i].getTitle())) {
if (quantity <= books[i].getQuantity()) {return true;}
else {return false;}
}
}
return false;
}
public boolean sellBook(String title, int quantity){
int i;
boolean sellflag=false;
// Checks to see if
the books are in stock.
boolean retval =
inStock(title, quantity);
// If so, completes the sale.
if (retval) {
for (i=0; i<totalBooks && !sellflag; i++) {
if (title.equals(books[i].getTitle())) {
books[i].subtractQuantity(quantity);
grossIncome += (books[i].getPrice()) * quantity;
sellflag = true;
}
} // for
} // if
return retval;
} // sellBook
public void listTitles()
{
for (int i = 0; i < totalBooks; i++)
{
System.out.println(books[i].getTitle());
}
}
public void listBooks()
{
int i;
System.out.println("\nList of
Books\n======");
for (i = 0; i < totalBooks; i++)
{
System.out.println(books[i]);
}
System.out.println();
}
public double getIncome()
{
return grossIncome;
}
}
static class Book{
private String title;
private int numOfPages;
private double price;
private int quantity;
private Book book;
public String
toString(){
return
"Title: " + title + "\nNumber of pages: " + numOfPages + "\nPrice:"
+ price +"\nQuantity: " + quantity + "\n";
}
public Book book(String
thetitle, int pages, double cost, int num){
/*title =
thetitle;
numOfPages =
pages;
price =
cost;
quantity =
num;*/
return book;
}
public String
getTitle(){
return
title;
}
public double
getPrice(){
return
price;
}
public int
getQuantity(){
return
quantity;
}
public void addQuantity(int
amount){
quantity = quantity + amount;
}
public void subtractQuantity(int amount)
{
System.out.println("Amount to buy");
Scanner s = new
Scanner(System.in);
quantity =
s.nextInt();
quantity = quantity -
amount;
}
}//end of class
}
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 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,...
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 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...
It written in can be python or java There is a bookstore that have the title, year, price is should display all the books in the collection when given the list of books some wants to purchase it will return the total amount they need to pay for example with a list of books like: great expectations, 1861, 13.21 wind in the willows, 1999, 5.89 great gatsby ,1914,20.90 it should show a list of the books at the start when...
(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)...
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...
I need this python program to access an excel file, books inventory file. The file called (bkstr_inv.xlsx), and I need to add another option [search books], option to allow a customer to search the books inventory, please. CODE ''' Shows the menu with options and gets the user selection. ''' def GetOptionFromUser(): print("******************BookStore**************************") print("1. Add Books") print("2. View Books") print("3. Add To Cart") print("4. View Receipt") print("5. Buy Books") print("6. Clear Cart") print("7. Exit") print("*****************************************************") option = int(input("Select your option:...
Subject: Java Program You are writing a simple library checkout system to be used by a librarian. You will need the following classes: Patron - A patron has a first and last name, can borrow a book, return a book, and keeps track of the books they currently have checked out (an array or ArrayList of books). The first and last names can be updated and retrieved. However, a patron can only have up to 3 books checked out at...
You need to program a simple book library system. There are three java classes Book.java // book object class Library.java //library class A2.java //for testing The Book.java class represents book objects which contain the following fields title: a string which represents the book title. author: a string to hold the book author name year: book publication year isbn: a string of 10 numeric numbers. The book class will have also 3 constructors. -The default no argument constructor - A constructor...
please use C++ write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to read a textfile containing a list of books. each line in the file has tile, ..... write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to read a textfile containing a list of books. Each line in...