Download presentation
Presentation is loading. Please wait.
Published by壁 季 Modified over 7 years ago
1
Do-While Loops A do-while loop is always guaranteed to iterate at least once. This is because the condition is evaluated at the end of the loop, instead of the beginning (as is done in while and for loops). Note: a do-while loop is the only loop that requires a semi-colon. Demo: DoWhileDemo
2
Sentinels A sentinel is a value that the user can enter in order to stop the loop Usually seen in while or do-while loops Demo: Sentinel
3
Java’s Math class Allows you to do basic math functions
Not necessary to import it 3 methods you must know: Math.abs(num) // find the absolute value of num Math.pow(base, exp) // raises base to the exp power Math.sqrt(num) // finds the square root of num Demo: MathDemo
4
Open Powerpoint 1.5 – review the String examples, especially the substring method.
Also open the assignment Middle
5
Assignment: QBrating Click here for the NFL QB Rating Formula. Write a program that asks the user for an NFL QB’s stats (completions, attempts, yards, TDs, and interceptions). Then, click here for Peyton Manning’s 2014 stats, and use them to make sure that your program displays his correct QB rating (101.5). ***On the QB rating page, take note of the line “a, b, c, and d can not…” – this means that if any of them exceed 2.375, then you must set it equal to 2.375, and if any fall below 0, you must set it to 0. Once the program works properly, add a do-while loop that wraps around much of the code so that after calculating a QB Rating, you ask the user (yes/no) if they would like to look up another. The user should be able to repeat the process as many times as they want to. If the user looks up 3 or more QB Ratings, you should start displaying “WHY?” every time you display the rating. If a QB rating is over 120 or under 20, display “system crash” and stop the loop from iterating. (see next slide)
6
Assignment (Stannis) Prompt the user to enter their first & last name (using 1 variable, not separately). Then…. Error check: If the user forgot to enter a space, make them try again until they get it right. Display the number of characters in the name (not including the space). Display the first letter, the third letter, and the last letter (of the full name). Display the name in all caps. If the letters A and Z (uppercase) are both in the name, display “both.” Display the characters from index #4 to (and including) index #6 Display the characters from index #2 to the end of the name Display the person’s initials only. Using a do-while loop, display each character in the person’s name on separate lines.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.