File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes sorting objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sorting objects" Watch "sorting objects" New topic
Author

sorting objects

Garry Meax
Ranch Hand

Joined: Feb 11, 2005
Posts: 31
Can someone please help me to
*sort the Employee objects
*print the Employee objects in descending order by Employee number

import java.io.*;
class emplyee
{
int number;
int salary;
int numb;
int sala;

void getdata() throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Employee Number: ");
numb = Integer.parseInt(in.readLine());
System.out.println("Employee Salary: ");
sala = Integer.parseInt(in.readLine());
}

void setdata()
{
number = numb;
salary = sala;

System.out.println("Number is: "+number);
System.out.println("Salary is: "+salary);
}


public static void main(String args[]) throws IOException
{

for(int i=0; i<5; i++)
{
emplyee q[i] = new emplyee();
q[i].getdata();
q[i].setdata();
}
}
}
[ February 16, 2005: Message edited by: Garry Meax ]
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
We don't like to help folks with homework assignments here. But, I will tell you that a simple Google search for "sort java" will get you started on the right track. You'll have to figure it out from there.


James Carman, President<br />Carman Consulting, Inc.
Garry Meax
Ranch Hand

Joined: Feb 11, 2005
Posts: 31
Originally posted by James Carman:
We don't like to help folks with homework assignments here. But, I will tell you that a simple Google search for "sort java" will get you started on the right track. You'll have to figure it out from there.


its not that i asked to do the whole program anyway thanks for tip.
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Which part were you having more trouble with? The sorting or the printing?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Garry Meax:


its not that i asked to do the whole program anyway thanks for tip.


True, but you also weren't very clear about which specific problems you have encountered. If you can answer James question, then we will be happy to help you along in the right direction.

Layne


Java API Documentation
The Java Tutorial
Garry Meax
Ranch Hand

Joined: Feb 11, 2005
Posts: 31
Originally posted by James Carman:
Which part were you having more trouble with? The sorting or the printing?


sorting. so, can you help me?
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Garry Meax:
sorting. so, can you help me?
Absolutely! The following code will sort three integers:It's not optimized, and of course it probably won't work for four integers. But hey, it sorts!

If this isn't what you need, please elaborate on your precise needs, what classes and packages you've looked in for ideas, what you've tried to do so far, how it turned out (compile errors, nothing happened, incorrect output), etc. Without that information, you get code that sorts three integers.

Skipping ahead . . . check out java.util.Comparable and java.util.Comparator and the java.util.Collection classes. Try it out, then ask specific questions so we can help you, most likely with more hints (and probably a few more jokes, but there's gotta be a price, right?).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sorting objects