13 Jun In Module Five, you have studied how to code for iteration through the use of loops. In Stepping Stone Lab Four, you will develop a simple program with a loop structure.
In Module Five, you have studied how to code for iteration through the use of loops. In Stepping Stone Lab Four, you will develop a simple program with a loop structure. Then, you will reflect on how loops may be used to help structure the program you have worked with throughout the stepping stones.
The Stepping Stone4_Loop for the starter code for this assignment.
To complete this assignment, review the following documents:
Stepping Stone Lab Four Guidelines
Loops
Overview: In Module Five, you have studied how to code for iteration through the use of loops. In Stepping Stone Lab Four, you will develop a simple program with a loop structure for users to enter a list of ingredients.
Be sure to review the Stepping Stone Lab Four guidelines before beginning this lab. The completed code (.java file) from Stepping Stone Lab Three is included in this module to use as a reference for comparison of your work in Module Four as well as moving forward. This code serves a number of functions:
· It allows you to review your own submitted code.
· You may utilize it as a useful foundation for Stepping Stone Lab Three as well as other assignments to come.
· Together with instructor feedback on your submitted code, you are building your own final project application.
The code for this stepping stone lab is short, but the concepts are extremely important. You will use two different looping techniques: a “do” loop and a “for” loop. This stepping stone lab also includes your first application of the Java ArrayList data type. In this stepping stone lab, you will use the ArrayList to store strings, but in future submissions, you will replace these with object types (ingredients).
Prompt: In this lab, you will write a short Java application that uses a loop control structure. Specifically, your application should accomplish the following:
· Create an ArrayList<String> to store the list of ingredient names added by the user.
· Implement the do while loop structure to allow the user to add ingredients until he or she is done.
· Within your loop, add a branch control structure to prompt the user to enter an ingredient or indicate that he or she is finished.
· Use a for loop to iterate through the ingredientList to print the ingredients in the list.
Guidelines for Submission: This assignment should be submitted as a Java file.
,
package SteppingStones; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.Scanner; import java.util.ArrayList; public class SteppingStone4_Loops { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String recipeName = ""; ArrayList<String> ingredientList = new ArrayList(); String newIngredient = ""; boolean addMoreIngredients = true; System.out.println("Please enter the recipe name: "); recipeName = scnr.nextLine(); do { System.out.println("Would you like to enter an ingredient: (y or n)"); String reply = scnr.next().toLowerCase(); /** * Add your code here (branches work well!). The code should check the * reply: * "y" –> prompt for the ingredient and add it to the ingredient list; * "n" –> break out of the loop; * (Hint: what is the 'while' condition? What could you change to * stop the loop from starting over?) * anything else –> prompt for a "y" or "n" * */ } while (addMoreIngredients); for (int i = 0; i < ingredientList.size(); i++) { /** * Get the item i from the ingredient list * and assigning it to the String ingredient * */ String ingredient = ???; System.out.println(ingredient); } } }
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.