Question

In: Computer Science

Mr Allen is selling 5 sets of western food in restaurant. He wants to build a...

Mr Allen is selling 5 sets of western food in restaurant. He wants to build a food ordering system. So if the system has added 5 sets of western food inside the text file, how to use search function to search the foods from the text file by using(( JAVA )) and display it ?

Solutions

Expert Solution

CODE (AS TEXT) ->

import java.io.File;
import java.util.Scanner;
import java.util.ArrayList;
  
public class Solution3
{
   public static void main(String[] args) throws Exception
   {
       File file = new File("C:\\Users\\ishu\\Desktop\\menu.txt"); // creating a new file object to read the input file
       Scanner s=new Scanner(file); // scanner object is created which reads the file
      
       ArrayList<String> menu=new ArrayList<String>(); // list to store the menu items
       String searchItem="Cheesy Rice and Broccoli Casserole";
         
       while(s.hasNextLine()) // loop terminates when there is no new line in the file
       {
           String nextItem=s.nextLine(); // next item of the menu (read from text file)
           menu.add(nextItem); // the read item is added in the list
             
           if(searchItem.contentEquals(nextItem)) //if the desired item is found
               System.out.println("Your item : " +searchItem+ " is found in the menu");
       }
         
       System.out.println("The entire menu is : "); // to print the entire menu
       System.out.println(menu);
   }
}

OUTPUT (ALONG WITH TEXT FILE) ->

CODE (IN THE CODE SNIPPET)  ->

import java.io.File; 
import java.util.Scanner; 
import java.util.ArrayList;
  
 public class Solution3
 {
         public static void main(String[] args) throws Exception
         {
                 File file = new File("C:\\Users\\ishu\\Desktop\\menu.txt");         // creating a new file object to read the input file
                 Scanner s=new Scanner(file);                                        // scanner object is created which reads the file
                
                 ArrayList<String> menu=new ArrayList<String>();                     // list to store the menu items
                 String searchItem="Cheesy Rice and Broccoli Casserole";
                 
                 while(s.hasNextLine())                                              // loop terminates when there is no new line in the file
                 {
                         String nextItem=s.nextLine();                                   // next item of the menu (read from text file)
                         menu.add(nextItem);                                             // the read item is added in the list
                         
                         if(searchItem.contentEquals(nextItem))                          //if the desired item is found
                                 System.out.println("Your item : " +searchItem+ " is found in the menu");
                 }
                 
                 System.out.println("The entire menu is : ");                         // to print the entire menu
                 System.out.println(menu);
         }
 }

NOTE ->

(i) i gave you code twice once as text and once in the code snippet because some students complaint about adding of extra invisible character in code , so i gave you code twice once a code and once as text , whatever works for you.

(ii) please change the name and location of the text file according to your file otherwise it may give you error.

I HOPE YOU WILL GET IT..............YOUR RESPONSE WILL BE HIGHLY APPRECIATED.


Related Solutions

Glenn is selling food in restaurant. She is using POS system. So if she wants to...
Glenn is selling food in restaurant. She is using POS system. So if she wants to store the food sets in array, how to use search function to search the food sets from the array by using(( JAVA )) and display it ? I want a sample like this, thank you For example: Enter the set you want to search: SET1 SET1 $10 Cheese Burger Coke fries --------------------------------------------------------- Your Entire food menu : SET1 $10 Cheese Burger Coke fries SET2...
1.A fast-food restaurant selling soft drinks advertises that they contain 15 ounces. A manager wants to...
1.A fast-food restaurant selling soft drinks advertises that they contain 15 ounces. A manager wants to find out whether the drinks are being overfilled. A random sample of 10 independently chosen drinks produced a mean of 15.6 ounces with a standard deviation of 0.4 ounce. Assume that the distribution of serving sizes in the population is Normally distributed. Carry out the appropriate hypothesis test using a 1% significance level. Explain what conclusion the manager should reach. 2.The mean weight of...
Ross has decided that he wants to build enough retirement wealth that, if invested at 5...
Ross has decided that he wants to build enough retirement wealth that, if invested at 5 percent per year, will provide him with $4,400 of monthly income for 30 years. To date, he has saved nothing, but he still has 20 years until he retires. How much money does he need to contribute per month to reach his goal? First compute how much money he will need at retirement, then compute the monthly contribution to reach that goal.
Ross has decided that he wants to build enough retirement wealth that, if invested at 5...
Ross has decided that he wants to build enough retirement wealth that, if invested at 5 percent per year, will provide him with $5,000 of monthly income for 30 years. To date, he's saved nothing, but he still has 20 years until he retires. How much money does he need to contribute per month to reach his goal?
Choose a fast food restaurant and select 5 types of food from the restaurant listing the...
Choose a fast food restaurant and select 5 types of food from the restaurant listing the fat grams and total calories for each type of food. Subsequent posting Thursday to Sunday, 11:59 PM: Is there a linear relationship between the two variables?  Use excel and include the scatterplot (select chart, scatter) and r-value (=COREL(input data) to support your decision regarding whether there is a relationship or not. You must also respond to at least one of your colleagues to help them...
Allen wants to open a savings account. He will transfer $40,000 from another account to the...
Allen wants to open a savings account. He will transfer $40,000 from another account to the savings account today. After that, he will deposit $1,000 every month to the savings account. If the annual interest rate is 3.2%, what will be the account balance in his savings account after 5 years? a. $112,653.52 b. $123,877.44 c. $123,877.23 d. $111,903.31 how would this be solved using finance functions in excel?
The owner of a restaurant that serves continental food wants to study characteristics of his customers....
The owner of a restaurant that serves continental food wants to study characteristics of his customers. He decides to focus on two variables: the amount of money spent by customers and whether customers order dessert. The results from a sample of 60 customers are as follows: • Amount spent ( =$38.54, S= $7.26) • 18 customers purchased dessert. Construct a 95% confidence interval estimate of the population mean amount spent per customer in the restaurant.      _____________ Construct a 90% confidence...
Answer Problems below: Q1. Mr. Miles is a first time investor and wants to build a...
Answer Problems below: Q1. Mr. Miles is a first time investor and wants to build a portfolio using only U.S. T-bills and an index fund that closely tracks the S&P 500 Index. The T-bills have a return of 5%. The S&P 500 has a standard deviation of 20% and an expected return of 15%. 1. Draw the CML and mark the points where the investment in the market is 0%, 25%, 75%, and 100%. 2. Mr. Miles is also interested...
Q. Mr. Miles is a first time investor and wants to build a portfolio using only...
Q. Mr. Miles is a first time investor and wants to build a portfolio using only U.S. T-bills and an index fund that closely tracks the S&P 500 Index. The T-bills have a return of 5%. The S&P 500 has a standard deviation of 20% and an expected return of 15%. 1. Draw the CML and mark the points where the investment in the market is 0%, 25%, 75%, and 100%. 2. Mr. Miles is also interested in determining the...
William is a restaurant owner. He has 5 restaurants in Virginia, Maryland and DC. He is...
William is a restaurant owner. He has 5 restaurants in Virginia, Maryland and DC. He is going through an extremely tough time due to Coronavirus crisis. He had to shut down his restaurants, as ordered by authorities. His restaurants are allowed to serve “take away” orders, however the revenue is very low to cover his costs. William’s restaurants are located within a 45 minutes radius. Financial information is shown below; Restaurant Locations 1 DC- Business Distric 2 Bethesda 3 Arlington...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT