• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Asking for help with Sort-Program (Arrays)

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.


Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would like to know why you want an Array based sorting?

For your approach Lists can be converted to Array using toArray method.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic