Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q2. Create a class called Book that contains: Four private instance variables: name (String), author (String), price (double), and qtyInStock (int). . One constructor, which

image text in transcribed
Q2. Create a class called Book that contains: Four private instance variables: name (String), author (String), price (double), and qtyInStock (int). . One constructor, which initializes all instances with the values given, except qtyInStock, assume all qty InStock are equal to 2 for all given books. . Methods getters and setters for all the instance variables Write a test program called TestBook to test the constructor and public methods in the class Book. Allow the user to inquire about books and buy books until exit is chosen. If a book is bought you need to modify the quantity available form that book. In your main you should first create 4 books as follows: 1. Big Magic by Elizabeth Gilbert $6.55 2. The glass castle by Jeannette Walls $5.55 3. Steve Jobs by Walter Isaacson $20.23 4. Bill Gates by George Ilian $26.56 Then promote the user to make a choice. Use the sample output below to guide you. Sample output: What would you like to do? (1. Buy a book or 2. Exit): 1 These are the books available in our store: 1. Big Magic by Elizabeth Gilbert $6.55 2. The glass castle by Jeannette Walls $5.55 3. Steve Jobs by Walter Isaacson $20.23 4. Bill Gates by George ilian $26.56 Which book you would like to buy? 3 How many books? 2 Sorry out of stock! What would you like to do? (1. Buy a book or 2. Exit): 1 These are the books available in our store: 1. Big Magic by Elizabeth Gilbert $6.55 2. The glass castle by Jeannette Walls $5.55 3. Steve Jobs by Walter Isaacson $20.23 4. Bill Gates by George Ilian $26.56 Which book you would like to buy? 1 How many books? 1 What would you like to do? (1. Buy a book or 2. Exit): 2 Your total is $20.23 Thank you

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

More Books

Students also viewed these Databases questions

Question

WHO are the interface stakeholders?

Answered: 1 week ago