Step 1: Extend the ItemToPurchase class per the following specifications: Private fields string itemDescription - Initialized in default constructor to "none" Parameterized constructor to assign item name, item description, item price, and item quantity.  Public member methods setDescription() mutator & getDescription() accessor  printItemCost() - Outputs the item name followed by the quantity, price, and subtotal printItemDescription() - Outputs the item name and description Ex. of PrintItemCost() output: Bottled Water 10 @ $1 = $10 Ex. of PrintItemDescription() output: Bottled Water: Deer Park, 12 oz. ShoppingCart.java - Class definition ShoppingCartManager.java - Contains main() method Build the ShoppingCart class with the following specifications. Private fields String customerName - Initialized in default constructor to "none" String currentDate - Initialized in default constructor to "January 1, 2016" ArrayList cartItems Default constructor Parameterized constructor which takes the customer name and date as parameters  Public member methods getCustomerName() accessor  getDate() accessor  addItem() Adds an item to cartItems array. Has a parameter of type ItemToPurchase. Does not return anything. removeItem() Removes item from cartItems array. Has a string (an item's name) parameter. Does not return anything. If item name cannot be found, output a message: Item not found in cart. Nothing removed. modifyItem() Modifies an item's description, price, and/or quantity. Has a parameter of type ItemToPurchase. Does not return anything. If item can be found (by name) in cart, check if parameter has default values for description, price, and quantity. If not, modify item in cart. If item cannot be found (by name) in cart, output a message: Item not found in cart. Nothing modified. getNumItemsInCart()  Returns quantity of all items in cart. Has no parameters. getCostOfCart()  Determines and returns the total cost of items in cart. Has no parameters. printTotal() Outputs total of objects in cart. If cart is empty, output a message: SHOPPING CART IS EMPTY printDescriptions() Outputs each item's description. If cart is empty, output a message: SHOPPING CART IS EMPTY Step 3: In main(), prompt the user for a customer's name and today's date. Output the name and date. Create an object of type ShoppingCart. Step 4: Implement the following menu functions in the ShoppingCartManager class printMenu() Prints the following menu of options to manipulate the shopping cart.  MENU a - Add item to cart d - Remove item from cart c - Change item quantity i - Output items' descriptions o - Output shopping cart q - Quit executeMenu() Takes 3 parameters: a character representing the user's choice, a shopping cart, and a Scanner object. Performs the menu options described below in step 5, according to the user's choice.  Step 5: Implement the menu options Step 5a: In main(), call printMenu() and prompt for the user's choice of menu options. Each option is represented by a single character. If an invalid character is entered, continue to prompt for a valid choice. When a valid option is entered, execute the option by calling executeMenu(). Then, print the menu and prompt for a new option. Continue until the user enters 'q'.  Hint: Implement Quit before implementing other options. Step 5b: Implement "Output shopping cart" menu option in executeMenu().  Step 5c: Implement "Output items' descriptions" menu option in executeMenu().  Step 5d: Implement "Add item to cart" menu option in executeMenu().  Ex: ADD ITEM TO CART Enter the item name: Nike Romaleos Enter the item description: Volt color, Weightlifting shoes Enter the item price: 189 Enter the item quantity: 2 Step 5e: Implement "Remove item from cart" menu option in executeMenu().  Ex: REMOVE ITEM FROM CART Enter name of item to remove: Chocolate Chips Step 5f: Implement "Change item quantity" menu option in executeMenu().  Hint: Make new ItemToPurchase object and use ItemToPurchase modifiers before using modifyItem() method.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Step 1: Extend the ItemToPurchase class per the following specifications:

  • Private fields
    • string itemDescription - Initialized in default constructor to "none"
  • Parameterized constructor to assign item name, item description, item price, and item quantity. 
  • Public member methods
    • setDescription() mutator & getDescription() accessor 
    • printItemCost() - Outputs the item name followed by the quantity, price, and subtotal
    • printItemDescription() - Outputs the item name and description

Ex. of PrintItemCost() output:

Bottled Water 10 @ $1 = $10

Ex. of PrintItemDescription() output:

Bottled Water: Deer Park, 12 oz.

  • ShoppingCart.java - Class definition
  • ShoppingCartManager.java - Contains main() method

Build the ShoppingCart class with the following specifications.

  • Private fields
    • String customerName - Initialized in default constructor to "none"
    • String currentDate - Initialized in default constructor to "January 1, 2016"
    • ArrayList cartItems
  • Default constructor
  • Parameterized constructor which takes the customer name and date as parameters 
  • Public member methods
    • getCustomerName() accessor 
    • getDate() accessor 
    • addItem()
      • Adds an item to cartItems array. Has a parameter of type ItemToPurchase. Does not return anything.
    • removeItem()
      • Removes item from cartItems array. Has a string (an item's name) parameter. Does not return anything.
      • If item name cannot be found, output a message: Item not found in cart. Nothing removed.
    • modifyItem()
      • Modifies an item's description, price, and/or quantity. Has a parameter of type ItemToPurchase. Does not return anything.
      • If item can be found (by name) in cart, check if parameter has default values for description, price, and quantity. If not, modify item in cart.
      • If item cannot be found (by name) in cart, output a message: Item not found in cart. Nothing modified.
    • getNumItemsInCart() 
      • Returns quantity of all items in cart. Has no parameters.
    • getCostOfCart() 
      • Determines and returns the total cost of items in cart. Has no parameters.
    • printTotal()
      • Outputs total of objects in cart.
      • If cart is empty, output a message: SHOPPING CART IS EMPTY
    • printDescriptions()
      • Outputs each item's description.
      • If cart is empty, output a message: SHOPPING CART IS EMPTY

        Step 3: In main(), prompt the user for a customer's name and today's date. Output the name and date. Create an object of type ShoppingCart.

        Step 4: Implement the following menu functions in the ShoppingCartManager class

        • printMenu()
          • Prints the following menu of options to manipulate the shopping cart. 
        MENU a - Add item to cart d - Remove item from cart c - Change item quantity i - Output items' descriptions o - Output shopping cart q - Quit
        • executeMenu()
          • Takes 3 parameters: a character representing the user's choice, a shopping cart, and a Scanner object. Performs the menu options described below in step 5, according to the user's choice. 

        Step 5: Implement the menu options

        Step 5a: In main(), call printMenu() and prompt for the user's choice of menu options. Each option is represented by a single character.

        If an invalid character is entered, continue to prompt for a valid choice. When a valid option is entered, execute the option by calling executeMenu(). Then, print the menu and prompt for a new option. Continue until the user enters 'q'. 

        Hint: Implement Quit before implementing other options.

        Step 5b: Implement "Output shopping cart" menu option in executeMenu(). 

        Step 5c: Implement "Output items' descriptions" menu option in executeMenu(). 

        Step 5d: Implement "Add item to cart" menu option in executeMenu(). 

        Ex:

        ADD ITEM TO CART Enter the item name: Nike Romaleos Enter the item description: Volt color, Weightlifting shoes Enter the item price: 189 Enter the item quantity: 2

        Step 5e: Implement "Remove item from cart" menu option in executeMenu(). 

        Ex:

        REMOVE ITEM FROM CART Enter name of item to remove: Chocolate Chips

        Step 5f: Implement "Change item quantity" menu option in executeMenu(). 

        Hint: Make new ItemToPurchase object and use ItemToPurchase modifiers before using modifyItem() method.

This image shows a snippet of Java code from a file named `ItemToPurchase.java`. Let's break down the code:

```java
public class ItemToPurchase {
    private String itemName;
    private int itemPrice;
    private int itemQuantity;

    // Default constructor
    public ItemToPurchase() {
        itemName = "none";
        itemPrice = 0;
        itemQuantity = 0;
    }

    // Mutator for itemName
    public void setName(String itemName) {
        this.itemName = itemName;
    }

    // Accessor for itemName
    public String getName() {
        return itemName;
    }
}
```

### Code Explanation
- **Class Declaration**: `public class ItemToPurchase` defines a public class named `ItemToPurchase`.
- **Private Fields**: 
  - `private String itemName;` declares a private variable `itemName` of type `String`.
  - `private int itemPrice;` declares a private integer variable `itemPrice`.
  - `private int itemQuantity;` declares a private integer variable `itemQuantity`.

- **Default Constructor**: 
  - `public ItemToPurchase()` is a default constructor that initializes `itemName` to `"none"`, `itemPrice` to `0`, and `itemQuantity` to `0`.

- **Mutator Method**:
  - `public void setName(String itemName)` is a method that sets the value of `itemName` to the provided parameter.

- **Accessor Method**:
  - `public String getName()` returns the value of `itemName`.

This class models an item to purchase, initializing its name, price, and quantity to default values and providing methods to access and modify the item's name.
Transcribed Image Text:This image shows a snippet of Java code from a file named `ItemToPurchase.java`. Let's break down the code: ```java public class ItemToPurchase { private String itemName; private int itemPrice; private int itemQuantity; // Default constructor public ItemToPurchase() { itemName = "none"; itemPrice = 0; itemQuantity = 0; } // Mutator for itemName public void setName(String itemName) { this.itemName = itemName; } // Accessor for itemName public String getName() { return itemName; } } ``` ### Code Explanation - **Class Declaration**: `public class ItemToPurchase` defines a public class named `ItemToPurchase`. - **Private Fields**: - `private String itemName;` declares a private variable `itemName` of type `String`. - `private int itemPrice;` declares a private integer variable `itemPrice`. - `private int itemQuantity;` declares a private integer variable `itemQuantity`. - **Default Constructor**: - `public ItemToPurchase()` is a default constructor that initializes `itemName` to `"none"`, `itemPrice` to `0`, and `itemQuantity` to `0`. - **Mutator Method**: - `public void setName(String itemName)` is a method that sets the value of `itemName` to the provided parameter. - **Accessor Method**: - `public String getName()` returns the value of `itemName`. This class models an item to purchase, initializing its name, price, and quantity to default values and providing methods to access and modify the item's name.
```java
// Mutator for itemPrice
public void setPrice(int itemPrice) {
    this.itemPrice = itemPrice;
}

// Accessor for itemPrice
public int getPrice() {
    return itemPrice;
}

// Mutator for itemQuantity
public void setQuantity(int itemQuantity) {
    this.itemQuantity = itemQuantity;
}

// Accessor for itemQuantity
public int getQuantity() {
    return itemQuantity;
}
```

### Explanation:

This code snippet demonstrates Java methods used for encapsulation, specifically getters and setters for managing the `itemPrice` and `itemQuantity` variables.

- **Mutator Methods (Setters):**
  - `setPrice(int itemPrice)`: Assigns the `itemPrice` value to the class's `itemPrice` variable.
  - `setQuantity(int itemQuantity)`: Assigns the `itemQuantity` value to the class's `itemQuantity` variable.

- **Accessor Methods (Getters):**
  - `getPrice()`: Returns the value of the `itemPrice` variable.
  - `getQuantity()`: Returns the value of the `itemQuantity` variable.

These methods provide controlled access to the private data of a class, following good encapsulation practices.
Transcribed Image Text:```java // Mutator for itemPrice public void setPrice(int itemPrice) { this.itemPrice = itemPrice; } // Accessor for itemPrice public int getPrice() { return itemPrice; } // Mutator for itemQuantity public void setQuantity(int itemQuantity) { this.itemQuantity = itemQuantity; } // Accessor for itemQuantity public int getQuantity() { return itemQuantity; } ``` ### Explanation: This code snippet demonstrates Java methods used for encapsulation, specifically getters and setters for managing the `itemPrice` and `itemQuantity` variables. - **Mutator Methods (Setters):** - `setPrice(int itemPrice)`: Assigns the `itemPrice` value to the class's `itemPrice` variable. - `setQuantity(int itemQuantity)`: Assigns the `itemQuantity` value to the class's `itemQuantity` variable. - **Accessor Methods (Getters):** - `getPrice()`: Returns the value of the `itemPrice` variable. - `getQuantity()`: Returns the value of the `itemQuantity` variable. These methods provide controlled access to the private data of a class, following good encapsulation practices.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 5 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education