Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

sorting objects

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which part were you having more trouble with? The sorting or the printing?
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?).
 
You firghten me terribly. I would like to go home now. Here, take this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic