Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Solution Description Create a file Giveaway. java that allows people to take items. We will provide you with an initial array containing items that are
Solution Description Create a file Giveaway. java that allows people to take items. We will provide you with an initial array containing items that are available to for grabs (represented by a 55 grid). Create a single Java class called Giveaway with a main method header. - Do NOT create a Scanner object outside of the main method. - Additionally, you must only create one instance of a Scanner object. 2D Array Chart The following String values must be stored within a 2D array called inventory. Create the 2D array with the values from the following chart. Each cell visually represents a space for an item. X represents that no item is currently at the location. For these locations, use " x " (lowercase) to represent empty spaces. Provided 2D array Name your program Giveaway. java, and it should work as follows. Acquiring items: - Welcome the user and print: "Welcome to the 1331 Giveaway!" - Prompt and ask the user if they want to take an item: "Would you like to take an item? [Y]es, [N]o, or [E]xit" - If the user inputs ' N ' (case sensitive), print: "Next person in line!" and prompt the next user the same prompt above. See example. - If the user inputs 'E' (case sensitive), print: "Have a good day!" and end the program gracefully (i.e., the program ends normally without any exceptions thrown) If the user inputs ' Y ', print the current state of the giveaway 2D array and then proceed to print: "What item are you interested in taking?" - At this point, the user should enter coordinates separated by a space where the row should be entered first followed by the column to the item's location. - See the next section titled "Item selection" for more details. Otherwise, if the user inputs a character outside of ' Y ', ' N ', or ' E, loop until the user inputs a proper character by prompting, "Please input ' Y ', ' N ', or ' E '." followed by the prompt "Would you like to take an item? [Y]es, [N]o, or [E]xit" - The giveaway program should be in a loop such that different users will be able to take an item until either ' E ' is inputted or there are no more items left. - Once there are no items left, instead of printing the regular prompt for Y/N/E, print: "Sorry, we have no more items!" The program should end gracefully afterwards. Note: in this case, "Have a good day!" should not be printed Item selection: - If the user input has an invalid row or invalid column, print: "Location does not exist." - Re-prompt the user "What item are you interested in taking?" - If the location inputted is empty (no item in it), print: "There is no item in this location." - Re-prompt the user "What item are you interested in taking?" - If the location inputted has an item, print: "You successfully took the [Name of the item]!" - Please be aware that we are only testing numeric input of the location in the correct format. 03 (correct format) - 0,3 (incorrect format) - 03 (incorrect format) - After an item has been taken, the grid containing the item should be replaced by " x ". Print out the new grid. - The program should loop back to the previous prompt, "Would you like to take an item? [Y]es,[N]o, or [E]xit Example Output\#1 - User input is bolded. (Your program should look exactly like this with the exact spacings and lines! If there is any deviation, you will lose points. For better readability, extra newline characters have been added between prompts. These new lines are optional but encouraged.) Welcome to the 1331 Giveaway! Would you like to take an item? [Y]es,[N], or [E] xit Example Output\#1 - User input is bolded. (Your program should look exactly like this with the exact spacings and lines! If there is any deviation, you will lose points. For better readability, extra newline characters have been added between prompts. These new lines are optional but encouraged.) Welcome to the 1331 Giveaway! Would you like to take an item? [Y]es, [N], or [E]xit Y xx StuffedPython x CSalt hAIrspray xxxx xxx JavaBeans x x RustedMetal SwiftShoes xx FuRniture xx GroovyGear RadiantRuby What item are you interested in taking? 05 Location does not exist. What item are you interested in taking? 0 You successfully took the CSalt! xx StuffedPython xx hAIrspray xxxx xxx JavaBeans x x RustedMetal Swiftshoes xx FuRniture xx GroovyGear RadiantRuby Would you like to take an item? [Y]es,[N], or [E] xit z Please input ' Y ', ' N ', or ' E '. Would you like to take an item? [Y] es, [N], or [E]it E Have a good day! Example Output\#2 - User input is bolded. (Your program should look exactly like this with the exact spacings and lines! If there is any deviation, you will lose points. For better readability, extra newline characters have been added between prompts. These new lines are optional but encouraged.) Welcome to the 1331 Giveaway! Would you like to take an item? [Y]es,[N], , or [E]xit Y xx StuffedPython x CSalt hAIrspray xxxx xxx JavaBeans x x RustedMetal SwiftShoes xx FuRniture xx GroovyGear RadiantRuby What item are you interested in taking? 105 Location does not exist
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started