Question: I keep getting this error for my Java code (see below) I have copied and pasted the code below the error message. I have made

I keep getting this error for my Java code (see below) I have copied and pasted the code below the error message. I have made the line bold for easier visualization.

I keep getting this error for my Java code (see below) I

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

public ItemToPurchase() { }

public String getName() { return itemName; }

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

public int getPrice() { return itemPrice; }

public void setPrice(int itemPrice) { this.itemPrice = itemPrice; }

public int getQuantity() { return itemQuantity; }

public void setQuantity(int itemQuantity) { this.itemQuantity = itemQuantity; } } public class ShoppingCartPrinter { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String name; int price,quantity,total1,total2; System.out.println("Item 1"); System.out.print("Enter the item name: "); name = scnr.nextLine(); System.out.print("Enter the item price: "); price = scnr.nextInt(); System.out.print("Enter the item quantity: "); quantity = scnr.nextInt(); ItemToPurchase itemToPurchase1 = new ItemToPurchase(); itemToPurchase1.setQuantity(quantity); itemToPurchase1.setName(name); itemToPurchase1.setPrice(price); total1=itemToPurchase1.getPrice()*itemToPurchase1.getQuantity(); System.out.println(); scnr.nextLine(); System.out.println("Item 2"); System.out.print("Enter the item name: "); name = scnr.nextLine(); System.out.print("Enter the item price: "); price = scnr.nextInt(); System.out.print("Enter the item quantity: "); quantity = scnr.nextInt(); ItemToPurchase itemToPurchase2 = new ItemToPurchase(); itemToPurchase2.setQuantity(quantity); itemToPurchase2.setName(name); itemToPurchase2.setPrice(price); total2=itemToPurchase2.getPrice()*itemToPurchase2.getQuantity(); //System.out.println();//uncomment this line if a newline is required before TOTAL COST System.out.println("TOTAL COST"); System.out.println(itemToPurchase1.getName()+" "+itemToPurchase1.getQuantity()+" @ $"+itemToPurchase1.getPrice()+" = $"+total1); System.out.println(itemToPurchase2.getName()+" "+itemToPurchase2.getQuantity()+" @ $"+itemToPurchase2.getPrice()+" = $"+total2); System.out.println(" Total: $"+(total1+total2));

} }

ShoppingCartPrinter.java:29: error: reached end of file while parsing } 1 error

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!