This assignment will involve Exceptions.
You are charged with helping a restaurant implement electronic ordering. You have access to a food database, as represented by the file Food.txt
. You also have access to a drink database, as represented by the file Drink.txt
. You will prompt the customer to enter their food item, and then their drink item. If the user enters a food item that does not exist, but their drink exists, you must generate a FoodNotFoundException
, a custom exception that you will build. If the user enters a drink item that does not exist, but their food exists, you must generate a custom DrinkNotFoundException
. If both their food and drink selections do not exist, you must generate a custom FoodAndDrinkNotFoundException
. All of your exceptions must be CHECKED EXCEPTIONS. If the user generates any of these exceptions, your program should not crash, but rather it should ask them again to enter their food and drink selections.
You will have to create the files Restaurant.java
, FoodNotFoundException.java
, DrinkNotFoundException.java
, and FoodAndDrinkNotFoundException.java
.
This class contains the following methods.
public static void main(String args[])
: prompts the customer to enter their food selection and their drink selection, then calls checkOrder
, passing in the food, drink, and the file names. The file names must be entered as command line arguments. DO NOT hard code the file names or prompt the user to enter them.
FileNotFoundException
), but do not prompt the customer to enter their food or drink again.public static void checkOrder(String food, String drink, String foodfile, String drinkFile)
: calls checkFood and checkDrink.
checkFood
and checkDrink
return false, throw a FoodAndDrinkNotFoundException
with the message “Our food menu doesn’t have food
and our drink menu doesn’t have drink
!”checkFood
returns false, throw a FoodNotFoundException
with the message “Our food menu doesn’t have food
!”checkDrink
returns false, throw a DrinkNotFoundException
with the message “Our drink menu doesn’t have drink
!”checkFood
and checkDrink
return true, simply print out “Order successful!” and the program should end.public static boolean checkFood(String food, String foodFile)
: reads through the file with name provided by the parameter foodfile
and determine if the food parameter that was passed in exists in the file. If it does, return true. If not, return false. DO NOT handle FileNotFoundException
in this method, only declare it as thrown.public static boolean checkDrink(String drink, String drinkFile)
: reads through the file with the name provided by the parameter drinkFile
, and determines if the drink parameter that was passed in exists in the file. If it does, return true. If not, return false. DO NOT handle FileNotFoundException
in this method, only declare it as thrown.These are CHECKED exceptions. For each Exception, implement a one argument constructor that takes in an error message as a String and properly sets the message. Hint: When the getMessage
method is called on any of these exceptions it should return the error message.
These files have been provided for you. They contain foods and drinks that the restaurant offers. The format will be as follows, where each line contains a separate item:
fajita
burrito
quesadilla
To compile your code simply run javac *.java
from the directory in which your java and text files are located. Run java Restaurant Food.txt Drinks.txt
in order to test your code. You can look through the text files to see which foods and drinks exist. Try entering various combinations of correct and incorrect foods and drinks, and see if the appropriate error messages print out.
You will need to write Javadoc comments along with checkstyling your submission. Some javadocs have already been provided for you. You also do not need to worry about writing javadocs for BuildTeam.java. However, you will need to modify the javadoc for the ComparableCollection class after modifying the class header appropriately.
Every class should have a class level Javadoc that includes @author <GT Username>
and @version <version #>
.
Every method should have a Javadoc explaining what the method does and includes any of the following tags if applicable.
@param <parameter name> <brief description of parameter>
@returns <brief description of what is returned>
@throws <Exception> <brief explanation of when the given exception is thrown>
See the CS 1331 Style Guide section on Javadoc comments for examples.
You must run checkstyle on your submission. The checkstyle cap for this submission is 30 points.
Run checkstyle for this assignment with java -jar checkstyle-6.2.2.jar -a *.java
. This will check for both checkstyle errors and javadoc errors.
When completing homeworks for CS1331 you may talk with other students about:
You may not discuss, show, or share by other means the specifics of your code, including screenshots, file sharing, or showing someone else the code on your computer, or use code shared by others.
Examples of approved/disapproved collaboration:
s 10:40 on Thursday... can I see your code? I won
t copy it directly I promise”Collaborating with others in a way that violates the approved means is a Georgia Tech Honor Code violation.
YOUR SUBMISSION SHOULD ONLY CONTAIN .JAVA FILES!
Compress the hw6 files into a .zip file and submit that on T-square. Make sure the zip file contains Restaurant.java
, FoodNotFoundException.java
, DrinkNotFoundException.java
, and FoodAndDrinkNotFoundException.java
. Do NOT submit your .class files.
Practice safe submission! Verify that your HW files were truly submitted correctly, the upload was successful, and that your program runs with no syntax or runtime errors. It is solely your responsibility to turn in your homework and practice this safe submission safeguard.
This procedure helps guard against a few things.