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

sorting objects

 
Garry Meax
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Garry Meax
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which part were you having more trouble with? The sorting or the printing?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Garry Meax
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic