Question

In: Computer Science

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
$14
spicy chicken
juice
potato

SET3
Texas Chicken
Juice
Potato Bowl

...and etcetera.

Solutions

Expert Solution

Here is the answer for your question in Java Programming Language.

You can use a class (ex: FoodStorage) to have all the details of a food set in one place and you can create array of objects of the class as array of foodsets and store data in the array.

I have used the above given approach to store and search a food set by using the food set name.

Kindly upvote if you find the answer helpful. Please comment if you have any doubts. Thank you.

CODE :

FoodStorage.java

public class FoodStorage {
  
//Required variables
private String setName;
private double cost;
private String mainCourse;
private String softDrink;
private String starters;
  
//Default constructor
FoodStorage(){ }
  
//Parameterized constructor
public FoodStorage(String setName, double cost, String mainCourse, String softDrink, String starters) {
this.setName = setName;
this.cost = cost;
this.mainCourse = mainCourse;
this.softDrink = softDrink;
this.starters = starters;
}
  
//Getters

public String getSetName() { return setName; }
public double getCost() { return cost; }
public String getMainCourse() { return mainCourse; }
public String getSoftDrink() { return softDrink; }
public String getStarters() { return starters; }
  
//toString() to display contents of class object
@Override
public String toString() {
return setName + "\n$" + cost + "\n" + mainCourse + "\n" + softDrink + "\n" + starters;
}
  
}

TestFoodStorage.java (This program is used to search a food set)


import java.util.Scanner;

public class TestFoodStorage {
  
public static void main(String[] args){
  
//String to store setname given by user
String setName;
  
//Scanner object to read input from user
Scanner s = new Scanner(System.in);
  
//Create array for FoodStorage objects
FoodStorage[] foodsets = new FoodStorage[5];
  
//Store data in the array of FoodStorage objects
foodsets[0] = new FoodStorage("SET1",10,"Cheese Burger","Coke","Fries");
foodsets[1] = new FoodStorage("SET2",14,"Spicy Chicken","Juice","Potato");
foodsets[2] = new FoodStorage("SET3",10,"Veg Pizza","Lemon Juice","Manchurian");
foodsets[3] = new FoodStorage("SET4",10,"Fried Rice","Pepsi","Aloo fries");
foodsets[4] = new FoodStorage("SET5",10,"Veg Pulao","Orange Juice","Cake");
  
//Display entire food menu
System.out.println("--------------------------");
System.out.println("Your entire food menu: ");
System.out.println("--------------------------");
//Loops thorugh every food set in foodsets array
for(FoodStorage foodset : foodsets){
//Prints the food set details
System.out.println(foodset);
System.out.println();
}
//Read the set name from the user in order to do a search
System.out.println("--------------------------");
System.out.print("Enter the set you want to search: ");
setName = s.nextLine();
  
//Call searchFoodSet method with setName given by user and foodsets array as parameters
searchFoodSet(setName,foodsets);
  
}
//Implementation of searchFoodSet
public static void searchFoodSet(String setName,FoodStorage[] foodsets){
  
//Create a flag and set it initially to false
boolean exists = false;
//Loop throug every food set in the foodsets array
for(FoodStorage foodset : foodsets){
//If set name of any food set matches given food set name
if(foodset.getSetName().compareToIgnoreCase(setName) == 0){
//Set the falg to true
exists = true;
//Print food set details
System.out.println("--------------------------");
System.out.println("Food Set Details");
System.out.println("--------------------------");
System.out.println(foodset);
}
}
//If the flag is false dsplay appropriate message
if(!exists){
System.out.println("--------------------------");
System.out.println("Food set " + setName + " has not been found in the food storage.");
System.out.println("--------------------------");
}
}
}

SCREENSHOTS :

Please see the screenshots of the code below for the indentations of the code.

FoodStorage.java

TestFoodStorage.java

OUTPUT :

If a set name which is not there in food storage is given,

Any doubts regarding this can be explained with pleasure :)


Related Solutions

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 ?
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...
Please research some more information on the benefits of using a POS system such as the...
Please research some more information on the benefits of using a POS system such as the MICROS or Squirrel? After collecting the information, please prepare a tabulation with two columns, In the left column list out the important functions that the POS system will perform, In the column on the Right side Explain briefly as to how you think you would have done / prepared a similar report in the absence of the POS or Computers. Limit your Report to...
Donna opened a restaurant, and she notices that by the time customers get the food, they...
Donna opened a restaurant, and she notices that by the time customers get the food, they seem irritated and impatient. She wants to investigate the problem further, so she hires you to design a research project to figure out what is bothering the customers. Discuss the steps it should undertake in this marketing research project.
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...
Alice works at the local restaurant as a food server. She typically earns 18% tips on...
Alice works at the local restaurant as a food server. She typically earns 18% tips on her tables served during her shift. From her tip earnings she is required to pay 5% of liquor sales served at her tables to the bartender. Additionally, she is required to pay 2% of her total sales to the hostess. Alice averages sales of 80% food and 20% liquor. This is the last night Alice works before rent is due and she is $92...
The manager of a fast-food restaurant wants to reduce the proportion of drive-through customers who have...
The manager of a fast-food restaurant wants to reduce the proportion of drive-through customers who have to wait longer than 2 minutes to receive their food after placing an order. Based on store records, the proportion of customers who had to wait longer than 2 minutes was p = 0.63. To reduce this proportion, the manager assigns an additional employee to assist with drive-through orders. During the next month, the manager will collect and random sample of drive through times...
Anna wants to have $5,000 saved when she graduates from college so that she will have...
Anna wants to have $5,000 saved when she graduates from college so that she will have a down payment for a new car. She already saved $300 dollars and her credit union pays 4% annual interest compounded monthly. How much money should she deposit each month to have the money available when she graduates in 3 years?
Many fast food restaurant chains, such as McDonald's, will occastionally discontinue restaurants in their system. What...
Many fast food restaurant chains, such as McDonald's, will occastionally discontinue restaurants in their system. What are some financial considerations in deciding to eliminate a store?
C++ Linkedlist Create a food menu so the customer can see what we are selling, if...
C++ Linkedlist Create a food menu so the customer can see what we are selling, if the users place order that not on the menu, prompt the users to enter again. Food code and food must be matched when users enter.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT