QUIZ: FRIDAY! Waffle Wednesday: Tuesday
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
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
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
Open Powerpoint 1.5 – review the String examples, especially the substring method. Also open the assignment Middle
Assignments 1)(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. (see next slide)
2) (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).here Peyton Manning’s 2014 stats ***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 so that after calculating a QB Rating, you ask the user 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.