title: Online shopping cart java
body: <p>I'm having a hard time figuring out why this code is not adding up at the end in "TOTAL COST".</p>
  
  <p>Two classes:  </p>
  
  <p>ShoppingCartPrinter.java and ItemToPurchase.java</p>
  
  <p>The result I keep getting are all 0's in "TOTAL COST".  Any help would be greatly appreciated.  Thanks.</p>
  
  <p>ShoppingCartPrinter.java code:  </p>
  
  <pre><code>import java.util.Scanner;
  
  public class ShoppingCartPrinter {
    public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    int i = 0;
    String productName;
    int productPrice = 0;
    int productQuantity = 0;
    int cartTotal = 0;
  
    ItemToPurchase item1 = new ItemToPurchase();
    ItemToPurchase item2 = new ItemToPurchase();
  
    System.out.println("Item 1");
    System.out.println("Enter the item name: ");
    productName = scnr.nextLine();                                         // Sets the variable productName for user input
  
    System.out.println("Enter the item price: ");
    productPrice = scnr.nextInt();                                         // Set the variable productPrice for user input
  
    System.out.println("Enter the item quantity: ");
    productQuantity = scnr.nextInt();                                      // Set the variable productQuantity for user user input
    System.out.println("");
  
    item1.setName(productName);
    item1.setPrice(productPrice);
    item1.setQuantity(productQuantity);
  
    System.out.println("Item 2");
    System.out.println("Enter the item name: ");
    scnr.nextLine();
    productName = scnr.nextLine();                                         // Set the variable productName for user input
  
    System.out.println("Enter the item price: ");
    productPrice = scnr.nextInt();                                         // Set the variable productPrice for user input
  
    System.out.println("Enter the item quantity: ");
    productQuantity = scnr.nextInt();                                      // Set the variable productQuantity for user input
    System.out.println("");
  
    item2.setName(productName);
    item2.setPrice(productPrice);
    item2.setQuantity(productQuantity);
  
    cartTotal = (item1.getPrice() * item1.getQuantity()) + (item2.getPrice() * item2.getQuantity());
  
    System.out.println("TOTAL COST");
    System.out.println(item1.getName() + " " + item1.getQuantity() + " @ $" + item1.getPrice()  + " = $" + (item1.getPrice() * item1.getQuantity()));
  
    System.out.println(item2.getName() + " " + item2.getQuantity() + " @ $" + item2.getPrice()  + " = $" + (item2.getPrice() * item2.getQuantity()));
    System.out.println("");
  
    System.out.println("Total: $" + cartTotal);
  
    return;
     }
  }
  </code></pre>
  
  <p>ItemToPurchase.java</p>
  
  <pre><code>public class ItemToPurchase {
     private String itemName;
     private int itemPrice;
     private int itemQuantity;
  
  public ItemToPurchase() {
    itemName = "none";
    itemPrice = 0;
    itemQuantity = 0;
    return;
  }
  
  public void setName(String name) {
    itemName = name;
    return;
  }
  
  public void setPrice(int price) {
     itemPrice = 0;
     return;
  }
  
  public void setQuantity (int quantity) {
     itemQuantity = 0;
     return;       
  }
  
  public String getName() {
    return itemName;
  }
  
  public int getPrice() {
    return itemPrice;
  }
  
  public int getQuantity() {
     return itemQuantity;
  }
  
  public void printItemPurchase() {
    System.out.println(itemQuantity + " " + itemName + " $" + itemPrice +  " = $" + (itemPrice * itemQuantity));
  }
  } 
  </code></pre>