Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A Chinese restaurant wants to have a computer-based search system that will display a recipe for each dish. The owner of the restaurant wants the

A Chinese restaurant wants to have a computer-based search system that will display a recipe for each dish. The owner of the restaurant wants the system to be flexible in that its recipes are stored in a text file. This way, the number of dishes can be expanded by adding more entries to the text file without changing any program code.

After analyzing the coding the restaurant realizes that Current coding only outputs first two line of the recipe.

Goal: Correct/debug RecipeFinder class to have the full recipe description in the output console in eclipse rather than having only first two lines. Other features should remain the same.

Requirements

To get full credit, you must follow the requirements specified below:

1. Particularly, you cannot use the Scanner class to read data from the keyboard or from a file. Instead, you should use BufferedReader, FileReader, InputStreamReader.

2. Your code must match your design (the class diagram). This includes the number of classes; the methods inside classes; and the relationships among these classes.

3. Put the unreliable code into Javas Exception management system (proper use of try-catch construct).

4. Must use automatic file closing feature.

Implementation

Create the text recipefile.txt and save it to C:/tmp/ directory.

Edit the work class RecipeFinder inside the project. This is the most difficult class in this program. One thing you need to figure out is how to output the whole body of a recipe based on the specific knowledge of when 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;

DO THE FOLLOWING TO SCORE YOUR POINTS

- Draw a class diagram in the space below (name your work class RecipeFinder; the application class TestRecipeFinder):

- Paste your source code in the space below (make sure that your code works appropriately, the source code format conforms to Java conventions (with appropriate indentations, you may lose points for not indent appropriately)):

-Test your code

Start afresh.

Type the recipe name roast fish.

Type stop.

Do a screen capture of the output.

_________________________________________________________

Here is the content of the recipefile.txt in C:/tmp/ directory.

#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 source, half gallon of water. Cook 15 minutes.

#fried rice

plain rice, pork, chicken, beef, shrimp, vegetable, vegetable, include greens, mushroom, carrots, banana, apple source, 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 Source, Chicken with Oyster Source, Curry Chicken with onion, Chicken with Pepper & Tomato, Chicken with Broccoli, Chicken with Mixed Vegetable, Sweet & Sour Chicken, Chicken with Garlic Source, Hunan Chicken, Szechuan Chicken.

__________________________________________________________

class TestRecipeFinder {

public static void main(String[] args) {

RecipeFinder mysobj = new RecipeFinder("C:/tmp/recipefile.txt");

String sWrd;

System.out.print("Welcome to variable search program. "

+ "Enter 'stop' to end. ");

do {

sWrd = mysobj.getSWd();

if(mysobj.searchWd(sWrd)) {

System.out.println(mysobj.getLines());

}else if(sWrd.equals("stop")){

System.out.println("Bye!");

}

else {

System.out.println("Not found.");

}

} while(sWrd.compareTo("stop") != 0);

}

}

_________________________________________________________________________________________________

// The file to be searched is located in C:/tmp.

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.InputStreamReader;

import java.io.IOException;

class RecipeFinder {

String fName;

String line1, line2;

public RecipeFinder(String s) {

fName = s;

line1 = " ";

line2 = " ";

}

// Get a search word from keyboard.

String getSWd() {

String info = " ";

BufferedReader br = new BufferedReader(

new InputStreamReader(System.in));

System.out.print(" Enter a recipe name: ");

try {

info = br.readLine();

} catch (IOException exc) {

System.out.println("Error reading console.");

}

return info;

}

// Search the file for variable name using the string passed in

boolean searchWd(String tWrd) {

int ch;

String info = " ";

File file = new File(fName);

try (BufferedReader br = new BufferedReader(

new FileReader(file))) {

do {

// read characters until a # is found

ch = br.read(); // read() reads a byte and returns it as an

// integer

if (ch == '#') {

info = br.readLine();

info = info.trim(); // remove space on both ends

if (tWrd.compareTo(info) == 0) { // found variable

line1 = info;

info = br.readLine();

line2 = info;

return true;

}

}

} while (ch != -1);

} catch (IOException exc) {

System.out.println("Error accessing file.");

return false;

}

return false; // variable not found.

}

String getLines() {

String rStr = " ";

rStr = line1 + " " + line2;

return rStr;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago