Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Branching Statements

Aravind voruganti
Aravind voruganti
437 Points

how do the names come?

how did the names..."summer","amey" appear in branching statements ?

I'll try to answer this by pulling out the relevant code below:

public static void main(String[] args) { Console console = System.console(); String[] rsvps = Rsvps.shuffled(); int prizesGivenAway = 0; int drawingNumber = 0;

while (prizesGivenAway < 5) {
  String winner = rsvps[drawingNumber];
  drawingNumber++;
  console.printf("Is %s present?  ", winner); 
  String isHere = console.readLine();
  if (isHere.equalsIgnoreCase("no")) {
    continue;

If we start from the Console console = System.console(); line, we can work through where the names come from.

The names come in this line: String[] rsvps = Rsvps.shuffled(); Somewhere, the array "rsvps" is stored and the method "shuffled" is applied to it. Unfortunately, it isn't visible to us and is probably private. This array is used in conjunction with the drawingNumber integer.

For the while loop, it is said that for anyone who has rsvp'd, shuffle the names and assign a number starting with 0 but to go no greater than the amount of rsvp'd people. Hence the code looks like this: String winner = rsvps[drawingNumber];

What we get is a string that returns the value of a person who rsvp'd whose name is a string related to a drawing number. The computer than increments the drawing number for every time it loops. So drawing number starts at 0 and increments up for every time it loops. The rsvp list is shuffled so the first person who registered isn't automatically assigned the 0 position. However, the drawing numbers start at 0 and increment by one going up.

Let me know if this answers your question or if you have further questions about my logic!