Results 1 to 4 of 4
- 09-29-2008, 05:09 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 11
- Rep Power
- 0
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. :)
- 09-29-2008, 05:34 PM #2
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.
- 09-29-2008, 05:49 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 11
- Rep Power
- 0
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
- 09-29-2008, 06:18 PM #4
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
-
Launching an application from another application dynamically
By Java Tip in forum Java TipReplies: 0Last Post: 02-16-2008, 09:31 PM -
Launching an application from another application using thread
By Java Tip in forum Java TipReplies: 0Last Post: 02-16-2008, 09:29 PM -
how to use JTA for application
By mary in forum Advanced JavaReplies: 1Last Post: 07-13-2007, 04:34 PM -
Cart of Purchase
By Marcus in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 07-06-2007, 05:16 PM -
Simple Shopping Cart Help
By CoOlbOyCoOl in forum NetBeansReplies: 0Last Post: 05-12-2007, 05:21 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks