20 Nov 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
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.
About Wridemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. 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.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
