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;     }     // 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;     } } import java.util.Scanner; public class ShoppingCartPrinter {    public static void main(String[] args) {       Scanner scnr = new Scanner(System.in);      // Creating instances of ItemToPurchase         ItemToPurchase item1 = new ItemToPurchase();         ItemToPurchase item2 = new ItemToPurchase();         // Setting properties for item1         item1.setName("Laptop");         item1.setPrice(800);         item1.setQuantity(2);         // Setting properties for item2         item2.setName("Mouse");         item2.setPrice(20);         item2.setQuantity(5);         // Displaying item information         System.out.println("Item 1:");         System.out.println("Name: " + item1.getName());         System.out.println("Price: $" + item1.getPrice());         System.out.println("Quantity: " + item1.getQuantity());         System.out.println("Total Cost: $" + item1.getPrice() * item1.getQuantity());         System.out.println();         System.out.println("Item 2:");         System.out.println("Name: " + item2.getName());         System.out.println("Price: $" + item2.getPrice());         System.out.println("Quantity: " + item2.getQuantity());         System.out.println("Total Cost: $" + item2.getPrice() * item2.getQuantity());     } }

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

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;
    }

    // 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;
    }
}

import java.util.Scanner;

public class ShoppingCartPrinter {
   public static void main(String[] args) {
      Scanner scnr = new Scanner(System.in);

     // Creating instances of ItemToPurchase
        ItemToPurchase item1 = new ItemToPurchase();
        ItemToPurchase item2 = new ItemToPurchase();

        // Setting properties for item1
        item1.setName("Laptop");
        item1.setPrice(800);
        item1.setQuantity(2);

        // Setting properties for item2
        item2.setName("Mouse");
        item2.setPrice(20);
        item2.setQuantity(5);

        // Displaying item information
        System.out.println("Item 1:");
        System.out.println("Name: " + item1.getName());
        System.out.println("Price: $" + item1.getPrice());
        System.out.println("Quantity: " + item1.getQuantity());
        System.out.println("Total Cost: $" + item1.getPrice() * item1.getQuantity());
        System.out.println();

        System.out.println("Item 2:");
        System.out.println("Name: " + item2.getName());
        System.out.println("Price: $" + item2.getPrice());
        System.out.println("Quantity: " + item2.getQuantity());
        System.out.println("Total Cost: $" + item2.getPrice() * item2.getQuantity());
    }
}

### Educational Website Transcription

#### Input Section
- **Chocolate Chips**  
  - Quantity: 3  
  - Unit Price: 1  

- **Bottled Water**  
  - Quantity: 1  
  - Unit Price: 10  

#### Your Output Section
- **Item 1:**
  - **Name:** Laptop
  - **Price:** $800
  - **Quantity:** 2
  - **Total Cost:** $1600

- **Item 2:**
  - **Name:** Mouse
  - **Price:** $20
  - **Quantity:** 5
  - **Total Cost:** $100

#### Expected Output Section
- **Item 1:**
  - Enter the item name:
  - Enter the item price:
  - Enter the item quantity:

- **Item 2:**
  - Enter the item name:
  - Enter the item price:
  - Enter the item quantity:

### Explanation
The image displays different sections showing input items, your program's current output, and the expected output format. 

- **Input Section:** Lists initial items with their quantities and prices.
- **Your Output Section:** Shows what your program currently outputs after processing inputs.
- **Expected Output Section:** This format should be used to prompt for item details, helping to structure data entry correctly.

The diagram is essentially a comparison between expected results and current functionality. This is useful for debugging or learning the correct output structure.
Transcribed Image Text:### Educational Website Transcription #### Input Section - **Chocolate Chips** - Quantity: 3 - Unit Price: 1 - **Bottled Water** - Quantity: 1 - Unit Price: 10 #### Your Output Section - **Item 1:** - **Name:** Laptop - **Price:** $800 - **Quantity:** 2 - **Total Cost:** $1600 - **Item 2:** - **Name:** Mouse - **Price:** $20 - **Quantity:** 5 - **Total Cost:** $100 #### Expected Output Section - **Item 1:** - Enter the item name: - Enter the item price: - Enter the item quantity: - **Item 2:** - Enter the item name: - Enter the item price: - Enter the item quantity: ### Explanation The image displays different sections showing input items, your program's current output, and the expected output format. - **Input Section:** Lists initial items with their quantities and prices. - **Your Output Section:** Shows what your program currently outputs after processing inputs. - **Expected Output Section:** This format should be used to prompt for item details, helping to structure data entry correctly. The diagram is essentially a comparison between expected results and current functionality. This is useful for debugging or learning the correct output structure.
### Input

- Product Name: Chocolate Chips
- Price per unit: 3
- Quantity: 1
- Product Name: Bottled Water
- Price per unit: 1
- Quantity: 10

### Your Output

#### Item 1:
- Name: Laptop
- Price: $800
- Quantity: 2
- Total Cost: $1600

#### Item 2:
- Name: Mouse
- Price: $20
- Quantity: 5
- Total Cost: $100

### Expected Output

#### Item 1:
- Enter the item name:
- Enter the item price:
- Enter the item quantity:

#### Item 2:
- Enter the item name:
- Enter the item price:
- Enter the item quantity:

#### Total Cost:
- Chocolate Chips 1 @ $3 = $3
- Bottled Water 10 @ $1 = $10

**Total:** $13

### Explanation

This illustration involves a simple input and output program dealing with itemized purchases.

- **Input Section:** Shows the data inputted for two items, Chocolate Chips and Bottled Water, including their respective prices per unit and quantities.
  
- **Your Output Section:** Demonstrates a mismatch, likely due to incorrect item entries labeled as Laptop and Mouse, with both the quantities and total costs calculated incorrectly based on the expected input. 

- **Expected Output Section:** Displays the correct prompt and computation format expected from the program. The total cost sums up the individual totals of the given items, producing the final total of $13.

The example illustrates the necessity for precise data entry and adherence to expected input formats for correct computational outcomes in programming environments, specifically related to itemized costs and sales.
Transcribed Image Text:### Input - Product Name: Chocolate Chips - Price per unit: 3 - Quantity: 1 - Product Name: Bottled Water - Price per unit: 1 - Quantity: 10 ### Your Output #### Item 1: - Name: Laptop - Price: $800 - Quantity: 2 - Total Cost: $1600 #### Item 2: - Name: Mouse - Price: $20 - Quantity: 5 - Total Cost: $100 ### Expected Output #### Item 1: - Enter the item name: - Enter the item price: - Enter the item quantity: #### Item 2: - Enter the item name: - Enter the item price: - Enter the item quantity: #### Total Cost: - Chocolate Chips 1 @ $3 = $3 - Bottled Water 10 @ $1 = $10 **Total:** $13 ### Explanation This illustration involves a simple input and output program dealing with itemized purchases. - **Input Section:** Shows the data inputted for two items, Chocolate Chips and Bottled Water, including their respective prices per unit and quantities. - **Your Output Section:** Demonstrates a mismatch, likely due to incorrect item entries labeled as Laptop and Mouse, with both the quantities and total costs calculated incorrectly based on the expected input. - **Expected Output Section:** Displays the correct prompt and computation format expected from the program. The total cost sums up the individual totals of the given items, producing the final total of $13. The example illustrates the necessity for precise data entry and adherence to expected input formats for correct computational outcomes in programming environments, specifically related to itemized costs and sales.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 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