Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions