Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java help with I/O Problem Description: A Chinese restaurant wants to have a computer based search system that will display a recipe for each dish.

Java help with I/O

Problem Description: 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. The implementation method for this application should be very similar to Example 4 in Week 8s lecture notes. The user obtains a recipe by typing its name. The program searches the recipe file for the recipe. If it is found, the content of the recipe will be displayed. Otherwise, the message of Not found will be displayed. The program will run continuously until the user types stop. Initially, the program should output the following message to the DOS console:

Welcome to Chinese recipe search program.

Enter stop to end.

Enter a recipe name:

The program then waits for the user input. Depending on the input, the program will either continuously offer the prompt Enter a recipe name: or quit (output the message Bye!).

The recipe file is a standard text file that is organized like this:

#recipe-name1

recipe body

#recipe-name2

recipe body

#recipe-name3

recipe body

To make it simpler, we will hardcode the file name; we will assume the short text file (named recipefile.txt). The name of each recipe must be preceded by a #, and the recipe name must be on a line of its own. Preceding each recipe name with a # allows the program to quickly find the start of each recipe. Following the recipe name are any number of information lines about the recipe. However, there must be a black line between the end of one recipes information and the start of the next recipe. Here is the content of the recipe file:

#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.

Steps in finishing the assignment

You need to do the design before writing the code. Follow the following steps to finish the assignment.

Program Design

As one of the design documentation, you need to draw a class diagram using UML notation. Based on the class diagram, you write Java source code. Your class diagram must match the Java source code. There are many complete application examples in lecture notes. You may follow the same design patterns: two-class pattern (one application class and one work class) given in the lecture notes. Particularly, you are going to design two classes with association relationship (TestRecipeFinder uses RecipeFinder).

The Requirements

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

You must use the classes introduced in Week 8 lecture notes. Particularly, you cannot use the Scanner class to read data from keyboard or from a file. Instead, you should use BufferedReader, FileReder, InputStreamReader.

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

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

Must use automatic file closing feature.

Implementation

It is recommended that you follow the steps below:

Create a text file called recipefile.txt and save it to C:/tmp/ directory.

Create a Java project (ics141prg5) using Eclipse.

Create an application class TestRecipeFinder inside the project. This class will contain a special main() method.

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;

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)):

Use the following input sequence, then do a screen capture of the output. You must follow the instructions in this section to get full credits.

Test Case 1 (non successful search):

Start afresh.

Type the recipe name roast dog.

Do a screen capture of the output.

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

Step: 3

blur-text-image

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

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions