Results 1 to 4 of 4
  1. #1
    helloworld is offline Member
    Join Date
    Sep 2008
    Posts
    11
    Rep Power
    0

    Default I need help for this shopping cart application!

    I'm currently learning how to create this shopping cart application. I'm very new to java and I have these questions to ask(Sorry if all of them are very stupid ones)

    1) To make the application, I'm supposed to create many classes such as Product, Menu, Stockline, Stock and etc. I'm puzzled as to how all the classes could be combined and ran at the same time in ms dos? Is there a certain topic on this? Hope someone can tell me so I can go read up on it...

    2) After creating a class, for e.g, Product, we were told to also create ProductTest. I do not understand the use of the ProductTest class. Why can't we just have the Product class?

    I thank you all for taking time to read this. I've been learning java for a few weeks now, and still pretty puzzled about it. Hope I can get assistance from all you pros! Thanks again. :)

  2. #2
    ShoeNinja's Avatar
    ShoeNinja is offline Senior Member
    Join Date
    Oct 2007
    Posts
    124
    Rep Power
    0

    Default

    1) You won't be running classes. You'll be running a main method.

    2) Without more information, there's no way to tell what ProductTest is for.

  3. #3
    helloworld is offline Member
    Join Date
    Sep 2008
    Posts
    11
    Rep Power
    0

    Default Product, ProductTest

    This is the code for Product:

    /**
    * An abstraction of a Product.
    */
    public class Product {
    private String name;
    private int reference;
    private double price;


    public void setName(String n) {
    name = n;
    }

    public void setReference(int ref) {
    reference = ref;
    }

    public void setPrice(double pr) {
    price = pr;
    }

    public String getName() {
    return name;
    }

    public int getReference(){
    return reference;
    }

    public double getPrice() {
    return price;
    }

    public String toString() {
    return name+" "+reference+" $"+price;
    // return "Product ("+name+") -- reference -- ("+reference+")-- unit price -- ($"+price+")";
    }
    }




    And for Product Test:



    /**
    * Created by IntelliJ IDEA.
    * User: lckoh
    * Date: Sep 6, 2008
    * Time: 10:38:27 PM
    * Modified to remove constructor
    */
    public class ProductTest {
    public static void main(String[] args) {


    Product aProduct = new Product();
    aProduct.setName("java book");
    aProduct.setReference(1001);
    aProduct.setPrice(25.3);

    System.out.println(aProduct);

    aProduct.setPrice(30.2);

    System.out.println(aProduct);
    }

    }




    My question is, how does MS dos run the main class, together with the 'execution' of other classes I've created? How does a program, with several classes, run? I know you run the main class, but I would like to know how to type methods into the main class such that other classes are running too?
    Last edited by helloworld; 09-29-2008 at 06:00 PM. Reason: nil

  4. #4
    ShoeNinja's Avatar
    ShoeNinja is offline Senior Member
    Join Date
    Oct 2007
    Posts
    124
    Rep Power
    0

    Default

    Classes don't run, they are instantiated. In your main method, you will create instances (objects) of the classes that you need to use.

    Look at the main method that is inside ProductTest.

    Java Code:
    public static void main(String[] args) {
    
    //create a new product object
    Product aProduct = new Product();
    //call the object/s setName method
    aProduct.setName("java book");
    //call the object's setReference method
    aProduct.setReference(1001);
    //call the object's setPrice method
    aProduct.setPrice(25.3);
    
    //call the object's toString method.  Objects passed to System.out.println automatically have their toString method called.
    System.out.println(aProduct);
    
    aProduct.setPrice(30.2);
    
    System.out.println(aProduct);
    }

Similar Threads

  1. Replies: 0
    Last Post: 02-16-2008, 09:31 PM
  2. Replies: 0
    Last Post: 02-16-2008, 09:29 PM
  3. how to use JTA for application
    By mary in forum Advanced Java
    Replies: 1
    Last Post: 07-13-2007, 04:34 PM
  4. Cart of Purchase
    By Marcus in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 07-06-2007, 05:16 PM
  5. Simple Shopping Cart Help
    By CoOlbOyCoOl in forum NetBeans
    Replies: 0
    Last Post: 05-12-2007, 05:21 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
  •