Shopping Cart using two files (class and main method) Java










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()

-setPrice() & getPrice()

-setQuantity() & getQuantity()




-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.



-Add the costs of the two items together and output the total cost.



Below is my code for ShoppingCartPrinter:




 public static void main(String args) 
Scanner scnr = new Scanner(System.in);
ItemToPurchase item1 = new ItemToPurchase();
ItemToPurchase item2 = new ItemToPurchase();

//String inputName = "";
//int inputPrice = 0;
//int inputQuantity = 0;

item1.setName("testName");
item1.setQuantity(1);
item1.setPrice(1);

String itemName = item1.getName();
int itemQuantity = item1.getQuantity();
int itemPrice = item1.getPrice();

System.out.println(itemName);
System.out.println(itemPrice);
System.out.println(itemQuantity);


//Add the costs of the two items together and output the total cost.
}


Below is my code for ItemToPurchase:




 public class ItemToPurchase 

// The class' private internal fields
private String itemName;
private int itemPrice;
private int itemQuantity;

// The class' public methods

public void setName(String inputName)
itemName = inputName;

public String getName()
return itemName;

public void setPrice(int inputPrice)
itemPrice = inputPrice;

public int getPrice()
return itemPrice;

public void setQuantity(int inputQuantity)
itemQuantity = inputQuantity;

public int getQuantity()
return itemQuantity;




I getting more and more confused as I look for resources to help me and haven't heard back from my Professor. The code builds without errors but doesn't copy. This is he error I am getting:
enter image description here










share|improve this question























  • I have a hard time understanding the core of your question. Your code looks fine so far; but I am not exactly sure what ANT is supposed to do here. Step number one would be: you run javac manually, and then try to run your main method manually using java. And: you got why to many tags on your question.
    – GhostCat
    Sep 30 '16 at 19:21










  • I am confused on why it won't print out the values for Name, Price, and Quantity. When I build in NetBeans no errors come up but there is nothing to copying. Up until this point my class has only has us writing code in the main but now they want us to use multiple classes.
    – Casey Vanecek
    Sep 30 '16 at 19:38











  • As said: try to step away from your IDE. Run the command line tools to avoid that additional complexity of netbeans.
    – GhostCat
    Sep 30 '16 at 19:39










  • Your screengrab shows you compiling your code, but I don't see where it actually tried to start running it.
    – Joe C
    Sep 30 '16 at 20:12










  • When I run the code I am getting an error when it is asking for item two's price. It jumps from name to price so I cannot put the name in..
    – Casey Vanecek
    Sep 30 '16 at 20:27















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()

-setPrice() & getPrice()

-setQuantity() & getQuantity()




-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.



-Add the costs of the two items together and output the total cost.



Below is my code for ShoppingCartPrinter:




 public static void main(String args) 
Scanner scnr = new Scanner(System.in);
ItemToPurchase item1 = new ItemToPurchase();
ItemToPurchase item2 = new ItemToPurchase();

//String inputName = "";
//int inputPrice = 0;
//int inputQuantity = 0;

item1.setName("testName");
item1.setQuantity(1);
item1.setPrice(1);

String itemName = item1.getName();
int itemQuantity = item1.getQuantity();
int itemPrice = item1.getPrice();

System.out.println(itemName);
System.out.println(itemPrice);
System.out.println(itemQuantity);


//Add the costs of the two items together and output the total cost.
}


Below is my code for ItemToPurchase:




 public class ItemToPurchase 

// The class' private internal fields
private String itemName;
private int itemPrice;
private int itemQuantity;

// The class' public methods

public void setName(String inputName)
itemName = inputName;

public String getName()
return itemName;

public void setPrice(int inputPrice)
itemPrice = inputPrice;

public int getPrice()
return itemPrice;

public void setQuantity(int inputQuantity)
itemQuantity = inputQuantity;

public int getQuantity()
return itemQuantity;




I getting more and more confused as I look for resources to help me and haven't heard back from my Professor. The code builds without errors but doesn't copy. This is he error I am getting:
enter image description here










share|improve this question























  • I have a hard time understanding the core of your question. Your code looks fine so far; but I am not exactly sure what ANT is supposed to do here. Step number one would be: you run javac manually, and then try to run your main method manually using java. And: you got why to many tags on your question.
    – GhostCat
    Sep 30 '16 at 19:21










  • I am confused on why it won't print out the values for Name, Price, and Quantity. When I build in NetBeans no errors come up but there is nothing to copying. Up until this point my class has only has us writing code in the main but now they want us to use multiple classes.
    – Casey Vanecek
    Sep 30 '16 at 19:38











  • As said: try to step away from your IDE. Run the command line tools to avoid that additional complexity of netbeans.
    – GhostCat
    Sep 30 '16 at 19:39










  • Your screengrab shows you compiling your code, but I don't see where it actually tried to start running it.
    – Joe C
    Sep 30 '16 at 20:12










  • When I run the code I am getting an error when it is asking for item two's price. It jumps from name to price so I cannot put the name in..
    – Casey Vanecek
    Sep 30 '16 at 20:27













1












1








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()

-setPrice() & getPrice()

-setQuantity() & getQuantity()




-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.



-Add the costs of the two items together and output the total cost.



Below is my code for ShoppingCartPrinter:




 public static void main(String args) 
Scanner scnr = new Scanner(System.in);
ItemToPurchase item1 = new ItemToPurchase();
ItemToPurchase item2 = new ItemToPurchase();

//String inputName = "";
//int inputPrice = 0;
//int inputQuantity = 0;

item1.setName("testName");
item1.setQuantity(1);
item1.setPrice(1);

String itemName = item1.getName();
int itemQuantity = item1.getQuantity();
int itemPrice = item1.getPrice();

System.out.println(itemName);
System.out.println(itemPrice);
System.out.println(itemQuantity);


//Add the costs of the two items together and output the total cost.
}


Below is my code for ItemToPurchase:




 public class ItemToPurchase 

// The class' private internal fields
private String itemName;
private int itemPrice;
private int itemQuantity;

// The class' public methods

public void setName(String inputName)
itemName = inputName;

public String getName()
return itemName;

public void setPrice(int inputPrice)
itemPrice = inputPrice;

public int getPrice()
return itemPrice;

public void setQuantity(int inputQuantity)
itemQuantity = inputQuantity;

public int getQuantity()
return itemQuantity;




I getting more and more confused as I look for resources to help me and haven't heard back from my Professor. The code builds without errors but doesn't copy. This is he error I am getting:
enter image description here










share|improve this question















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()

-setPrice() & getPrice()

-setQuantity() & getQuantity()




-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.



-Add the costs of the two items together and output the total cost.



Below is my code for ShoppingCartPrinter:




 public static void main(String args) 
Scanner scnr = new Scanner(System.in);
ItemToPurchase item1 = new ItemToPurchase();
ItemToPurchase item2 = new ItemToPurchase();

//String inputName = "";
//int inputPrice = 0;
//int inputQuantity = 0;

item1.setName("testName");
item1.setQuantity(1);
item1.setPrice(1);

String itemName = item1.getName();
int itemQuantity = item1.getQuantity();
int itemPrice = item1.getPrice();

System.out.println(itemName);
System.out.println(itemPrice);
System.out.println(itemQuantity);


//Add the costs of the two items together and output the total cost.
}


Below is my code for ItemToPurchase:




 public class ItemToPurchase 

// The class' private internal fields
private String itemName;
private int itemPrice;
private int itemQuantity;

// The class' public methods

public void setName(String inputName)
itemName = inputName;

public String getName()
return itemName;

public void setPrice(int inputPrice)
itemPrice = inputPrice;

public int getPrice()
return itemPrice;

public void setQuantity(int inputQuantity)
itemQuantity = inputQuantity;

public int getQuantity()
return itemQuantity;




I getting more and more confused as I look for resources to help me and haven't heard back from my Professor. The code builds without errors but doesn't copy. This is he error I am getting:
enter image description here







java






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 30 '16 at 19:21









GhostCat

88.1k1684144




88.1k1684144










asked Sep 30 '16 at 19:16









Casey Vanecek

233




233











  • I have a hard time understanding the core of your question. Your code looks fine so far; but I am not exactly sure what ANT is supposed to do here. Step number one would be: you run javac manually, and then try to run your main method manually using java. And: you got why to many tags on your question.
    – GhostCat
    Sep 30 '16 at 19:21










  • I am confused on why it won't print out the values for Name, Price, and Quantity. When I build in NetBeans no errors come up but there is nothing to copying. Up until this point my class has only has us writing code in the main but now they want us to use multiple classes.
    – Casey Vanecek
    Sep 30 '16 at 19:38











  • As said: try to step away from your IDE. Run the command line tools to avoid that additional complexity of netbeans.
    – GhostCat
    Sep 30 '16 at 19:39










  • Your screengrab shows you compiling your code, but I don't see where it actually tried to start running it.
    – Joe C
    Sep 30 '16 at 20:12










  • When I run the code I am getting an error when it is asking for item two's price. It jumps from name to price so I cannot put the name in..
    – Casey Vanecek
    Sep 30 '16 at 20:27
















  • I have a hard time understanding the core of your question. Your code looks fine so far; but I am not exactly sure what ANT is supposed to do here. Step number one would be: you run javac manually, and then try to run your main method manually using java. And: you got why to many tags on your question.
    – GhostCat
    Sep 30 '16 at 19:21










  • I am confused on why it won't print out the values for Name, Price, and Quantity. When I build in NetBeans no errors come up but there is nothing to copying. Up until this point my class has only has us writing code in the main but now they want us to use multiple classes.
    – Casey Vanecek
    Sep 30 '16 at 19:38











  • As said: try to step away from your IDE. Run the command line tools to avoid that additional complexity of netbeans.
    – GhostCat
    Sep 30 '16 at 19:39










  • Your screengrab shows you compiling your code, but I don't see where it actually tried to start running it.
    – Joe C
    Sep 30 '16 at 20:12










  • When I run the code I am getting an error when it is asking for item two's price. It jumps from name to price so I cannot put the name in..
    – Casey Vanecek
    Sep 30 '16 at 20:27















I have a hard time understanding the core of your question. Your code looks fine so far; but I am not exactly sure what ANT is supposed to do here. Step number one would be: you run javac manually, and then try to run your main method manually using java. And: you got why to many tags on your question.
– GhostCat
Sep 30 '16 at 19:21




I have a hard time understanding the core of your question. Your code looks fine so far; but I am not exactly sure what ANT is supposed to do here. Step number one would be: you run javac manually, and then try to run your main method manually using java. And: you got why to many tags on your question.
– GhostCat
Sep 30 '16 at 19:21












I am confused on why it won't print out the values for Name, Price, and Quantity. When I build in NetBeans no errors come up but there is nothing to copying. Up until this point my class has only has us writing code in the main but now they want us to use multiple classes.
– Casey Vanecek
Sep 30 '16 at 19:38





I am confused on why it won't print out the values for Name, Price, and Quantity. When I build in NetBeans no errors come up but there is nothing to copying. Up until this point my class has only has us writing code in the main but now they want us to use multiple classes.
– Casey Vanecek
Sep 30 '16 at 19:38













As said: try to step away from your IDE. Run the command line tools to avoid that additional complexity of netbeans.
– GhostCat
Sep 30 '16 at 19:39




As said: try to step away from your IDE. Run the command line tools to avoid that additional complexity of netbeans.
– GhostCat
Sep 30 '16 at 19:39












Your screengrab shows you compiling your code, but I don't see where it actually tried to start running it.
– Joe C
Sep 30 '16 at 20:12




Your screengrab shows you compiling your code, but I don't see where it actually tried to start running it.
– Joe C
Sep 30 '16 at 20:12












When I run the code I am getting an error when it is asking for item two's price. It jumps from name to price so I cannot put the name in..
– Casey Vanecek
Sep 30 '16 at 20:27




When I run the code I am getting an error when it is asking for item two's price. It jumps from name to price so I cannot put the name in..
– Casey Vanecek
Sep 30 '16 at 20:27












1 Answer
1






active

oldest

votes


















0














For the ShoppingCartPrinter, this works:



import java.util.Scanner;

class ShoppingCartPrinter

public static void main(String args)

Scanner scnr = new Scanner(System.in);
String item1 = "";
String item2 = "";
int price1 = 0;
int price2 = 0;
int quantity1 = 0;
int quantity2 = 0;

ItemToPurchase itemInfo1 = new ItemToPurchase();
ItemToPurchase itemInfo2 = new ItemToPurchase();

System.out.println("Item 1");
System.out.println("Enter the item name:");
itemInfo1.setName(scnr.nextLine());

System.out.println("Enter the item price:");
itemInfo1.setPrice(scnr.nextInt());

System.out.println("Enter the item quantity:");
itemInfo1.setQuantity(scnr.nextInt());
System.out.println();

System.out.println("Item 2");
itemInfo2.setName(scnr.nextLine());
System.out.println("Enter the item name:");
itemInfo2.setName(scnr.nextLine());

System.out.println("Enter the item price:");
itemInfo2.setPrice(scnr.nextInt());

System.out.println("Enter the item quantity:");
itemInfo2.setQuantity(scnr.nextInt());
System.out.println();

System.out.println("TOTAL COST");

System.out.println(itemInfo1.getName() + " " + itemInfo1.getQuantity() + " @ $" + itemInfo1.getPrice() + " = $" + (itemInfo1.getPrice() * itemInfo1.getQuantity()));

System.out.println(itemInfo2.getName() + " " + itemInfo2.getQuantity() + " @ $" + itemInfo2.getPrice() + " = $" + (itemInfo2.getPrice() * itemInfo2.getQuantity()));

System.out.println();

System.out.println("Total: $" + ((itemInfo1.getPrice() * itemInfo1.getQuantity()) + (itemInfo2.getPrice() * itemInfo2.getQuantity())));






And then for the ItemToPrint, this matches up with it:



public class ItemToPurchase

private String itemName;
private int itemPrice;
private int itemQuantity;

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 void setName(String itemName)

this.itemName = itemName;


public String getName()

return itemName;


public void setPrice(int itemPrice)

this.itemPrice = itemPrice;


public int getPrice()

return itemPrice;


public void setQuantity(int itemQuantity)

this.itemQuantity = itemQuantity;


public int getQuantity()

return itemQuantity;








share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39798624%2fshopping-cart-using-two-files-class-and-main-method-java%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    For the ShoppingCartPrinter, this works:



    import java.util.Scanner;

    class ShoppingCartPrinter

    public static void main(String args)

    Scanner scnr = new Scanner(System.in);
    String item1 = "";
    String item2 = "";
    int price1 = 0;
    int price2 = 0;
    int quantity1 = 0;
    int quantity2 = 0;

    ItemToPurchase itemInfo1 = new ItemToPurchase();
    ItemToPurchase itemInfo2 = new ItemToPurchase();

    System.out.println("Item 1");
    System.out.println("Enter the item name:");
    itemInfo1.setName(scnr.nextLine());

    System.out.println("Enter the item price:");
    itemInfo1.setPrice(scnr.nextInt());

    System.out.println("Enter the item quantity:");
    itemInfo1.setQuantity(scnr.nextInt());
    System.out.println();

    System.out.println("Item 2");
    itemInfo2.setName(scnr.nextLine());
    System.out.println("Enter the item name:");
    itemInfo2.setName(scnr.nextLine());

    System.out.println("Enter the item price:");
    itemInfo2.setPrice(scnr.nextInt());

    System.out.println("Enter the item quantity:");
    itemInfo2.setQuantity(scnr.nextInt());
    System.out.println();

    System.out.println("TOTAL COST");

    System.out.println(itemInfo1.getName() + " " + itemInfo1.getQuantity() + " @ $" + itemInfo1.getPrice() + " = $" + (itemInfo1.getPrice() * itemInfo1.getQuantity()));

    System.out.println(itemInfo2.getName() + " " + itemInfo2.getQuantity() + " @ $" + itemInfo2.getPrice() + " = $" + (itemInfo2.getPrice() * itemInfo2.getQuantity()));

    System.out.println();

    System.out.println("Total: $" + ((itemInfo1.getPrice() * itemInfo1.getQuantity()) + (itemInfo2.getPrice() * itemInfo2.getQuantity())));






    And then for the ItemToPrint, this matches up with it:



    public class ItemToPurchase

    private String itemName;
    private int itemPrice;
    private int itemQuantity;

    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 void setName(String itemName)

    this.itemName = itemName;


    public String getName()

    return itemName;


    public void setPrice(int itemPrice)

    this.itemPrice = itemPrice;


    public int getPrice()

    return itemPrice;


    public void setQuantity(int itemQuantity)

    this.itemQuantity = itemQuantity;


    public int getQuantity()

    return itemQuantity;








    share|improve this answer



























      0














      For the ShoppingCartPrinter, this works:



      import java.util.Scanner;

      class ShoppingCartPrinter

      public static void main(String args)

      Scanner scnr = new Scanner(System.in);
      String item1 = "";
      String item2 = "";
      int price1 = 0;
      int price2 = 0;
      int quantity1 = 0;
      int quantity2 = 0;

      ItemToPurchase itemInfo1 = new ItemToPurchase();
      ItemToPurchase itemInfo2 = new ItemToPurchase();

      System.out.println("Item 1");
      System.out.println("Enter the item name:");
      itemInfo1.setName(scnr.nextLine());

      System.out.println("Enter the item price:");
      itemInfo1.setPrice(scnr.nextInt());

      System.out.println("Enter the item quantity:");
      itemInfo1.setQuantity(scnr.nextInt());
      System.out.println();

      System.out.println("Item 2");
      itemInfo2.setName(scnr.nextLine());
      System.out.println("Enter the item name:");
      itemInfo2.setName(scnr.nextLine());

      System.out.println("Enter the item price:");
      itemInfo2.setPrice(scnr.nextInt());

      System.out.println("Enter the item quantity:");
      itemInfo2.setQuantity(scnr.nextInt());
      System.out.println();

      System.out.println("TOTAL COST");

      System.out.println(itemInfo1.getName() + " " + itemInfo1.getQuantity() + " @ $" + itemInfo1.getPrice() + " = $" + (itemInfo1.getPrice() * itemInfo1.getQuantity()));

      System.out.println(itemInfo2.getName() + " " + itemInfo2.getQuantity() + " @ $" + itemInfo2.getPrice() + " = $" + (itemInfo2.getPrice() * itemInfo2.getQuantity()));

      System.out.println();

      System.out.println("Total: $" + ((itemInfo1.getPrice() * itemInfo1.getQuantity()) + (itemInfo2.getPrice() * itemInfo2.getQuantity())));






      And then for the ItemToPrint, this matches up with it:



      public class ItemToPurchase

      private String itemName;
      private int itemPrice;
      private int itemQuantity;

      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 void setName(String itemName)

      this.itemName = itemName;


      public String getName()

      return itemName;


      public void setPrice(int itemPrice)

      this.itemPrice = itemPrice;


      public int getPrice()

      return itemPrice;


      public void setQuantity(int itemQuantity)

      this.itemQuantity = itemQuantity;


      public int getQuantity()

      return itemQuantity;








      share|improve this answer

























        0












        0








        0






        For the ShoppingCartPrinter, this works:



        import java.util.Scanner;

        class ShoppingCartPrinter

        public static void main(String args)

        Scanner scnr = new Scanner(System.in);
        String item1 = "";
        String item2 = "";
        int price1 = 0;
        int price2 = 0;
        int quantity1 = 0;
        int quantity2 = 0;

        ItemToPurchase itemInfo1 = new ItemToPurchase();
        ItemToPurchase itemInfo2 = new ItemToPurchase();

        System.out.println("Item 1");
        System.out.println("Enter the item name:");
        itemInfo1.setName(scnr.nextLine());

        System.out.println("Enter the item price:");
        itemInfo1.setPrice(scnr.nextInt());

        System.out.println("Enter the item quantity:");
        itemInfo1.setQuantity(scnr.nextInt());
        System.out.println();

        System.out.println("Item 2");
        itemInfo2.setName(scnr.nextLine());
        System.out.println("Enter the item name:");
        itemInfo2.setName(scnr.nextLine());

        System.out.println("Enter the item price:");
        itemInfo2.setPrice(scnr.nextInt());

        System.out.println("Enter the item quantity:");
        itemInfo2.setQuantity(scnr.nextInt());
        System.out.println();

        System.out.println("TOTAL COST");

        System.out.println(itemInfo1.getName() + " " + itemInfo1.getQuantity() + " @ $" + itemInfo1.getPrice() + " = $" + (itemInfo1.getPrice() * itemInfo1.getQuantity()));

        System.out.println(itemInfo2.getName() + " " + itemInfo2.getQuantity() + " @ $" + itemInfo2.getPrice() + " = $" + (itemInfo2.getPrice() * itemInfo2.getQuantity()));

        System.out.println();

        System.out.println("Total: $" + ((itemInfo1.getPrice() * itemInfo1.getQuantity()) + (itemInfo2.getPrice() * itemInfo2.getQuantity())));






        And then for the ItemToPrint, this matches up with it:



        public class ItemToPurchase

        private String itemName;
        private int itemPrice;
        private int itemQuantity;

        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 void setName(String itemName)

        this.itemName = itemName;


        public String getName()

        return itemName;


        public void setPrice(int itemPrice)

        this.itemPrice = itemPrice;


        public int getPrice()

        return itemPrice;


        public void setQuantity(int itemQuantity)

        this.itemQuantity = itemQuantity;


        public int getQuantity()

        return itemQuantity;








        share|improve this answer














        For the ShoppingCartPrinter, this works:



        import java.util.Scanner;

        class ShoppingCartPrinter

        public static void main(String args)

        Scanner scnr = new Scanner(System.in);
        String item1 = "";
        String item2 = "";
        int price1 = 0;
        int price2 = 0;
        int quantity1 = 0;
        int quantity2 = 0;

        ItemToPurchase itemInfo1 = new ItemToPurchase();
        ItemToPurchase itemInfo2 = new ItemToPurchase();

        System.out.println("Item 1");
        System.out.println("Enter the item name:");
        itemInfo1.setName(scnr.nextLine());

        System.out.println("Enter the item price:");
        itemInfo1.setPrice(scnr.nextInt());

        System.out.println("Enter the item quantity:");
        itemInfo1.setQuantity(scnr.nextInt());
        System.out.println();

        System.out.println("Item 2");
        itemInfo2.setName(scnr.nextLine());
        System.out.println("Enter the item name:");
        itemInfo2.setName(scnr.nextLine());

        System.out.println("Enter the item price:");
        itemInfo2.setPrice(scnr.nextInt());

        System.out.println("Enter the item quantity:");
        itemInfo2.setQuantity(scnr.nextInt());
        System.out.println();

        System.out.println("TOTAL COST");

        System.out.println(itemInfo1.getName() + " " + itemInfo1.getQuantity() + " @ $" + itemInfo1.getPrice() + " = $" + (itemInfo1.getPrice() * itemInfo1.getQuantity()));

        System.out.println(itemInfo2.getName() + " " + itemInfo2.getQuantity() + " @ $" + itemInfo2.getPrice() + " = $" + (itemInfo2.getPrice() * itemInfo2.getQuantity()));

        System.out.println();

        System.out.println("Total: $" + ((itemInfo1.getPrice() * itemInfo1.getQuantity()) + (itemInfo2.getPrice() * itemInfo2.getQuantity())));






        And then for the ItemToPrint, this matches up with it:



        public class ItemToPurchase

        private String itemName;
        private int itemPrice;
        private int itemQuantity;

        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 void setName(String itemName)

        this.itemName = itemName;


        public String getName()

        return itemName;


        public void setPrice(int itemPrice)

        this.itemPrice = itemPrice;


        public int getPrice()

        return itemPrice;


        public void setQuantity(int itemQuantity)

        this.itemQuantity = itemQuantity;


        public int getQuantity()

        return itemQuantity;









        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 10 at 0:21









        Unheilig

        11.9k165283




        11.9k165283










        answered Nov 10 at 0:04









        CarverOfChoice

        1




        1



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39798624%2fshopping-cart-using-two-files-class-and-main-method-java%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

            How do I collapse sections of code in Visual Studio Code for Windows?