Java Bookstore program

darthdre758

New Member
I am writing a bookstore program for homework. The program gives the user 6 different options for them to select from. Currently, the one I am working on is option 1. Option 1 is to add more books to the stock. When the user selects option 1, it asks the user to enter the book title, it then checks if the books is already in stock. The problem that I am having is checking to see if the book title that the user enters in is already in stock. I have a function called inStock, but I am unsure of how to call this function. Right now the code does not compile because I am receiving an error on the line that says \[code\]if (bt == myBkStore.inStock(title, y))\[/code\] because of incompatible types. But I am not sure of how to call the inStock() function. This is my coding so far:\[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(); Book book = new Book(); String title = "", bookName = "", bookName2 = ""; ArrayList<Book> myLibrary = new ArrayList<Book>(); 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(); if (bt.toString() instanceof String[]) { System.out.println("How many more books to add to the stock? "); Book ba = s.next(); //myBkStore.addNewBook(ba); } else { System.out.println("Enter the amount of pages the book has: "); int pages = s.nextInt(); //myBkStore.addNewBook(pages); System.out.println("Enter the price of the book: "); double price = s.nextDouble(); //myBkStore.addNewBook(price); System.out.println("Enter quantity of books to add to the stock: "); int quant = s.nextInt(); //myBkStore.addNewBook(quant); } System.out.println("Enter a opening balance"); double d = s.nextDouble(); //System.out.println("Account was created and it has the following number: " + myBank.openNewAccount(cn, d));*/ String bt = s.next(); //stores title of book user enters in if (bt == 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); } /*for (Book b : myLibrary) { b.inStock(); } */ 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 bookstoreprivate 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
 
Top