Question: This program takes input from the user and prints out a formatted grocery list. For example, the parts in bold were entered by the user.

 This program takes input from the user and prints out a

formatted grocery list. For example, the parts in bold were entered bythe user. Once read, the user input will be modified to fit

the following rules: 1. Store name: no leading or trailing whitespace; all

This program takes input from the user and prints out a formatted grocery list. For example, the parts in bold were entered by the user. Once read, the user input will be modified to fit the following rules: 1. Store name: no leading or trailing whitespace; all characters should be upper case; the only String that may contain a space character (can be multiple words). 2. All food and drink: no leading or trailing whitespace; all characters should be lower case. Note to remove any leading/trailing whitespace you may want to consider using the .trim() method for strings! Below is an example of input, in bold, for the grocery list program. Each amount/weight in the input are followed by their corresponding food/drink (amount1 corresponds to food 1 , amount 3 corresponds to drink, etc). Store: the Farmer's Market weight: 5 food: Apples count: 12 drink: milK Note the store/amount/food/drink labels will not be included in the input. Thus the input alone will be as follows: the Farmer's Market 3.2 ApPles 3 milK The resulting grocery list is: I am going to THE FARMER'S MARKET to get: 3.2 pounds of apples 3 bottles of milk Note: there should always be 2 items in the grocery list, with the first item in units of pounds, and the second item in units of bottles. The names of the items are all converted to lowercase. Requirements: - Your main method should contain all input code (e.g., Scanner instance) and have 5 user prompts inputting values with nextLine(), nextDouble(), next(), and nextlnt(). - All output code (e.g., print statements) must be in the main method as well. The makeGroceryList method takes the arguments passed in and prepares the entire grocery list, using all the 5 parameters and returning one long String. You will need to use string concatenation to create this one long string combining all the variables. - You do not need to use the above grocery list. You can try out your own input values. Note that you may change the makeGroceryList parameter names to be more meaningful, but be sure to keep the order and data types the same. It is good practice to test different combinations of input with your method, but note that we will test your method using specific input for this lab. When calling makeGroceryList, the arguments passed are by position (the order in which they show up as parameters in the method header), so the parameter names do not matter outside the method. Also note that the grocery list should NOT end with a newline character. Note: (1) A common error found when running this program is an InputMismatchException error. This occurs when a scanner is looking for one type of object but finds another (for example scnr.nextInt() is looking for an integer when the next value may be a string). Be sure the order in which you read in inputs matches the expected type. Hint: Read 3L / Tutorial: Using Scanner to make sure you understand the differences among nextInt(), nextDouble(), next(), and nextLine() on reading the input. (Especially how nextLine() is different from others.) import java.util. Scanner; / * Reads in items and prepares a formatted grocery list. */ public class GroceryList \{ / * Returns a single String that is formatted as a grocery list that contains all * 5 parameters. * There are no input or output statements in this method. All input should * already be done in main (when the user is prompted), and all output should be * done in main after this method returns. * DO NOT MODIFY THE METHOD HEADER. If you do, you may not pass the * automatic tests that we use to grade your submission. * @param storeName * @param weight * @param food * @param count *@param drink * @return A grocery list that contains all 5 parameters. */ public static String makeGrocerylist(String storeName, double weight, String food, int count, String drink) \{ String list = "I am going to " + storeName +"; //revise return list; 3 / * Read in 5 input values and prints out a formatted list created by the * makeGrocerylist method

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!