This problem is a little bit tricky, because you have to completely rethink the
approach. Previously, we looked at a picture,and the one to the left. But when
we use an enhanced for loop, we only get to look at one picture at a time, so we
have to remember something from the past. The way I've done it is, I would
remember the rightmost position of the previous picture. Let me show you. I
have an enhanced for loop, and when I'm done positioning the picture, I
remember its rightmostX value. So when I reenter the loop with the next
picture, then I can position it 10 further than the rightmostX value. And
they're always spaced apart nicely. What about he first picture? If I start the
rightmostX at 0, then the first picture ends up at offset 10. So that's the
answer. And now when you look at these two loops, you can see that we can
actually merge them. So we do the positioning and drawing in a single loop.
That's enough about pictures for right now. Sarah will show you another
application of array lists. She'll revisit a class that you've seen in lesson
three. The person class that collected friends, at that time we did it in
a less than perfect way by just having one long string of friend names. Now
that you know how to collect objects, she'll collect the friends in an array
list. Alright, over to you Sarah.
Este problema es un poco complicado, ya que hay que repensar por completo el
enfoque. Anteriormente vimos una imagen y la imagen a la izquierda de ella. Pero cuando
utilizamos un bucle for mejorado, sólo tenemos que mirar una imagen a la vez, por lo que
hay que recordar algo del pasado. La forma en que lo he hecho es que
recordaría la posición más a la derecha de la imagen anterior. Deja que te enseñe. Tengo
un bucle for mejorado y cuando termino de posicionar la imagen,
recuerdo su valor rightmostX. Así que cuando vuelva a entrar en el bucle con la siguiente
imagen, entonces puedo posicionarla en 10 más al valor x más a la derecha. Y
siempre están muy bien separadas. ¿Qué pasa con la primer imagen? Si pongo
rightmostX en 0, entonces la primer imagen termina en offset 10. Y esa es la
respuesta. Y ahora, cuando nos fijamos en estos dos bucles, se puede ver que podemos
en realidad fusionarlos. Así que hacemos el posicionamiento y el dibujo en un solo bucle.
Eso es suficiente sobre imágenes por ahora. Sara te mostrará otra
aplicación de listas de arreglo. Ella volverá a una clase que viste en la lección
tres. La clase Persona que recoge los amigos, la hicimos entonces en
una forma menos que perfecta teniendo solo una larga cadena de nombres de amigos. Ahora
que sabes cómo recoger objetos, ella va a recoger a los amigos en una lista de
arreglo. Muy bien, ahora quédate con Sara.
Ce problème est un peu délicat, car vous
devez complètement repenser l'approche.
Auparavant, nous regardions
une photo et celle de gauche.
Mais avec une boucle for améliorée,
nous ne pouvons regarder
qu'une image à la fois,
nous devons donc nous souvenir
de quelque chose du passé.
La façon dont je l'ai fait,
c'est en me souvenant de la position
la plus à droite de l'image précédente.
Voici comment.
J'ai une boucle for améliorée,
et quand j'ai fini de positionner l'image,
je repense à sa valeur de droite.
Donc, quand je rentre dans
la boucle avec l'image suivante,
alors je peux la positionner 10
plus loin que la valeur rightmostX
et elle sont toujours bien séparées.
Qu'en est-il de la première photo?
Si je commence rightmostX
à partir de 0,
alors la première image
se termine à la position 10.
Voilà donc la réponse.
Et quand vous regardez
ces deux boucles,
vous voyez que nous
pouvons les fusionner.
Nous faisons donc le positionnement
et le dessin en une seule boucle.
Voilà pour les photos.
Sara vous montrera une autre
application des vecteurs.
Elle révisera un cours
de la leçon numéro 3.
La classe personne qui
recueillait des amis,
à l'époque nous l'avions fait
d'une manière moins que parfaite
en ayant juste une longue
chaîne de noms d'amis.
Maintenant que vous savez
comment collecter des objets,
elle collectera les amis dans un vecteur.
À vous, Sara.
この問題はアプローチを考え直す必要があるので
少し厄介です
前回は1枚の絵とその左にある絵を見ました
しかし拡張した絵を使うと
一度に1つの絵しか見ることができません
そこである物を覚えておく必要があります
説明しましょう
それは前の写真の右端の位置です
見ていてください
拡張forループがあります
絵の位置づけが終わったら
その絵のrightmostXの値を覚えておきます
そうすると次の絵のループに再度入る時
rightmostXの値より10遠くに
位置づけることができます
すると絵の間が常にきれいに空きます
では最初の絵はどうでしょうか
もしrightmostXをゼロで始めたら
最初の絵はオフセット10になります
それが答えです さてこの2つのループを見た時
これらは融合できることが分かります
よって1つのループで位置づけと描画を行います
絵の話はこれくらいにしておきましょう
サラがArrayListの別の応用例をお見せします
レッスン3で学んだクラスを思い出してください
personクラスで友人を収集しましたね
1つの長い友人の名前の文字列を作りましたが
あまり完璧な方法とは言えません
今回オブジェクトの収集の仕方が分かったので
今度はサラがArrayListで友人を収集します
それではサラに引き継ぎます
이 문제는 조금 어렵습니다. 왜냐하면 접근하는 것을 새롭게 생각해야 하기
때문입니다. 이전에는, 그림 하나와 그 왼쪽에 있는 그림만 접근했습니다. 하지만
특별한 for문을 사용할 때는 그림 하나만 접근할 수 있습니다. 그래서 기억해야
할 것이 있습니다. 이 방법은, 이전 그림의 가장 오른쪽에 있는 위치를
기억해야 합니다. 여러분께 보여드리겠습니다.
여기에 특별한 for문을 작성하고 그림의 위치를 지정하는 데 완료하면
rightMostX 값을 저장합니다. 그래서 제가 이 반복문을 다음 그림과
함께 접근하면, 그 그림의 위치를 rightMostX 값보다 10만큼 더 지정할 수 있습니다.
그렇게 되면 보기 좋게 정렬이 됩니다. 첫 번째 그림은 어떻게 할까요? 만약 제가
rightMostX의 값을 0으로 시작하게 한다면, 첫 번째 그림은 10만큼 떨어지게
됩니다. 이게 정답입니다. 그리고 이 두 개의 반복문을 보면, 사실 이 반복문을
합칠 수 있다는 것을 알 수 있습니다. 이렇게 하면 출력하는 것과 위치 선정 동시에
가능합니다. 이제 그림 갖고 하는 것은 그만할 때가 왔습니다. Sara가 배열
목록을 갖고 할 수 있는 일을 더 보여줄 겁니다. 전에 실습했던
클래스를 이용해서 수업할 예정입니다. 그 클래스는 친구를 모으는 person
클래스 입니다. 그때는 친구를 그저 하나의 문자열 안에 저장하기만 했습니다. 이제
객체를 모으는 방법을 알게 되었으니, Sara가 배열 리스트 안에 저장하는
법을 알려드릴 겁니다. 부탁합니다 Sara!