Question
import java.util.Scanner; public class ItemToPurchase { private String itemName; private int itemPrice; private int itemQuantity; public ItemToPurchase() { itemName = none; itemPrice = 0; itemQuantity
import java.util.Scanner; public class ItemToPurchase { private String itemName; private int itemPrice; private int itemQuantity; public ItemToPurchase() { itemName = "none"; itemPrice = 0; itemQuantity = 0; } public void setName(String name) { itemName = name; } public String getName() { return itemName; } public void setPrice(int price) { itemPrice = price; } public int getPrice() { return itemPrice; } public void setQuantity(int quantity) { itemQuantity = quantity; } public int getQuantity() { return itemQuantity; } } } public class ShoppingCartPrinter { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); ItemToPurchase item1 = new ItemToPurchase(); ItemToPurchase item2 = new ItemToPurchase(); String name; int price; int quantity; System.out.println("Item 1"); System.out.print("Enter the item name: "); name = scnr.nextLine(); item1.setName(name); System.out.print("Enter the item price: "); price = scnr.nextInt(); item1.setPrice(price); System.out.print("Enter the item quantity: "); quantity = scnr.nextInt(); item1.setQuantity(quantity); scnr.nextLine(); // to allow the user to input a new string System.out.println(" Item 2"); System.out.print("Enter the item name: "); name = scnr.nextLine(); item2.setName(name); System.out.print("Enter the item price: "); price = scnr.nextInt(); item2.setPrice(price); System.out.print("Enter the item quantity: "); quantity = scnr.nextInt(); item2.setQuantity(quantity); } }
//my errors ItemToPurchase.java:38: error: class, interface, or enum expected } ^ ShoppingCartPrinter.java:29: error: reached end of file while parsing } ^ 2 errors
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started