Answered step by step
Verified Expert Solution
Question
1 Approved Answer
IS 2031: LE 3.2 Purpose: To code a program using a while-loop with nested (embedded) if and if-else structures. Prep Work: Chapters 2 and 3
IS 2031: LE 3.2 Purpose: To code a program using a while-loop with nested (embedded) if and if-else structures. Prep Work: Chapters 2 and 3 (to include Shepherd's PowerPoints). Examine if else Example.pdf (shows you how to nest if-else structures) Examine Capturing Character Input.pdf (shows how to capture and use a single character for your sentinel-controlled while-loop). Instructions: Name your program YourLastNameFirstInitialLE32. Code a program that 1. asks for the number of traffic violations, 2. then asks for the number of months within which these violations were incurred. 3. If the number of violations is greater than 3 and the number of months is less than or equal to 12, or the number of violations is greater than 6 and the number of months is less than 25, a. set a boolean variable called suspendLicense to true. b. If the license is suspended print the suspension message; otherwise, print the non- suspension message. c. The messages can be found in the attached sample output. d. Code 2 single-selection IFs that nest the test for the month to determine whether the license is suspended. e. Code a double-selection IF (if-else) to determine which message to print based on the truth value of suspendLicense. 4. Use a sentinel-controlled while loop. The while loop contains all the prompts (except for the priming-read prompt), ifs, nested ifs, if-else, and messages along with the re- prompt for the sentinel variable. a. You'll have to reset suspendLicense to false within the while loop. b. Don't forget an empty call to nextLine(). c. Refer to the sample output for the sentinel variable prompt. 5. Use printf(): refer to Demo Printf.java. 6. Exit the main(). 7. Refer to sample output for additional output details. Do you want to see if your license is suspended? Enter 'Y' or 'N': y How many traffic violations have you had? 4 within a period of how many months were these violations committed? 6 Your license is suspended! Do you want to see if your license is suspended? Enter 'Y' or 'N': y How many traffic violations have you had? 7 within a period of how many months were these violations committed? 12 Your license is suspended! Do you want to see if your license is suspended? Enter 'Y' or 'N': y How many traffic violations have you had? 2 within a period of how many months were these violations committed? 18 Lucky day! Your license is NOT suspended. Do you want to see if your license is suspended? Enter 'Y' or 'N': n
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