一次又一次地在java中编辑对象/arrayList [英] edit object/arrayList in java again and again

查看:38
本文介绍了一次又一次地在java中编辑对象/arrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用对象对 AllayList 进行了排序,请参阅我之前的帖子 如何从 Java Object/ArrayList 中排序和获取最大值

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) );

现在在步骤1:我想获取其中的任何人(随机选择任何对象),否则它们是第一个最高的(即H"),然后编辑数字然后将其保存回来.步骤2:我想获取其中第二高的(即C")的任何人(随机选择任何对象),然后编辑数字然后将其保存回来.step3:我想取出他们中的任何人(随机选择任何对象)其他第三高(即B"),然后编辑数字然后将其保存回来.

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.

当所有 5 个都完成后,过程将从步骤 1 重新开始.这样我就可以减少所有学生的人数.

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?

推荐答案

我通过一些简单的算术得到了答案.创建另一个类来为以下情况选择随机数:

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

step1:获取当前学生索引step2:随机选择一名学生,数量应该减少,而不是step1学生

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

再次继续 step1 和 step2

continuing again step1 and step2

这篇关于一次又一次地在java中编辑对象/arrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆