import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class KindergartenGarden {

  private static String[] DEFAULT_STUDENTS = { "Alice", "Bob", "Charlie", "David", "Eve", "Fred", "Ginny", "Harriet", "Ileana", "Joseph", "Kincaid", "Larry"};

  private List<String> students;
  private char[][] plants;

  public KindergartenGarden(String diagram) {
    this(diagram, DEFAULT_STUDENTS);
  }

  public KindergartenGarden(String diagram, String[] students) {
    this.plants = generatePlantGrid(diagram);
    this.students = Arrays.asList(students);
    Collections.sort(this.students);
  }

  public List<Plant> getPlantsOfStudent(String student) {
    return getPlantsForIndex(getAlphabeticIndex(student));
  }

  private int getAlphabeticIndex(String student) {
    return students.indexOf(student);
  }

  private List<Plant> getPlantsForIndex(int index) {
    return Arrays.asList(getPlantAt(0,index * 2),
                         getPlantAt(0, index * 2 + 1),
                         getPlantAt(1, index * 2),
                         getPlantAt(1, index * 2 + 1));
  }

  private Plant getPlantAt(int row, int col) {
    return Plant.getPlant(plants[row][col]);
  }

  private char[][] generatePlantGrid(String diagram) {
    String[] rows = diagram.split("\n");
    char[][] plants = new char[2][rows[0].length()];

    for (int i = 0; i < rows.length; i++) {
      plants[i] = rows[i].toCharArray();
    }

    return plants;
  }

}

@@ -70,16 +70,42 @@
 il.List;
+%0Aimport java.util.Scanner;
 %0A%0Apublic
@@ -150,16 +150,22 @@
  static 
+final 
 String%5B%5D
@@ -313,53 +313,66 @@
 ate 
-List%3CString%3E students;%0A  private char%5B%5D%5B%5D pla
+final Plant%5B%5D%5B%5D plants;%0A  private final List%3CString%3E stude
 nts;
@@ -544,33 +544,28 @@
 lants = 
-generatePlantGrid
+parseDiagram
 (diagram
@@ -948,29 +948,26 @@
 .asList(
-getPlantAt(0,
+plants%5B0%5D%5B
 index * 
@@ -959,33 +959,33 @@
 nts%5B0%5D%5Bindex * 2
-)
+%5D
 ,%0A              
@@ -999,22 +999,18 @@
     
-getPlantAt(0, 
+plants%5B0%5D%5B
 inde
@@ -1018,17 +1018,17 @@
  * 2 + 1
-)
+%5D
 ,%0A      
@@ -1042,38 +1042,34 @@
             
-getPlantAt(1, 
+plants%5B1%5D%5B
 index * 2),%0A
@@ -1065,17 +1065,17 @@
 ndex * 2
-)
+%5D
 ,%0A      
@@ -1097,22 +1097,18 @@
     
-getPlantAt(1, 
+plants%5B1%5D%5B
 inde
@@ -1116,17 +1116,17 @@
  * 2 + 1
-)
+%5D
 );%0A  %7D%0A%0A
@@ -1144,244 +1144,276 @@
 lant
- getPlantAt(int row, int col) %7B%0A    return Plant.getPlant(p
+%5B%5D%5B%5D parseDiagram(String diagram) %7B%0A    final int rows = 2;%0A    final int cols = diagram.length() / 2;%0A    Plant%5B%5D%5B%5D plants = new P
 lant
-s
 %5Brow
+s
 %5D%5Bcol
+s
 %5D
-)
 ;%0A  
-%7D%0A%0A  private char%5B%5D%5B%5D generatePlantGrid(String diagram) %7B%0A    String%5B%5D rows = diagram.split(%22%5Cn%22);%0A    char%5B%5D%5B%5D plants = new char%5B2%5D%5Brows%5B0%5D.length()%5D;%0A
+  Scanner sc = new Scanner(diagram.replaceAll(%22%5Cn%22,%22%22)).useDelimiter(%22%22);%0A    for (int r = 0; r %3C rows; r++) %7B
 %0A    
+  
 for 
@@ -1421,33 +1421,26 @@
 int 
-i
+c
  = 0; 
-i %3C rows.length; i
+c %3C cols; c
 ++) 
@@ -1451,49 +1451,75 @@
     
+  
 plants%5B
-i%5D = rows%5Bi%5D.toCharArray(
+r%5D%5Bc%5D = Plant.getPlant(sc.next().charAt(0)
 );%0A    
+  
 %7D%0A
+    %7D
 %0A   

Refactor parseDiagram