Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to create two classes

 
Yogesh Dhond
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic