我想阅读带有对象的 ArrayList 的示例。(Java)
我创建了两个类,我试图调用一个构造函数(带参数)和一个方法。我发现如果我只使用一个对象就很容易。
我的目标:
- 使用 3 个对象调用相同的方法。
- 使用ArrayList调用该方法3次。
我的作业: 我谷歌了一下。我碰巧以对 ArrayList 的解释及其某些示例作为结束。我没有找到我认为需要的示例,即将 ArrayList 与对象一起使用(如我的引文)。
public class DrawGraphics
{
BouncingBox box;
/** Initializes this class for drawing. */
public DrawGraphics()
{
box = new BouncingBox(200, 50, Color.green);
box.setMovementVector(1, 1);
}
//..................
//................
}
感谢那些试图提供帮助的人。
I have created two classes and I am trying to invoke a constructor(with argument) and a method. I find it easy if I just use an object.
My Goal :
- To invoke the same method by using 3 objects.
- Use ArrayList to invoke the method 3 times.
My Homework:
I did google a bit. I happen to end with explanation of ArrayList and certain examples of it. I did not find examples which I think I need i.e. using ArrayList with Objects(like my citation).
public class DrawGraphics
{
BouncingBox box;
/** Initializes this class for drawing. */
public DrawGraphics()
{
box = new BouncingBox(200, 50, Color.green);
box.setMovementVector(1, 1);
}
//..................
//................
}
Thank you for those who try to help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
继续您的示例,这可能会让您了解列表的用途:
这是您正在寻找的吗?
Continuing with your example this might give you an idea of what Lists can be used for:
Is this what you were looking for?
我确信这对原始发帖人没有帮助,除非他们接管课程,但是:
此作业的详细信息可在 MIT“开放课程软件”上找到,作业的目标是通过修改提供的代码(一个数组列表)来创建 3 个不同的对象不需要,就此而言不需要数组,您只需通过添加类似的代码即可创建附加框,
即:
等等...
同一类中的第二个函数也需要修改,它将看起来像这样:
注意如果你真的对编程感兴趣或爱好,但不明白你在课堂上做什么,最好寻求帮助。简单地在网上复制答案并不能拯救你在现实世界中的处境。
I'm sure this wont help the original poster unless they are taking the class over but:
The details of this assignment are available on MIT "opencourseware" the goal of the assignment is to create 3 different objects by modifying provided code, an array list is not needed, an array is not needed for that matter, you simple create additional boxes by adding similar code
ie:
etc...
the second function in that same class needs to be modified as well, it will look something like this:
note that if you're actually interested in programming as a career or hobby, but don't understand what you're doing in class, it's a good idea to ask for help. Simply copying the answers online will not save you in the real world.