Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a work class “RecipeFinder” inside the project. This is the most difficul

ID: 3855701 • Letter: C

Question

Create a work class “RecipeFinder” inside the project. This is the most difficulty class in this program. One thing you need to figure out is how to output the body of a recipe based on the specific knowledge of there is an empty line between the current recipe and the one following it. To help you, I offer the following segment of code (you are not required to use it) for you to use:

do {

            info = br.readLine();

            if(info != null) System.out.println(info);

} while((info != null) && (info.trim().compareTo(“ ”) != 0));

return true;

Explanation / Answer

TestRecipeFinder.java
-------------------------------------------
import java.io.*;

public class TestRecipeFinder {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String recipe = "";

        RecipeFinder myRecipe = new RecipeFinder();

        System.out.println("Welcome to Chinese recipe search program.");
        System.out.println("Enter 'stop' to end.");

        while (!((recipe.equals("stop")))) {
            InputStreamReader instream = new InputStreamReader(System.in);
            BufferedReader ins = new BufferedReader(instream);
            System.out.print("Enter a recipe name: ");
            try {
                recipe = ins.readLine();
                if (recipe.equals("stop")) { break; }
                myRecipe.setRecipe(recipe);
                myRecipe.getIngredients();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println("Invalid input type.");
                System.exit(-1);
            }
        }
        System.out.println("Bye!");
    }

}

------------------------------------------------------------------------------------
RecipeFinder.java
-------------------------------------------
import java.io.*;

public class RecipeFinder {
   /*
   * instance variables
   */
   private String recipe;
   private String ingredients;
   private BufferedReader br;
  
   /*
   * class methods
   */
  
   // constructor method
   public RecipeFinder() {

   }
  
   // setting value for recipe
   public void setRecipe (String recipe) {
       this.recipe = "#" + recipe;      
   }
  
   // reading value for the
   public String readIngredients() {
       String str;
       try (BufferedReader br = new BufferedReader(new FileReader("recipefile.txt"))) {
           // reading until we get #this.recipe
           try {
               do {
                   str = br.readLine();
                   if (str.equals(this.recipe)) {
                       this.ingredients = br.readLine();
                       return this.ingredients;
                   }
               } while (str != null);
               return ("Recipe could not be found.");
           } catch (IOException recipenotfound) {
               return ("Recipe " + this.recipe + " could not be found.");
           }
       } catch (IOException filenotfound) {
           // TODO Auto-generated catch block
           return ("File could not be found.");
       }
   }
}

-------------------------------------------------------------------------------------------------
recipefile.txt
------------------------------------------------------
#appetizers
vegetable, egg roll, mixed with cream cheese, add some Teriyaki chicken, half gallon of water. Cook 15 minutes.

#chow mein
white meat chicken, pork beef, shrimp, vegetable include greens, mushroom, carrots, banana, apple sauce, half gallon of water. Cook 15 minutes.

#fried rice
plain rice, pork, chicken, beef, shrimp, vegetable, vegetable, include greens, mushroom, carrots, banana, apple sauce, one ounce of vegetable oil. Add the oil to a wok first, using hot fire to cook the oil to hot and able to see slight smoke. Then add all the ingredients and mix them. Cook 15 minutes.

#poultry dish
Moo Goo Gai Pan, Chicken with Mushroom, Chicken with Black Bean Sauce, Chicken with Oyster Sauce, Curry Chicken with onion, Chicken with Pepper & Tomato, Chicken with Broccoli, Chicken with Mixed Vegetable, Sweet & Sour Chicken, Chicken with Garlic Sauce, Hunan Chicken, Szechuan Chicken

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote