Hi, My name is Micky.

I have requirement, but i don't know how to start it, could anyone help me out. here is the requirement.

In a class there are 10 Students with name , marks , Percentage and there rank should be in the below format

Name Marks Percentage Rank

bbb 100 100 1
ccc 100 100 1
ddd 99 99 4
eee 99 99 4
fff 98 98 6
ggg 98 98 6
hhh 97 97 8
iii 96 95 9
jjj 96 96 10

Recommended Answers

All 3 Replies

Are you asking how to sort by name?

So you want to read that data into memory -- into something like a List or array. And then you want to sort it -- based on "Marks" and "Percentage" it seems. (Presumably, the input would not already be in sorted order.)

Now, depending on how you do the sort, the "top 10" could be the first or last 10. If you're "smart" about it, the "top 10" would be the first ten. So you just "display" (print) the first ten.

Start by defining a Student class that has instance variables for name. marks etc.
Input the raw data, create the instances of Student and add them to a List like JeffGrigg said.

Java has methods to sort a List:
http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#sort%28java.util.List,%20java.util.Comparator%29

you need to create one or more Comparators ( http://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html ) that define the order in which you want things sorted.

commented: Yep; more good advice. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.