Agenda Warmup Lesson 1.6 (Do-while loops, sentinels, etc)

Slides:



Advertisements
Similar presentations
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Advertisements

Constants A constant is a variable whose value is expected to remain the same throughout a program It is considered “good programming style” to use constants.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
ITI 1120 Lab #5 Contributors: S. Boyd, R. Plesa, A. Felty, D. Inkpen, A. Williams, D. Amyot.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
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.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology_ George Koutsogiannakis.
Chapter 3 Using Variables, Constants, Formatting Mrs. UlshaferSept
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.
Few More Math Operators
Variables and input/output
Java Language Basics.
Agenda Warmup Lesson 1.4 (double precision, String methods, etc)
Chapter 2 Basic Computation
Agenda Warmup Finish 2.4 Assignments
2.5 Another Java Application: Adding Integers
Agenda Warmup AP Exam Review: Litvin A2
Programming Mehdi Bukhari.
Variables, Expressions, and IO
Open AvgLoop. It should provide SOME guidance for today’s assignment, but don’t just copy-paste….THINK.
Programming Fundamentals
Lecture 07 More Repetition Richard Gesick.
Agenda Warmup Lesson 2.5 (Ascii, Method Overloading)
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Building Java Programs
Building Java Programs
Looping and Repetition
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Lesson #5 Repetition and Loops.
Manipulating Text In today’s lesson we will look at:
Introduction to Object-Oriented Programming with Java--Wu
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Building Java Programs
Java Programming Arrays
Java Programming Loops
We’re moving on to more recap from other programming languages
IPC144 Introduction to Programming Using C Week 3 – Lesson 2
Java Programming Control Structures Part 1
Do … Loop Until (condition is true)
Chapter 6: Repetition Statements
Computing Fundamentals
OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS
Chapter 3: Selection Structures: Making Decisions
Welcome to AP Computer Science A!
Welcome to AP Computer Science A!
CS2011 Introduction to Programming I Selections (I)
Java Programming Loops
Agenda Warmup Lesson 2.6 (Constructors, Encapsulation)
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Chapter 3: Selection Structures: Making Decisions
Agenda Warmup Lesson 1.4 (double precision, String methods, etc)
Other types of variables
Building Java Programs
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
Agenda Warmup Lesson 2.2 (parameters, etc)
Announcements Lab 3 was due today Assignment 2 due next Wednesday
Agenda Warmup Lesson 1.6 (Do-while loops, sentinels, etc)
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Agenda Warmup Review Finish 1.2 Assignments Lesson 1.3 (If Statements)
EECE.2160 ECE Application Programming
Agenda Warmup Lesson 2.8 (Overloading constructors, etc)
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Agenda Warmup Review Finish 1.2 Assignments Lesson 1.3 (If Statements)
Looping and Repetition
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
Agenda Warmup Lesson 2.4 (String concatenation, primitive types, etc)
Presentation transcript:

Agenda Warmup Lesson 1.6 (Do-while loops, sentinels, etc) Guided Practice (1.6 Assignments) (Time Permitting): Lesson 1.7 Closure Activity Students will be able to: know how to write a do-while loop Understand how a do-while loop differs from a while loop Know what a sentinel is Use the Math class to accomplish certain arithmetic operations See how today's lesson fits into the unit and the course as a whole

Socrative.com - EASTQUINN char x = ‘a’; char y = ‘b’; System.out.print(x + y); // result? String z = “a”; if (2 > 3 || z.charAt(1)==‘a’) // result? 45 % 63 = 4) 45 / 63 = 5) int x = 0; while (x>0); { System.out.print(x); } // result? 6) What is the name for a variable that determines how many times a loop iterates? 7) What is the name for a variable in a loop that calculates a sum or product? 8) What is the most important advantage of using Object-Oriented programming languages, such as Java? 9) True/False: the center of the Earth is liquid. 10) Is Java a low-level or high-level language? What’s the difference?

Quiz: Tomorrow

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

Local vs global variables If you declare a variable in a loop, then that variable is local to that loop – meaning that it will not be recognized outside of the loop. In order to make the variable global, or accessible throughout a program, declare it outside of the loop. Show in DoWhileDemo.

Sometimes the user determines when a loop will stop iterating. Demo: DoWhileDemo2

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

What it returns (what type the answer is) Java’s Math class Allows you to do basic math functions Not necessary to import it 3 methods (functions) you must know: Demo: MathDemo Name of method What it returns (what type the answer is) Math.abs(num) an int Math.pow(base, exponent) a double Math.sqrt(num)

To help with today’s assignments… Open Powerpoint 1.4 – review the String examples, especially the substring method. Also open the assignment Middle

Assignment: SpaceChecker Prompt the user to enter their first & last name (using 1 variable, not separately). Then…. Error check: The name should contain a space, and should be at least 5 characters long. If not, make them try again until they get it right. Display how many times an invalid name was entered. Display whether or not the name is the same as yours. Display the number of characters in the name (not including the space). Display the first, third, and last characters (of the full name). Display the name in all caps. If the letters a and z (lowercase) are both in the name, display “both.” Display the 3rd to the 5th (including the 5th) characters in the name. Display the 2nd to the last (including the last) characters in the name. Display the person’s initials only; display “whoa” if they’re the same. Using a do-while loop, display each character in the person’s name on separate lines. Display how many times the letter e appears in the name. (see next slide)

Assignment: QBRating Click here for the NFL QB Rating Formula. Write a program that asks the user to enter an NFL QB’s stats (completions, attempts, yards, TDs, and interceptions), and calculates his rating. Round off the rating to 1 decimal place. 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 that one equal to 2.375, and if any fall below 0, you must set that one to 0. Then, click here for Nick Foles’ 2018 stats, and use them to test your program, making sure that you calculate his correct QB rating (96.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.