class BakedItemList {

   public void readItemFile(String fileName) throws IOException {
      Scanner scan = new Scanner(new File(fileName));
      listName = scan.nextLine();
      String[] elements;
      char type;
      String typeS;
      while (scan.hasNext()) {
         String input = scan.nextLine();
         elements = input.split(",");
         typeS = elements[0];
         type = typeS.toUpperCase().charAt(0);

         // Switch variables
         String nameIn;
         String flavorIn;
         int quantityIn;
         double crustCostIn;
         int layersIn;
         int tiersIn;
         String[] ingredients = new String[50];
         int j;
         String[] ingredientsTrim;

         switch (type) {
            case 'C':
               nameIn = elements[1];
               flavorIn = elements[2];
               quantityIn = Integer.parseInt(elements[3]);
               j = 0;
               for (int i = 0; i < elements.length - 4; i++) {
                  ingredients[i] = elements[i + 4];
                  j++;
               }
               ingredientsTrim = Arrays.copyOf(ingredients, j);
               Cookie c = new Cookie(nameIn, flavorIn, quantityIn,
                     ingredientsTrim);
               itemList[itemCount] = c;
               itemCount++;
               break;

            case 'P':
               nameIn = elements[1];
               flavorIn = elements[2];
               quantityIn = Integer.parseInt(elements[3]);
               crustCostIn = Double.parseDouble(elements[4]);
               j = 0;
               for (int i = 0; i < elements.length - 5; i++) {
                  ingredients[i] = elements[i + 5];
                  j++;
               }
               ingredientsTrim = Arrays.copyOf(ingredients, j);
               Pie p = new Pie(nameIn, flavorIn, quantityIn, crustCostIn,
                     ingredientsTrim);
               itemList[itemCount] = p;
               itemCount++;
               break;

            case 'K':
               nameIn = elements[1];
               flavorIn = elements[2];
               quantityIn = Integer.parseInt(elements[3]);
               layersIn = Integer.parseInt(elements[4]);
               j = 0;
               for (int i = 0; i < elements.length - 5; i++) {
                  ingredients[i] = elements[i + 5];
                  j++;
               }
               ingredientsTrim = Arrays.copyOf(ingredients, j);
               Cake k = new Cake(nameIn, flavorIn, quantityIn, layersIn,
                     ingredientsTrim);
               itemList[itemCount] = k;
               itemCount++;
               break;

            case 'W':
               nameIn = elements[1];
               flavorIn = elements[2];
               quantityIn = Integer.parseInt(elements[3]);
               layersIn = Integer.parseInt(elements[4]);
               tiersIn = Integer.parseInt(elements[5]);
               j = 0;
               for (int i = 0; i < elements.length - 6; i++) {
                  ingredients[i] = elements[i + 6];
                  j++;
               }
               ingredientsTrim = Arrays.copyOf(ingredients, j);
               WeddingCake w = new WeddingCake(nameIn, flavorIn, quantityIn,
                     layersIn, tiersIn, ingredientsTrim);
               itemList[itemCount] = w;
               itemCount++;
               break;

            default:
               excludedRecords[excludedCount] = input;
               excludedCount++;
               break;
         }
      }
   }

   public  BakedItemList();

}