Task Specification

You are to implement a book purchasing system, called TechBooks. The system keeps a list of book titles that can be purchased, in both physical and ebook form.

  • You have to keep track of how many copies of the physical books are available for each title. If the user tries to buy a (physical) book and there are no copies available, then the system outputs an error message.
  • Some (not all) titles are available in ebook form. If the ebook exists for that title, then there is always a copy of the ebook available.
  • All physical books cost $30.00; all ebooks cost $10.00. Prices may be updated in later versions.
  • The user can request purchasing a book by giving the starting part of the title: the system then lists all books that start with that string, along with the number of copies and whether an ebook exists. The user enters which form of the book they want: if the book is available then it gets added to the users shopping cart.
    • Matching for titles is not case-senstive.
  • Once the user is finished selecting books, they checkout and pay; the system prints the final total price, and updates the number of copies of each book.
  • The user has the option of viewing their shopping cart.
  • The user has the option of printing the full list of books and their availability.
  • The user can quit the system (before or after paying).

Part A

Implement the above specifications, without worrying about availability of physical books or whether there is an ebook. This means the only information you have to store about a book is the title. You do not have to use object oriented concepts at this point: you can implement the system in a main program as a single class. However, you should use multiple methods to break up the complexity of your code: i.e., dont put it all in one method!

SIMPLIFICATIONS for Part A:

  • when the user searches for a book, only the first match is displayed;
  • in Part A you do not have to display or check for number of copies or ebook availability: just assume the book is available and a Physical book is selected (i.e. ignore ebooks);
  • the Shopping Cart can only hold one book (any further selections replace it).

HINTS:

  • use an array of String to represent the list of books (i.e., just store the title);
  • String methods startsWith() and toUpperCase()/toLowerCase()may be useful.

The system should present a menu with the following options:

  • Add a book to shopping cart
  • View shopping cart
  • Checkout
  • List all books in store
  • Quit

UPDATE: Option 1 only needs to display the FIRST matching title found and automatically adds it (a physical copy) to the Shopping Cart. If there are no matches then an error is printed.

Part B

The aim of Part B is to incorporate basic object oriented concepts into your program. In particular, define a Book class that contains all information related to a book: title, author, number of physical copies, and ebook availability. Your main program should be in a new Store class. Using the OO solution, your store could contain an array of Book objects.

Updates to the functionality:

  • you now need to display and check for availability: i.e., check there are >0 books if the user requests a physical copy, or there is an ebook if the user requests that;
  • when you print list of books, you list both title and author, as well as number of copies and ebook availability (see example below);
  • your Shopping Cart should still be a single item (this is extended in Part C).

NOTE: it is OK to start using Object Oriented concepts from the start of the assignment if you prefer---i.e. it is not a requirement to complete Part A before introducing OO.

Book titles to include as data:

You must include the following titles as a minimum exactly as written below, for testing purposes (use only titles for testing Part A). Number of items in stock and ebook availability are indicated. For this assignment, you may hand-code these books directly into your Store:

Absolute Java (Savitch) 5 yes
JAVA: How to Program (Deitel and Deitel) 0 yes
Computing Concepts with JAVA 3 Essentials (Horstman) 5 no
Java Software Solutions (Lewis and Loftus) 5 no
Java Program Design (Cohoon and Davidson) 1 yes

Sample interaction

Below is a sample interaction with the TechBooks system. You do not have to follow this precisely but it illustrates the required functionality. Text in bold is input from the user:

Welcome to TechBooks!

Choose an option:
1. Add a book to shopping cart
2. View shopping cart
3. Checkout
4. List all books
0. Quit
Please make a selection: 1

Enter title to search for: Java concepts
There is no title starting with that

Choose an option:
1. Add a book to shopping cart
2. View shopping cart
3. Checkout
4. List all books
0. Quit
Please make a selection: 1

Enter title to search for: Java
The following title is a match:
1. JAVA: How to program
0. cancel What is your selection: 1

Do you want to buy this as an ebook: no
There are no physical copies of that book available!

Choose an option:
1. Add a book to shopping cart
2. View shopping cart
3. Checkout
4. List all books
0. Quit Please make a selection: 1

Enter title to search for: Computing
The following title is a match:
1. Computing Concepts with JAVA 3 Essentials
0. cancel What is your selection: 1

Do you want to buy this as an ebook: no
“Computing Concepts with JAVA 3 Essentials” has been added to your Cart

Choose an option:
1. Add a book to shopping cart
2. View shopping cart
3. Checkout
4. List all books
0. Quit Please make a selection: 2

Your Shopping Cart contains the following items:
1. Computing Concepts with JAVA 3 Essentials

Choose an option:
1. Add a book to shopping cart
2. View shopping cart
3. Checkout
4. List all books
0. Quit Please make a selection: 1

Enter title to search for: Absolute
The following title is a match:
1. Absolute Java
0. cancel What is your selection: 1

Do you want to buy this as an ebook: no
“Absolute Java” has been added to your Cart

Choose an option:
1. Add a book to shopping cart
2. View shopping cart
3. Checkout
4. List all books
0. Quit Please make a selection: 2

Your Shopping Cart contains the following items:
1. Absolute Java

Choose an option:
1. Add a book to shopping cart
2. View shopping cart
3. Checkout
4. List all books
0. Quit

Please make a selection: 3
You purchased the following item(s):
1. Absolute Java
You have purchased items to the total value of $30.00 Thanks for shopping with TechBooks!

Choose an option:
1. Add a book to shopping cart
2. View shopping cart
3. Checkout
4. List all books
0. Quit
Please make a selection: 4

The following titles are available:
1. Absolute Java (Savitch), 4 copies, no ebook
2. JAVA: How to Program (Deitel and Deitel), 0 copies, ebook available
3. Computing Concepts with JAVA 3 Essentials (Horstman), 5 copies, no ebook
4. Java Software Solutions (Lewis and Loftus), 5 copies, no ebook
5. Java Program Design (Cohoon and Davidson), 1 copy, ebook available

Choose an option:
1. Add a book to shopping cart
2. View shopping cart
3. Checkout
4. List all books
0. Quit Please make a selection: 8

Sorry, that is an invalid option!

Choose an option:
1. Add a book to shopping cart
2. View shopping cart
3. Checkout
4. List all books
0. Quit Please make a selection: 0

Goodbye

Part C

Extend your solution so that:

All matches to a search are displayed and the user selects using line number. An error is printed if the user selects an invalid line number, and the system prompts for a new line number. There should also be a cancel option.

The Shopping Cart can hold up to at least 10 items. (There are no marks for it, but if you want to extend yourself, add a Remove Item from Shopping Cart option.)

To implement this extension, you need to use more arrays (for selection and Shopping Cart).

This extension would result in the following changes to the above interaction:

Choose an option:
1. Add a book to shopping cart
2. View shopping cart
3. Checkout
4. List all books
0. Quit Please make a selection: 1

Enter title to search for: Java
The following title is a match:
1. JAVA: How to program -- Deitel and Deitel
2. Java Software Solutions -- Lewis and Loftus
3. Java Program Design -- Cohoon and Davidson
0. cancel
Which number item do you wish to purchase: 1

Purchasing: JAVA: How to program This is not available as an ebook There is no ebook available for that title “JAVA: How to program” has been added to your Cart
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.