*
The moose likes Beginning Java and the fly likes Asking for help with Sort-Program (Arrays) 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 "Asking for help with Sort-Program (Arrays)" Watch "Asking for help with Sort-Program (Arrays)" New topic
Author

Asking for help with Sort-Program (Arrays)

Roland Weber
Greenhorn

Joined: Dec 04, 2009
Posts: 1
Hi

Some time ago, I've written this Code:


With that little proggie, you can sort some students by their name, lastname, id and grades but with no sorting options (no GUI), which means: after running the program,
5 entries will be printed on the console:

- All students (not sorted)
- All students (sorted by their name)
- All students (sorted by their lastname)
- All students (sorted by their ID)
- All students (sorted by their grades)

In the second version, you can now choose the sorting options (GUI => 4 JButtons). I didn't write that second version on my own, someone else did it for me
(for tutorial purposes). Here's the code:



Now, why am I posting in this forum: I'd like to have the sorting done only with arrays (array-sort, like I did in the first version) and not with lists and
collections (as it is done in the second version above).
I've already altered my own version of the code (first one posted) to match it better to the tutorial code. My new code consists of parts from my original code and
parts form the tutorial code. Here it is:


Unfortunately, I've encountered some problems:

- How do I get the Array-Sort-Methods working again (what do I have to change / write), so that it is possible to invoke them by pressing the corresponding JButton?
- How do I get the student2 variable working outside of the main-method? Declare it as final? But how...?
- How do i get rid off the remaining list-objects, so that it is (still) possible to run the program?
- Are there other things I have to change in my Code to make it work properly?

I hope you understand what I've written and can help me. English is not my native language.


Greeting

Learner
Ulrika Tingle
Ranch Hand

Joined: Nov 24, 2009
Posts: 92
Why don't you take this opportunity to rethink your design?

The problem is that you've strewn implementation detail throughout the whole program so that when you want to change a data structure you have to change in lots of places.

Try instead to use OO and hide implementation detail in classes so you can change data structures without effecting the whole program. Try to hide exactly how you store students.

Rather than engaging this forum into helping you debug a program with a fawlty design, it's better you fix the design to make your program easier to change. Making programs easy to change is why you use OO in the first place.
chandrakant karale
Ranch Hand

Joined: Nov 21, 2007
Posts: 41
Would like to know why you want an Array based sorting?

For your approach Lists can be converted to Array using toArray method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Asking for help with Sort-Program (Arrays)