shopping cart system?

shopping cart systems
Jessy C asked:


How do you create a shopping cart system Java program?
Any ideas on how to even start?

Thanks!
well the program has to read a file that has the title followed by a coma followed by the price.
I Did It Your Way, 11.95
The History of Scotland, 14.50
Learn Calculus in One Day, 29.95
Feel the Stress, 18.50
Great Poems, 12.95
Europe on a Shoestring, 10.95
The Life of Mozart, 14.50
I need to list only the title, how do I do that?

Thanks!

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Webnews
  • MisterWong
  • Y!GG

2 comments to shopping cart system?

  • import java.util.Scanner;

    is a great place to start it will let you ask the user to input data. This needs to be at the very, very top of the program!!

    next you will want to put in the code…

    Scanner input = new Scanner(System.in);

    this needs to be within the public static void main(Sting []args){

    Which is the main class. finally you will want to ask your user to input their items. for example;(be sure to declare your variables… String item1;
    String item2;

    System.out.println(please enter your first item);
    item1 = input.next();

    from here you can either output all the things they have entered;
    System.out.println(item1);

    or you could get into some if statements..

    if (item1 == apples) {
    totalprice =+ totalprice + 1.99;
    }

    hopefully that helps a little not personally knowing what your program needs to do.

  • Well, think of the shopping cart at your grocer. What do you do when you go shopping. First you get a cart. You add stuff to it. Finally when you check out, the price of each item is added to give you a dollar amount that you need to pay up.

    Moving on to your example, first allocate a cart. In your case, you do not know how many items it will contain. So use a container(if you are familiar with one). This container will contain objects. Each object will represent an item (like the books in your example, I presume). So it will have a name and a price attributes.

    Every time an item is added to the cart, create an object with the attributes (perhaps via a constructor) and add it to the container.
    When the checkout is done(perhaps by a method in your case), go through the collection and add up the amounts. This is your grand total. Note that a number of things like quantity, taxes etc are ignored in your exercise. But there is a simple cart for you in simple english.

You must be logged in to post a comment.