Chat with us, powered by LiveChat Give an example of a?while?loop, then provide the equivalent do-while loop and for loop.? Then give a different example of a?do-while?loop, along with the equivalent while loop and for lo | EssayAbode

Give an example of a?while?loop, then provide the equivalent do-while loop and for loop.? Then give a different example of a?do-while?loop, along with the equivalent while loop and for lo

1.Give an example of a while loop, then provide the equivalent do-while loop and for loop.  Then give a different example of a do-while loop, along with the equivalent while loop and for loop. Finally, give an example of a for loop, along with the equivalent while loop and do-while loop. Use your examples to illustrate the advantages and disadvantages of each looping structure, and describe those advantages and disadvantages.

Your Discussion should be at least 250 words in length, but not more than 750 words. Once you’ve completed your initial post, be sure to respond to the posts of at least 3 of your classmates.

2.attached

CS 1102 – Unit 2 Programming Assignment

First create a new Java class for this assignment. You should start in Eclipse with your CS1102 project from the previous assignment.

• Select "New"->"Class" from the File menu. • Enter the Name "Quiz". • Check the box "public static void main(String[] args)". • Click "Finish".

Now have your program ask a multiple-choice quiz question. You should create your own original quiz question.

• Create a String called "question" and initialize it to the question you want to ask. Use the characters "n" to start a new line. For example: String question = "What is a quiz?n"; (Use your own quiz question, not this one.)

• Add multiple choices starting with "A", "B", "C", "D", and "E" using the "+=" operator and "n". question += "A. a test of knowledge, especially a brief, informal test given to studentsn";

Ask the user your question using "JOptionPane.showInputDialog".

• Add the following import statement at the top of your code, before "public class Quiz", to give your program access to JOptionPane. import javax.swing.JOptionPane;

• Ask your question and store the answer in a String. In particular, add the following statement in your main method after setting all the lines of your question String. String answer = JOptionPane.showInputDialog(question);

Try running your program.

• Select "Run Configurations…" from the Run menu. • Change the Name from "SuperPower" to "Quiz". • Change the Main Class from "SuperPower" to "Quiz". • Click "Apply". • Click "Run".

A dialog box should appear with your question and a text field for the answer. (In the Virtual Lab, a "File Changed" dialog may pop up. Click "Yes". This will bring the main Eclipse window to the front, hiding the message dialog from your program. Move the main Eclipse window or minimize it, and you will see the message dialog behind it.)

Now modify your program to check the answer.

• Change the answer to upper case so lower-case input works. answer = answer.toUpperCase();

• Use an if statement to check the answer and display a message if it is correct. For example, if the correct answer is "A": if (answer.equals("A")) { JOptionPane.showMessageDialog(null,"Correct!"); }

Run your program and enter various answers. Make sure you get the correct response.

Modify your program so that it responds differently to different input.

• It should display one message if the answer is correct, like "Correct!" • It should display a different message if the answer is valid ("A", "B", "C", "D", or "E") but

incorrect, like "Incorrect. Please try again." • It should display a third message if the answer is invalid (anything other than single characters

"A", "B", "C", "D", and "E"), like "Invalid answer. Please enter A, B, C, D, or E."

Run your program and test each of these possibilities.

Modify your program so that it asks the question and responds with a dialog until the user enters the correct answer.

• Move the statements that record the answer and display a response into a while loop. • Use "break" or "return" to exit the loop when the answer is correct.

Now test your final program.

Upload the following for your Programming Assignment submission.

• Quiz.java • Screen shot showing the input dialog with the quiz question • Screen shot showing the message dialog for the correct answer • Screen shot showing the message dialog for a valid but incorrect answer • Screen shot showing the message dialog for an invalid answer

Related Tags

Academic APA Assignment Business Capstone College Conclusion Course Day Discussion Double Spaced Essay English Finance General Graduate History Information Justify Literature Management Market Masters Math Minimum MLA Nursing Organizational Outline Pages Paper Presentation Questions Questionnaire Reference Response Response School Subject Slides Sources Student Support Times New Roman Title Topics Word Write Writing