Truth and while Today 15 Minutes online time to finish the random/Swing programs. Truth tables: Ways to organize results of Boolean expressions. Note Taking:

Slides:



Advertisements
Similar presentations
Copyright 2010 by Pearson Education Building Java Programs Chapter 4 Lecture 4-2: Advanced if/else ; Cumulative sum reading: 4.1, 4.3, 4.5; "Procedural.
Advertisements

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
If statements Chapter 3. Selection Want to be able to do a statement sometimes, but not others if it is raining, wear a raincoat. Start first with how.
LAB 10.
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
Chapter 4: Control Structures II
Computer Programming Lab(4).
JAVA Control Structures: Repetition. Objectives Be able to use a loop to implement a repetitive algorithm Practice, Practice, Practice... Reinforce the.
Chapter 6: Iteration Part 2. Create triangle pattern [] [][] [][][] [][][][] Loop through rows for (int i = 1; i
Java Programming: From the Ground Up
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
Input & Output In Java. Input & Output It is very complicated for a computer to show how information is processed. Although a computer is very good at.
Chapter 5 Loops.
1 Fencepost loops “How do you build a fence?”. 2 The fencepost problem Problem: Write a class named PrintNumbers that reads in an integer called max and.
October 28, 2015ICS102: For Loop1 The for-loop and Nested loops.
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
Chapter 4: Control Structures II
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
FUNDAMENTALS 2 CHAPTER 2. OPERATORS  Operators are special symbols used for:  mathematical functions  assignment statements  logical comparisons 
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
Java Review if Online Time For loop Quiz on Thursday.
CONTROL STRUCTURE Chapter 3. CONTROL STRUCTURES ONE-WAY SELECTION Syntax: if (expression) statement Expression referred to as decision maker. Statement.
 CSC111 Quick Revision. Problem Write a java code that read a string, then show a list of options to the user to select from them, where:  L to print.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
int [] scores = new int [10];
CSCI S-1 Section 8. Coming Soon Problem Set Four (72 + 5/15 points) – Tuesday, July 21, 17:00 EST.
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
AP Java Java’s version of Repeat until.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
1 BUILDING JAVA PROGRAMS CHAPTER 5 PROGRAM LOGIC AND INDEFINITE LOOPS.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING For Loop.
AP Java 10/1/2015. public class Rolling { public static void main( String [] args) public static void main( String [] args) { int roll; int roll; for.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Chapter 7 Iteration. Chapter Goals To be able to program loops with the while, for, and do statements To avoid infinite loops and off-by-one errors To.
CSC111 Quick Revision.
AP Java 10/4/2016.
Chapter 6 More Conditionals and Loops
Chapter 5: Control Structures II
Repetition-Counter control Loop
Repetition-Sentinel,Flag Loop/Do_While
TK1114 Computer Programming
Something about Java Introduction to Problem Solving and Programming 1.
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
Java Methods Making Subprograms.
While Statement.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Java Fix a program that has if Online time for Monday’s Program
The for-loop and Nested loops
int [] scores = new int [10];
Truth tables: Ways to organize results of Boolean expressions.
Control Statements Loops.
AP Java 10/4/2016.
Dry run Fix Random Numbers
Truth tables: Ways to organize results of Boolean expressions.
Java Fix a program that has if Online time for Monday’s Program
Introduction to Java Brief history of Java Sample Java Program
Truth tables: Ways to organize results of Boolean expressions.
Computer Science 1 while
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Control Statements Loops.
Building Java Programs
Computer Science I: Get out your notes.
Random Numbers while loop
Computer Science 1 while
CSS161: Fundamentals of Computing
Computer Science Club 1st November 2019.
Presentation transcript:

truth and while Today 15 Minutes online time to finish the random/Swing programs. Truth tables: Ways to organize results of Boolean expressions. Note Taking: DeMorgan’s law using online text While Code

Programs from Tuesday Tree height calculator: –Input the distance you are from a tree and the angle you look up to the top of the tree. –Output: The height of the tree. –Calculation: tree height = the height of your eyes + (Distance from the tree) * tan(angle) –Look up the Math.tan() method to determine if the angle is in degrees or radians. –Push: Research to find out how to use this information to estimate the number of ‘board-foot’ volume of the standing tree. Random Program optionsRandom Program options Flip a coin 100 times, show the total number of heads and tails AND which occurred the most often.Flip a coin 100 times, show the total number of heads and tails AND which occurred the most often. Roll a pair of 6 sided dice 100 times. Find out which occurs most often, 3 or 11. Show how often each of these rolls occur and which occurs most often.Roll a pair of 6 sided dice 100 times. Find out which occurs most often, 3 or 11. Show how often each of these rolls occur and which occurs most often.

Learning Objectives Be able to use a truth table to evaluate boolean expressions. Be able to use the while loop in Java.

Truth Tables: A truth table is another way to show the evaluation of a boolean expression. ABA && B TT TF FT FF ABA || B TT TF FT FF Complete these tables in your notes.

More Truth: ! (A && B), (!A) || (!B) AB(A&&B)!(A&&B) TT TF FT FF AB!A!B(!A)||(!B) TT TF FT FF "It is not the case that Tom is rich and famous." is true if and only if "Tom is not rich or he is not famous." DeMorgan’s Law Complete these tables in your notes.

Truth Tables –A truth table is another way to show the evaluation of a boolean expression. DeMorgan –!(A && B) = (!A) || (!B) –"It is not the case that Tom is rich and famous." is true if and only if "Tom is not rich or he is not famous." –!( A || B ) = (!A) && (!B) –"It is not the case that Tom is rich or famous." is true if and only if "Tom is not rich and he is not famous." Introduction to Computer Science using Java Add your answers to the online text to your notes.

More on Truth Tables Read through Chapter 40B and record your answers in your notes, then complete the review Example of notes: 1)False 2)…

while Learning Objectives Be able to write a program that uses the while loop.

While loop When to use it When to use it Repeating something an unknown number of times, but might not occur Repeating something an unknown number of times, but might not occur It’s a sentinel-controlled loop. It’s a sentinel-controlled loop. Semantics Semantics Get Variable Get Variable while (variable !=flag) while (variable !=flag) Squiggly line Squiggly line Get Variable Get Variable end end Syntax Syntax while (condition) while (condition) { Commands repeated Commands repeated } SEMANTICS OF A WHILE LOOP! Put it in your notes.

Example // Example of a while loop class LoopExample { public static void main (String[] args ) { int count = 1; // start count out at one while ( count <= 3 ) // loop while count is <= 3 { System.out.println( "count is:" + count ); count = count + 1; // add one to count } System.out.println( "Done with the loop" ); }} Read the program to see how the syntax of the while looks.

Example getting input from the User import java.util.Scanner; public class LoopTotal { public static void main(String [] args) public static void main(String [] args) { int total = 0, score, count = 0; int total = 0, score, count = 0; Scanner input = new Scanner(System.in); Scanner input = new Scanner(System.in); System.out.println("Enter a score, -1 to quit"); System.out.println("Enter a score, -1 to quit"); score = input.nextInt(); score = input.nextInt(); while (score != -1) while (score != -1) { total += score; total += score; count++; count++; System.out.println("Enter a score, -1 to quit"); System.out.println("Enter a score, -1 to quit"); score = input.nextInt(); score = input.nextInt(); } System.out.println("The total score = " + total); System.out.println("The total score = " + total); }}

Program Options 1.Input: An unknown number of integers. –Output: The total, average, high and low values. 2.Input: None –Process: Roll a pair of six-sided dice and count how many rolls it takes for you to roll three sevens in a row. –Output: Each roll and the count for the number of rolls it takes to roll three sevens in a row. 3.Input: An unknown number of integers representing light sensor readings. –Output: A running average of the three most recent readings. –Determine how you will handle the first two readings and include your approach in your header notes. –Push: Modify the program so the user can enter how many readings to consider when calculating the average. Use swing to create a windows application for one of the options.