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.