Week 61 Introduction to Programming Ms. Knudtzon C Period Tuesday October 12.

Slides:



Advertisements
Similar presentations
Any questions on the Section 5. 8 homework
Advertisements

Basic Control Structures Control order of execution of statements sequential selection iteration - Repeat some action while a certain condition is true.
Hand Crafting your own program By Eric Davis for CS103.
2420 Review Questions Chapter 6.
Classes, methods, and conditional statements We’re past the basics. These are the roots.
1 Interactive Applications (CLI) and Math Interactive Applications Command Line Interfaces The Math Class Example: Solving Quadratic Equations Example:
Lecture 7. Review Homework 1 (sample solution) Project 1 will be assigned next week –Draw a picture (whatever you want) in the world by using turtles.
Lesson 1-6 Solving Quadratic Equations. Objective:
Please CLOSE YOUR LAPTOPS, and turn off and put away your cell phones, and get out your note-taking materials. Today’s daily quiz will be given at the.
Coming up in Math 110: Today: Section 8.2 (Quadratic formula)
Solving Quadratic Equations Section 1.3
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
CPSC 171 Introduction to Computer Science 3 Levels of Understanding Algorithms More Algorithm Discovery and Design.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Invitation to Computer Science, Java Version, Second Edition.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 19 : Recursion King Fahd University of Petroleum & Minerals College of Computer.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Making Decisions uCode: October Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.
Week91 APCS-AB: Java Problem Solving November 1, 2005.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
Chapter 5: Control Structures II
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Conditional Statements.  Quiz  Hand in your jQuery exercises from last lecture  They don't have to be 100% perfect to get full credit  They do have.
Java iteration statements ● Iteration statements are statements which appear in the source code only once, but it execute many times. ● Such kind of statements.
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
Quadratic Relations Solving Quadratic Equations Day 3: Solve by Factoring Tuesday, January 05, 20161Day 2 - Solve by Factoring.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
1 10/3/05CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Chapter 7 Problem Solving with Loops
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
Introduction to Computers and Programming Lecture 7:
COMP Loop Statements Yi Hong May 21, 2015.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Introduction to Flowcharts
Week91 APCS-A: Java Problem Solving November 2, 2005.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
Loops ( while and for ) CSE 1310 – Introduction to Computers and Programming Alexandra Stefan 1.
Program design Program Design Process has 2 phases:
ALGORITHMS AND FLOWCHARTS
REPETITION CONTROL STRUCTURE
ALGORITHMS AND FLOWCHARTS
C++ Basic Syntax – Homework Exercises
Repetition-Counter control Loop
Chapter 4 – Control Structures Part 1
Repetition Chapter 6 12/06/16 & 12/07/16 1 1
Introduction to Programming
Worksheet Key 9 11/14/2018 8:58 PM Quadratic Formula.
TOPIC 4: REPETITION CONTROL STRUCTURE
Solving Quadratic Equations by Completing the Square
Introduction to Programming
Solving Quadratic Equations by Completing the Square
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

Week 61 Introduction to Programming Ms. Knudtzon C Period Tuesday October 12

Week 62 Wrapping up Lab Homework –Task 5: Guessing Game should be done Did you get Task 3: Fibonacci numbers? –Series: 0,1,1,2,3,5,8,13,21,34,55,89 –F(n) = F(n-1) + F (n-2); F(0) = 0; F(1) = 1; –How did you go about solving this?

Week 63 Mini-Quiz Ready, Set, Code

Week 64 Homeworks Due Thursday October 14 in class (sheet says 7 th ) – 4 problems – choose 3 of them to solve – Extra Credit: Program a rock-paper-scissors game (Hint: you can use chooseRandom from the last assignment to get 0, 1,2 and assign each to rock, paper, scissors, respectively) Gradebook homework problem – coming back to visit it this week

Week 65 Introduction to Programming Ms. Knudtzon C Period Thursday October 14

Week 66 Control Structures Know when and how to use conditionals –Nested if/else blocks –Using logical operators && || ! Know when and how to use for loops Know when and how to use increment and decrement operators Know when and how to use while loops

Week 67 Administrative Details Homework 6 – –hand it in for a grade ( it to me) Lab –Show me it’s all working Extra Credit –Hand it in ( or turn it in)

Week 68 Problem Solving – 4 phases Understanding the problem Devising a plan Carrying out the plan Looking back (testing solution) –From “How to Solve It” –By G. Polya

Week 69 Understanding the problem Read it – do you understand what it is asking? Think about what it is asking you to do –What are the inputs to the problem? –What are the outputs of your solution? –Are there any conditions? Draw a figure, show a sample of the problem.

Week 610 Devising a plan Have you seen a similar problem before? –Or have you seen something like this problem in a different form? Can you restate the problem? Can you think of a more general problem? A more special problem? Can you solve part of the problem? Draw out what you think might work Think about and name the variables you might need Think about what kind of conditional structures might be suited to the problem Pseudocode your plan

Week 611 Carrying out the plan Program your plan, checking each step. Is that line of code correct? Is it doing what you want/expect it to?

Week 612 Looking back (testing solution) Examine your solution Make sure that you get the expected output Step through your program and trace its state at each step –GRID method (for problems with looping)

Week 613 Method Level Problem Solving Understanding the problem –What exactly does this method need to do? –What are the inputs to the problem? –What are the outputs of your solution? –Are there any conditions? What must be true before this method starts (pre- conditions) What will be true when this method finished (post- conditions)

Week 614 Method Level Problem Solving Devising a plan –Is there a related method we could modify? –PSEUDOCODE Identify and name variables, Think about the conditional structures you need lay out the steps the method needs to do Carrying out the plan –Turn the pseudocode into Java code Looking Back (testing solution –Step through your program. Do the pre-conditions hold? Do the post-conditions?

Week 615 Calculating Powers. Given a base “b” (a double) and a power “p” calculate b to the p power How do we do this?

Week 616 Understanding the problem Do you understand what you are supposed to do? –b^p –Samples: 3^4 = 3 * 3 * 3 * 3 5^5 = 5 * 5 * 5 * 5 * 5 –So b^p means that we multiply b times itself p times What are your inputs? What is the output? Are there any conditions?

Week 617 Devising a plan Have we seen something similar? –Maybe the factorial problem… Can you restate the problem? Draw out what might work –What are the variables? –Need a loop – because we are repeating an action a number of times So what does the loop do? What kind of loop would be best for this problem? –What do we need to make the loop work? Need to hold the answer in a new variable Need a counter variable –have to count how many times we multiply b by itself (so that we can stop after we multiply it by itself p times) Start to pseudocode a solution

Week 618 Carrying out the plan Program your plan, checking each step public double power(double b, int p){ double answer = 1; for(int x = 1; x <= p; x++){ answer *= b; } return answer; } Why do we set answer = 1? What if we thought answer should equal b?

Week 619 Looking back (testing solution) Let’s test our solution with trying 5^4 bpxanswer start541 begin loop15 check x <= p ??215 check x <= p ??375 check x <= p ??4375 check x <= p ??DONE

Week 620 Quadratic Let's suppose we want to write a program to solve quadratic (i.e. second-order) equations. As you know, given a quadratic equation of the form: ax^2 + bx + c = 0 The quadratic formula gives the two roots (b +/- √(b^2 – 4ac))/2a Now, how do we write the program?

Week 621 Understanding the problem Do we know what we are being asked to do? What are the inputs? What are the outputs? Are there any conditions?

Week 622 Devising a plan: A Simple Plan Get the coefficients of the equation (could be passed in as parameters or could prompt a user for them) Solve the quadratic formula given those coefficients Print or return the roots

Week 623 Devising a plan: A More Detailed Plan We will assume we will prompt the user for input 1.Get the coefficients of the equation from the user (Need InputReader) –Prompt for the three coefficients: a, b, and c –Input the three coefficients: a, b, and c 2.Solve the quadratic formula given those coefficients (Need Java Math package) –compute the common subexpression √(b^2 – 4ac) and call it root –compute the first root: (-b + root)/2a –compute the second root: (-b - root)/2a 3.Print the roots for the user

Week 624 Carrying out the plan public void quadratic(){ double a, b, c; // The three coefficients double root, // The Common subexpression double x1, x2; // The 2 results // Get the coefficients from the user System.out.println(("Enter the three coefficients" + " of a quadratic equation:"); a = reader.getDoubleInput(); b = reader.getDoubleInput(); c = reader.getDoubleInput(); // Solve the quadratic formula given those coefficients // Compute the common sub expression root = Math.sqrt(b * b - 4 * a * c); // Computer the two roots x1 = (-b + root)/(2*a); x2 = (-b - root)/(2*a); // Print the roots for the user System.out.println("The roots of the equation are " + x1 + " and " + x2); }

Week 625 Looking back (testing solution) Is our program correct? Specifically we need to check the general correctness as well as the boundary cases. –What are boundary cases? No looping (so no need to do the grid check)

Week 626 Method Level Problem Solving Understanding the problem Devising a plan Carrying out the plan Looking back (testing solution) How could this help us on the lab problems? Let’s look at solving Fibonacci?

Week 627 Homework Method Level Problem Solving: Ask the user for an integer and tell them all the factors of the number (i.e. the numbers between 1 and the number that the number is divisible by). Do it on paper – lay out the four steps

Week 628 Administrative Details Turn in homework 7 Homework 6 (due 8 pm) Fibonacci Method Level Problem Solving –Understanding the problem –Devising a plan –Carrying out the plan –Looking back (testing solution) –Note: Special cases for 0 and 1 Calculating Fib for 2 and above

Week 629 Fibonacci 1. Understand the problem (on whiteboard) 2. Devise a plan (on whiteboard) 3. Carry out the plan (handout) 4. Looking Back – Grid (on whiteboard)