-5

I have sorted AllayList with Objects refer to my previous post How to sort and get highest value from Java Object/ArrayList

ArrayList<> allStudents = new ArrayList();
allStudents.add(new Student("H", 99, 93) );    
allStudents.add(new Student("C", 98, 92) );
allStudents.add(new Student("B", 98, 91) );    
allStudents.add(new Student("A", 80, 94) );
allStudents.add(new Student("F", 70, 84) );

Now in step1: I want to fetch anyone (randomly select any object) of them else the first highest(that is "H"), then edit numbers then save it back. step2: I want to to fetch anyone (randomly select any object) of them else the second highest(that is "C"), then edit numbers then save it back. step3:I want to to fetch anyone (randomly select any object) of them else the third highest(that is "B"), then edit numbers then save it back.

When all 5 will be finished, then the process will start again from step1. In this way I can reduce all student's numbers.

If someone please suggest me how can I do that?

Community
  • 1
  • 1
  • Your code shouldn't even compile -- you have the diamond operator on the wrong side, and the constructor is for a raw type. – Thorn G Jun 04 '14 at 02:59
  • 1
    what have you tried? Get a random number from 0-3, do some simple arithmetic, that's it – Adrian Shum Jun 04 '14 at 03:01
  • I have tried the below one but of course you are right. I used simple math. thanks –  Jul 31 '14 at 21:36

1 Answers1

0

I got the answer bu doing some simple arithmetic. Create another class to select random number for bellow cases:

step1: Taking current student index step2: Randomly selecting one student, whom number should reduce, rather than step1 student

continuing again step1 and step2

logcat
  • 485
  • 12
  • 22