Results 1 to 3 of 3
  1. #1
    barqcider is offline Member
    Join Date
    Oct 2012
    Rep Power

    Default so lost, i need help with methods and object constructors

    so I have two classes: my shopping cart and my main, my store (which has the main).

    Java Code:
    import java.util.Scanner;
    public class Store {
    	 * @param args
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		String item;
    		double cost;
    		Scanner input= new Scanner(;
    		System.out.println("please enter item description. type exit to quit:");
    		System.out.println("please enter item price.type 0 to exit:");
    			(cost <=0);
    that's my main.

    Java Code:
    public class shoppingCart {
    	final double shippingCost=19.95;
    	final double tax =.07;
    	double total=0;
    	public double calcTotal(double cost){ (cost*.07)+total;
    that is my other class with object constructor.

    I need to create a method in which:
    the shopping cart calculates total and each item added to the shopping cart, a running total. im not sure how to go about this, so any start to get this done would be appreciated (and if I did something wrong here, let me know too). thanks all.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Rep Power

    Default Re: so lost, i need help with methods and object constructors

    Think about the real world. When you go to the shops you place multiple items in your shopping cart and then you sum up the prices at the checkout. How many things can your shopping cart class hold?

  3. #3
    Nhatmeister is offline Member
    Join Date
    Aug 2013
    Rep Power

    Default Re: so lost, i need help with methods and object constructors

    I am pretty new to Java too, but I am thinking maybe there should be a class call itemPurchase. This would have info such as description, price, etc ....Your shopping cart could have an itemPurchase[] to hold these items. Once all the buying are done, you can loop this [] and add up everything...or if you need a running total, then everytime a new itemPurchase is instantiated, have it update your total (only have couple months of Java, so if forgive if I am completely off standard...thanks).

Similar Threads

  1. Help with arrays and methods and constructors
    By mjfitches in forum New To Java
    Replies: 1
    Last Post: 02-27-2013, 03:40 PM
  2. Classes, constructors and methods
    By GRGoucho in forum New To Java
    Replies: 3
    Last Post: 02-17-2013, 06:54 PM
  3. Constructors & Methods
    By candygirl198827 in forum New To Java
    Replies: 1
    Last Post: 12-02-2010, 01:51 AM
  4. Formulas in methods or constructors?
    By kyameron in forum New To Java
    Replies: 11
    Last Post: 11-20-2010, 12:22 PM
  5. Calling subclassed methods from constructors
    By arefeh in forum New To Java
    Replies: 7
    Last Post: 01-22-2010, 12:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts