| Author |
how to create two classes
|
Yogesh Dhond
Greenhorn
Joined: Jul 19, 2006
Posts: 17
|
|
I have following problem. Theres is small shop which maintains the details of its customer who bought product p1 and p2. The total quantity of both the products is added and the customer details are displayed in the sorted order displaying customer who bought highest quantity on top.Also if the particular customer bought the quantity lower then some threshold, shop owner can take decison to remove it frm the current list. Now for this i have written one class which takes customer details like his name,address,p1 quantity,p2 quantity and then displays it. The other class just maintains the list of all the customer and adds or deletes them from the list.But I am not sure how to code this class as I also want to display the customer in some order. Can anybody help me in this regard?
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
Not here in the SCJP forum. Moving to our Java In General (Beginner) forum. But I would advise you to have some code available that you have already written to attempt to solve your problem.
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Justin Fox
Ranch Hand
Joined: Jan 24, 2006
Posts: 802
|
|
well, you could use a Doubly Linked List, and have each node contain a value of type Cusomter.. and make the Node class for the DLL an inner class.. for example lil help to get you started... Justin p.s, if you want to insert in order... make another innerclass that implements? comparable... or maybe extends.. i cant really remember.. then you could do like the following.. if(curr.emp.getName().compareTo( noo.emp.getName())>0) { insertAfterCurrentNode(noo); } where the > 0 means if curr.name is > noo.name; and same for < 0, mans if curr.name is < noo.name; Justin
|
You down with OOP? Yeah you know me!
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16479
|
|
However if you are doing this for real use, or if it's for an assignment that doesn't say anything about what kind of list you should use, then you should definitely not spend any time writing low-level code to work with lists. Instead, choose a standard List from the standard Java API -- it doesn't really matter which one you choose since your data is small, so ArrayList is as good as any other choice. Then you can have a class that adds and deletes customers that's very simple, basically one line of code per method. To sort a list, there are also standard methods like Collections.sort(list). Here is a tutorial about lists and other collections.
|
 |
Justin Fox
Ranch Hand
Joined: Jan 24, 2006
Posts: 802
|
|
yeah, well if you ever come across any other language, oh, such as C!!! you dont have these little shortcuts like java does, and it's good to know how to implent through other data structures, and see how they actually work, dont be lazy... ofcourse, that is, the prof tells you to be lazy... Justin
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: how to create two classes
|
|
|