Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, Working on this library project with Classes and what not, having a hard

ID: 3603368 • Letter: H

Question

Hello,

Working on this library project with Classes and what not, having a hard time wrapping it up. I will post what I have so far and the directions and hopefully someone can help me out.

The cpp file: https://paste.ofcode.org/y3sf9YsL2ybLdHE4GxRdt8

The .h file: https://paste.ofcode.org/f5nEywFHwsBHZn58qgJr53

Directions:

1. Create BookClass.h with the following:

Member variables:

• title. A string that holds the book’s title

• author. A string that holds the book’s author

• publisher. A string that holds the book’s publisher

• isbn. A string that holds the book’s ISBN number

• price. A double that holds the book’s price

• year. An int that holds the year when the book was published

• numInStock. An int that holds the number of copies of this book

Member functions:

• void storeBook(string bookTitle, string authorName, string bookPublisher, string bookISBN, double bookPrice, int bookYear, int booksInStock)

     o Stores the parameters into the BookClass member variables

• void displayBookInfo() Displays the contents of the BookClass member variables

• void checkOutBook() Subtracts 1 from the numInStock member variable; tests to make sure numInStock is not 0

• void returnBook() Adds 1 to the numInStock member variable • string getTitle() Returns the value in title

• int getNumInStock() Returns the value in numInStock

2. Create BookMain.cpp to test your BookClass.

Functions:

• void getBookInfo (BookClass &); o Asks the user to enter information for one book, then invokes member function storeBook to store the information in the BookClass variable.

Test your class and function with a main program:

• Call getBookInfo to store the book information into the BookClass variable

• Call CheckOutBook
• Call getTitle to get the book’s title

• Call getNumInStock to get the number of copies currently in stock

• Display the book’s title and number of copies in stock

• Call returnBook • Call getTitle to get the book’s title

• Call getNumInStock to get the number of copies currently in stock

• Display the book’s title and number of copies in stock 3

Thank you, I got most of the .h file done and the implementations of those member functions. Currently having an issue with using storeBook in the .cpp file, and I haven't done the main program yet.

Thank you!

Explanation / Answer


import java.awt.* ;
import javax.swing.* ;
import java.awt.event.* ;

public class Pizzeria extends JFrame implements ActionListener, ItemListener
{
       private static final int WIDTH = 450 ;
private static final int HEIGHT = 150 ;
private static final int X_ORIGIN = 200 ;
private static final int Y_ORIGIN = 100 ;
  
       private static final double smallPizzaPrice = 7.00 ;
       private static final double mediumPizzaPrice = 9.00 ;
       private static final double largePizzaPrice = 11.00 ;
       private static final int smallPizzaSize = 0 ;
       private static final int mediumPizzaSize = 1 ;
       private static final int largePizzaSize = 2 ;
       private static final int TRUE = 1 ;
       private static final int FALSE = 0 ;
       int states = 0 ;
       double totalPrice = 0 ;
       double pizzaSizePrice = smallPizzaPrice ;
       
       
//Toppings & Panel
JCheckBox pepperoni ;
JCheckBox cheese ;
JCheckBox sausage ;
JCheckBox peppers ;
JCheckBox olives ;
JPanel checkboxPanel ;
  
//Pizza Size & Panel
JComboBox pizzaSize ;
JPanel comboboxPanel ;
  
//Price Calc. Button & Panel
JButton calculatePrice ;
JPanel buttonPanel ;
  
//Price Display Field and Panel
JTextField message ;
JPanel messagePanel ;
  
public Pizzeria()
{
super("Pizzeria") ;
  
pizzaSize = new JComboBox() ;
pizzaSize.addItem( "Small" ) ;
pizzaSize.addItem( "Medium" ) ;
pizzaSize.addItem( "Large" ) ;
              pizzaSize.setSelectedIndex(0) ;
pizzaSize.addItemListener(this) ;
  
pepperoni = new JCheckBox("Pepperoni") ;
pepperoni.addItemListener(this) ;
cheese = new JCheckBox("Cheese") ;
cheese.addItemListener(this) ;
sausage = new JCheckBox("Sausage");
sausage.addItemListener(this) ;
peppers = new JCheckBox("Peppers");
peppers.addItemListener(this) ;
olives = new JCheckBox("Olives");
olives.addItemListener(this) ;

calculatePrice = new JButton( "Calculate Price" ) ;
calculatePrice.addActionListener(this) ;
  
message = new JTextField(10) ;

//setSize( 300, 200 ) ;
  
Container contentPane = getContentPane() ;
GridLayout contentpaneLayout = new GridLayout(4,0,10,10) ;
contentPane.setLayout(contentpaneLayout) ;
  
comboboxPanel = new JPanel() ;
GridLayout comboboxPanelLayout = new GridLayout(1,1) ;
comboboxPanel.setLayout(comboboxPanelLayout) ;
comboboxPanel.add(pizzaSize) ;
contentPane.add(comboboxPanel) ;
  
checkboxPanel = new JPanel() ;
GridLayout checkboxPanelLayout = new GridLayout(1,1) ;
checkboxPanel.setLayout(checkboxPanelLayout) ;
checkboxPanel.add(pepperoni) ;
checkboxPanel.add(cheese) ;
checkboxPanel.add(sausage) ;
checkboxPanel.add(peppers) ;
checkboxPanel.add(olives) ;
contentPane.add(checkboxPanel) ;
  
buttonPanel = new JPanel() ;
GridLayout buttonPanelLayout = new GridLayout(1,1) ;
buttonPanel.setLayout(buttonPanelLayout) ;
buttonPanel.add(calculatePrice) ;
contentPane.add(buttonPanel) ;
  
messagePanel = new JPanel() ;
GridLayout messagePanelLayout = new GridLayout(1,1) ;
messagePanel.setLayout(messagePanelLayout) ;
messagePanel.add(message) ;
contentPane.add(messagePanel) ;
  
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
setBounds(X_ORIGIN, Y_ORIGIN, WIDTH, HEIGHT) ;
}
  
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource() ;
  
              //if
              //{                    
              JComboBox cb = (JComboBox)e.getSource() ;
                   int pizzaSize = (int)cb.getSelectedIndex() ;      
                   if (pizzaSize == smallPizzaSize)
              {
                   pizzaSizePrice = smallPizzaPrice ;
                   }
                   else if (pizzaSize == mediumPizzaSize)
                   {
                          pizzaSizePrice = mediumPizzaPrice ;
                   }
                   else if (pizzaSize == largePizzaSize)
                   {
                          pizzaSizePrice = largePizzaPrice ;
                   }
  
              if (source == calculatePrice)
{
                   totalPrice = pizzaSizePrice ;
                   totalPrice += states ;
                   message.setText( "" + totalPrice) ;
              }
                    
              
              //}                  
      }
     
     public void itemStateChanged(ItemEvent e)
{
Object source = e.getSource() ;
  
// if the source of the event was a Toggle Button
  
              if (source instanceof JToggleButton)
            {
                   getComponentStates() ;
            }
       }
  
int getComponentStates()
{
       states = 0 ;
      if (pepperoni.isSelected())
{
states= states + 1;
}
  
if (cheese.isSelected())
{
states= states + 1;
}
  
if (sausage.isSelected())
{
states= states + 1 ;
}
  
if (peppers.isSelected())
{
states= states + 1 ;
}
if (olives.isSelected())
{
states= states + 1 ;
}
  
return states ;
}
}

----------------------------------------------------------------------------------------------------------------------------------

public class PizzeriaApp
{
public static void main(String[] args)
{
Pizzeria myFrame = new Pizzeria() ;
myFrame.setVisible(true) ;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote