0

I am very new to programing. The following project I do for my programming courses at university. We have code a mini bank program where each customer should get an ID like "KU345-32". I generate these IDs with following code:

int customerID = ThreadLocalRandom.current().nextInt(1, 100000);
        char firstChar = (char)ThreadLocalRandom.current().nextInt(65, 91); 
        char secondChar = (char)ThreadLocalRandom.current().nextInt(65, 91);

        custID= "" + firstChar + secondChar + (formatCID.format(customerID)).substring(0, 3) + "-" + (formatCID.format(customerID)).substring(3, 5);

One task of this bankprogram is to sort these IDs first alphabatically then numeric:

AT234-12

BA123-08

and so on. But how is this possible? It is no problem for me to delete the - everywhere but then I dont know how to compare or which interface to use. Write an own comparable is maybe too much for me. I am looking forward to any help :)

Philipp
  • 35
  • 1
  • 5
  • If using a Collection in the Java API, you'll need to implement a custom `Comparator`, see http://stackoverflow.com/a/5805621/7001059 – d.j.brown Nov 16 '16 at 23:01
  • Avoid asking questions on Stack Overflow that ask "How can I do this?" Instead, post what you have tried already, and why it doesn't work. A quick Google search would give you a lot of information on what you need. – Sub 6 Resources Nov 16 '16 at 23:17

1 Answers1

0

If I have understood your post, you need to sort your "ID" char by char.

For String alphabetical sort, take a short look at this topic.

Then combine the numeric sort in your own comparator. No much fun there. Good Luck !

Community
  • 1
  • 1
Davezedave
  • 35
  • 9