5.12 Online shopping cart (Java) Create a program using classes that does the following in the zyLabs developer below. For this lab, you will be working with two different class files. To switch files, look for where it says "Current File" at the top of the developer window. Click the current file name, then select the file you need. (1) Create two files to submit: ItemToPurchase.java - Class definition ShoppingCartPrinter.java - Contains main() method Build the ItemToPurchase class with the following specifications: Private fields String itemName - Initialized in default constructor to "none" int itemPrice - Initialized in default constructor to 0 int itemQuantity - Initialized in default constructor to 0 Default constructor Public member methods (mutators & accessors) setName() & getName() (2 pts) setPrice() & getPrice() (2 pts) setQuantity() & getQuantity() (2 pts) (2) In main(), prompt the user for two items and create two objects of the ItemToPurchase class. Before prompting for the second item, call scnr.nextLine(); to allow the user to input a new string. (2 pts) Ex: Item 1 Enter the item name: Chocolate Chips Enter the item price: 3 Enter the item quantity: 1 Item 2 Enter the item name: Bottled Water Enter the item price: 1 Enter the item quantity: 10 (3) Add the costs of the two items together and output the total cost. (2 pts) Ex: TOTAL COST Chocolate Chips 1 @ $3 = $3 Bottled Water 10 @ $1 = $10 Total: $13 Here's the code I put in for ItemToPurchase.java public class ItemToPurchase { //Private fields - itemName, itemPrice, and itemQuanity private String itemName; private int itemPrice; private int itemQuantity; //Default Constructor public ItemToPurchase() { this.itemName = "none"; this.itemPrice = 0; this.itemQuantity = 0; } //public ItemToPurchase(String itemName, int itemPrice, int itemQuantity) { //this.itemName = itemName; //this.itemPrice = itemPrice; //this.itemQuantity = itemQuantity; //public member methods (mutators & accessors) //setName() & getName() public String getItemName() { return itemName; } public void setItemName(String itemName) { this.itemName = itemName; } //setPrice() & getPrice() public int getItemPrice() { return itemPrice; } public void setItemPrice(int itemPrice) { this.itemPrice = itemPrice; } //setQuantity() & getQuantity() public int getItemQuantity() { return itemQuantity; } public void setItemQuantity(int itemQuantity) { this.itemQuantity = itemQuantity; } } Heres the code I used for ShoppingCartPrinter.java import java.util.Scanner; public class ShoppingCartPrinter { public static void main(String[] args) { ItemToPurchase item1 = new ItemToPurchase(); ItemToPurchase item2 = new ItemToPurchase(); Scanner scnr = new Scanner(System.in); // Get item 1 details from user, create itemToPurchase object System.out.println("Item 1"); System.out.println("Enter the item name: "); item1.setItemName(scnr.nextLine()); System.out.println("Enter the item price: "); item1.setItemPrice(scnr.nextInt()); System.out.println("Enter the item quantity: "); item1.setItemQuantity(scnr.nextInt()); System.out.println(); scnr.nextLine(); // Get item 2 details from user, create itemToPurchase object System.out.println("Item 2"); System.out.println("Enter the item name: "); item2.setItemName(scnr.nextLine()); System.out.println("Enter the item price: "); item2.setItemPrice(scnr.nextInt()); System.out.println("Enter the item quantity: "); System.out.println(); item2.setItemQuantity(scnr.nextInt()); // Add costs of two items and print total // cartTotal = item one price + item two price // Total Cost // item one information // item two information // Total output int totalItem1 = item1.getItemPrice() * item1.getItemQuantity(); int totalItem2 = item2.getItemPrice() * item2.getItemQuantity(); int total = totalItem1 + totalItem2; System.out.println("TOTAL COST"); System.out.println(item1.getItemName() + " " + item1.getItemQuantity() + " @ $" + item1.getItemPrice() + " = $" + totalItem1); System.out.println(item2.getItemName() + " " + item2.getItemQuantity() + " @ $" + item2.getItemPrice() + " = $" + totalItem2); System.out.println(); System.out.println("Total: $" + total); } } When I used this code, I got some points but some tests I didn't pass and I need to know how to fix my code to pass those tests. Here are two of the tests I did not pass.

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

5.12 Online shopping cart (Java)

 

Create a program using classes that does the following in the zyLabs developer below. For this lab, you will be working with two different class files. To switch files, look for where it says "Current File" at the top of the developer window. Click the current file name, then select the file you need.

(1) Create two files to submit:

  • ItemToPurchase.java - Class definition
  • ShoppingCartPrinter.java - Contains main() method

Build the ItemToPurchase class with the following specifications:

  • Private fields
    • String itemName - Initialized in default constructor to "none"
    • int itemPrice - Initialized in default constructor to 0
    • int itemQuantity - Initialized in default constructor to 0
  • Default constructor
  • Public member methods (mutators & accessors)
    • setName() & getName() (2 pts)
    • setPrice() & getPrice() (2 pts)
    • setQuantity() & getQuantity() (2 pts)

(2) In main(), prompt the user for two items and create two objects of the ItemToPurchase class. Before prompting for the second item, call scnr.nextLine(); to allow the user to input a new string. (2 pts)

Ex:

Item 1
Enter the item name: Chocolate Chips
Enter the item price: 3
Enter the item quantity: 1
 
Item 2
Enter the item name:
Bottled Water
Enter the item price: 1
Enter the item quantity: 10


(3) Add the costs of the two items together and output the total cost. (2 pts)

Ex:

TOTAL COST
Chocolate Chips 1 @ $3 = $3
Bottled Water 10 @ $1 = $10
Total: $13
 
 
Here's the code I put in for ItemToPurchase.java
public class ItemToPurchase {
   //Private fields - itemName, itemPrice, and itemQuanity
   private String itemName;
   private int itemPrice;
   private int itemQuantity;
   
   //Default Constructor
   public ItemToPurchase() {
      this.itemName = "none";
      this.itemPrice = 0;
      this.itemQuantity = 0;
   }
   
   //public ItemToPurchase(String itemName, int itemPrice, int itemQuantity) {
      //this.itemName = itemName;
      //this.itemPrice = itemPrice;
      //this.itemQuantity = itemQuantity;
   
   
    
   //public member methods (mutators & accessors)
   //setName() & getName() 
   public String getItemName() {
      return itemName;
   }
   public void setItemName(String itemName) {
      this.itemName = itemName;
   }
   
   //setPrice() & getPrice() 
   public int getItemPrice() {
      return itemPrice;
   }
   public void setItemPrice(int itemPrice) {
      this.itemPrice = itemPrice;
   }
   //setQuantity() & getQuantity() 
   public int getItemQuantity() {
      return itemQuantity;
   }
   public void setItemQuantity(int itemQuantity) {
      this.itemQuantity = itemQuantity;
   }
}
Heres the code I used for ShoppingCartPrinter.java

import java.util.Scanner;

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

      // Get item 1 details from user, create itemToPurchase object
      System.out.println("Item 1");
      System.out.println("Enter the item name: ");
      item1.setItemName(scnr.nextLine());
      System.out.println("Enter the item price: ");
      item1.setItemPrice(scnr.nextInt());
      System.out.println("Enter the item quantity: ");
      item1.setItemQuantity(scnr.nextInt());
      System.out.println();
      scnr.nextLine();
      
 
      // Get item 2 details from user, create itemToPurchase object
      System.out.println("Item 2");
      System.out.println("Enter the item name: ");
    
      item2.setItemName(scnr.nextLine());
      System.out.println("Enter the item price: ");
     
      item2.setItemPrice(scnr.nextInt());
      System.out.println("Enter the item quantity: ");
      System.out.println();
      item2.setItemQuantity(scnr.nextInt());
      
      // Add costs of two items and print total
      // cartTotal = item one price + item two price
      // Total Cost
      // item one information
      // item two information
      // Total output
      int totalItem1 = item1.getItemPrice() * item1.getItemQuantity();
      int totalItem2 = item2.getItemPrice() * item2.getItemQuantity();
      int total = totalItem1 + totalItem2;
      
      System.out.println("TOTAL COST");
      System.out.println(item1.getItemName() + " " + item1.getItemQuantity() + " @ $" + item1.getItemPrice() + " = $" + totalItem1);
      System.out.println(item2.getItemName() + " " + item2.getItemQuantity() + " @ $" + item2.getItemPrice() + " = $" + totalItem2);
      System.out.println();
      System.out.println("Total: $" + total);
   }
}

When I used this code, I got some points but some tests I didn't pass and I need to know how to fix my code to pass those tests. Here are two of the tests I did not pass.
 
 
1: Unit test
Tests item.setName("Chocolate Chips") and item.GetName() == "Chocolate Chips"
Compilation failed
Compilation failed
zyLabs UnitTest.java:6: error: cannot find symbol
item.setName ("Chocolate Chips");
symbol: method setName (String)
location: variable item of type ItemTo Purchase
zyLabs UnitTest.java:8: error: cannot find symbol
if (item.getName() "Chocolate Chips") {
==
symbol: method getName()
location: variable item of type ItemToPurchase
zyLabs UnitTest.java:14: error: cannot find symbol
System.out.println("Incorrect name returned: + item.getName()
symbol: method getName()
location: variable item of type ItemToPurchase
3 errors
0/2
"1
Transcribed Image Text:1: Unit test Tests item.setName("Chocolate Chips") and item.GetName() == "Chocolate Chips" Compilation failed Compilation failed zyLabs UnitTest.java:6: error: cannot find symbol item.setName ("Chocolate Chips"); symbol: method setName (String) location: variable item of type ItemTo Purchase zyLabs UnitTest.java:8: error: cannot find symbol if (item.getName() "Chocolate Chips") { == symbol: method getName() location: variable item of type ItemToPurchase zyLabs UnitTest.java:14: error: cannot find symbol System.out.println("Incorrect name returned: + item.getName() symbol: method getName() location: variable item of type ItemToPurchase 3 errors 0/2 "1
2: Unit test ^
Tests item.setPrice(3) and item.getPrice() == 3
Compilation failed
Compilation failed
zyLabs UnitTest.java:6: error: cannot find symbol
item.setPrice (3);
symbol: method set Price (int)
location: variable item of type ItemToPurchase
zyLabs UnitTest.java:8: error: cannot find symbol
if (item.getPrice ()
3) {
==
symbol: method getPrice ()
location : variable item of type ItemToPurchase
zyLabs UnitTest.java:14: error: cannot find symbol
System.out.println("Incorrect price returned:
symbol: method getPrice ()
location: variable item of type ItemToPurchase
3 errors
0/2
+ item.getPrice
Transcribed Image Text:2: Unit test ^ Tests item.setPrice(3) and item.getPrice() == 3 Compilation failed Compilation failed zyLabs UnitTest.java:6: error: cannot find symbol item.setPrice (3); symbol: method set Price (int) location: variable item of type ItemToPurchase zyLabs UnitTest.java:8: error: cannot find symbol if (item.getPrice () 3) { == symbol: method getPrice () location : variable item of type ItemToPurchase zyLabs UnitTest.java:14: error: cannot find symbol System.out.println("Incorrect price returned: symbol: method getPrice () location: variable item of type ItemToPurchase 3 errors 0/2 + item.getPrice
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
Array
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
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