10 ThinkOfANumber program1July 151 10 ThinkOfANumber program CE00858-1: Fundamental Programming Techniques.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Computer and Programming
Building Java Programs
04 WeightLoss program1May WeightLoss program CE : Fundamental Programming Techniques.
08 Deterministic iteration1May Deterministic iteration CE : Fundamental Programming Techniques.
12 Pontoon1May Pontoon program CE : Fundamental Programming Techniques.
03 Data types1June Data types CE : Fundamental Programming Techniques.
June Searching CE : Fundamental Programming Techniques 16 Searching1.
15 Sorting1June Sorting CE : Fundamental Programming Techniques.
Loop variations do-while and for loops. Do-while loops Slight variation of while loops Instead of testing condition, then performing loop body, the loop.
18 File handling1June File handling CE : Fundamental Programming Techniques.
09 Non-deterministic iteration1June Non-deterministic iteration CE : Fundamental Programming Techniques.
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
11 Methods1June Methods CE : Fundamental Programming Techniques.
Fundamentals of Python: From First Programs Through Data Structures
JAVA Control Structures: Repetition. Objectives Be able to use a loop to implement a repetitive algorithm Practice, Practice, Practice... Reinforce the.
Lecture 15 Practice & exploration Subfunctions: Functions within functions “Guessing Game”: A hands-on exercise in evolutionary design © 2007 Daniel Valentine.
Fundamentals of Python: First Programs
Building Java Programs Chapter 5 Program Logic and Indefinite Loops Copyright (c) Pearson All rights reserved.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
Chapter 4: Loops and Files
CS1101X: Programming Methodology Recitation 3 Control Structures.
Chapter 5 Loops.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
CS 108 Computing Fundamentals Notes for Thursday, February 19, 2015.
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.
1 while loops. 2 Definite loops definite loop: A loop that executes a known number of times.  The for loops we have seen so far are definite loops. We.
Chapter 4: Control Structures II
Chapter 5: Control Structures II
Georgia Institute of Technology More on Creating Classes part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
Recursion Pepper. Another way to loop Call yourself repeatedly until you say to stop. Example: add up 10 numbers using addUp. -- Input – number to count.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I 12/11/20151.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014 Office hours: Thursday 1300 – 1400hrs.
Random UNPREDICTABLE NUMBERS. A FEW APPLICATIONS THAT USE RANDOM…. Predictions for life expectance used in insurance Business simulations Games (Give.
Programming Fundamentals I Java Programming Spring 2009 Instructor: Xuan Tung Hoang TA: Tran Minh Trung Lab 03.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I 2/4/20161.
1 Class Chapter Objectives Use a while loop to repeat a series of statements Get data from user through an input dialog box Add error checking.
14 BirthMonth1February BirthMonth CE : Fundamental Programming Techniques.
AP Java Java’s version of Repeat until.
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.
1 BUILDING JAVA PROGRAMS CHAPTER 5 PROGRAM LOGIC AND INDEFINITE LOOPS.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
13 Arrays CE : Fundamental Programming Techniques June 161.
CSC111 Quick Revision.
Repetition (While-Loop) version]
Chapter 5: Control Structures II
Repetition-Sentinel,Flag Loop/Do_While
Repetition.
Control Statement Examples
Building Java Programs
Learning to Program in Python
Java Language Basics.
Chapter 8 The Loops By: Mr. Baha Hanene.
Coding Concepts (Basics)
IPC144 Introduction to Programming Using C Week 3 – Lesson 2
Truth tables: Ways to organize results of Boolean expressions.
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
Looping III (do … while statement)
Building Java Programs
Random Numbers while loop
Building Java Programs
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Computer Science Club 1st November 2019.
Presentation transcript:

10 ThinkOfANumber program1July ThinkOfANumber program CE : Fundamental Programming Techniques

10 ThinkOfANumber program2July 152 Objectives In this session, we will: analyse a problem that uses selection and iteration implement the solution using concepts introduced so far

10 ThinkOfANumber program3July 15 ThinkOfANumber specification generate random number and get user to guess what it is randomly generate a number in range 1 – 100 prompt user to enter a guess keep prompting for a number until the user guesses correctly output a hint based on the number guessed: higher lower at the end, output the number of guesses taken to guess correctly

10 ThinkOfANumber program4July 15 Analysis what data is used? what operations are needed? what operations are done once before the loop? how many times is loop repeated? what operations are repeated inside the loop? what operations are done once after the loop? some of these operations may need further analysis

10 ThinkOfANumber program5July 15 //think of a number and allow the user to guess it import java.util.*; public class ThinkNumber { public static void main (String args[]) { //generate number in range //prompt user to enter guess //loop until correct number is guessed //check guess and output hint //guess is correct - output count }

10 ThinkOfANumber program6July 15 Code snippets generating value in range 1 – 100: int number = (int)(Math.random() * 100) + 1; looping until correct value input while (guess != number)

10 ThinkOfANumber program7July 15 Testing need to modify code to be able to test add an output statement so that we know what number has been randomly generated must guess correct number first so that loop is not entered must guess higher than number so that "lower" is output must guess lower than number so that "higher" is output

10 ThinkOfANumber program8July 158 Summary In this session we have: analysing a problem to determine what is required implementing a solution that: generates random numbers uses a while loop to handle a non-deterministic situation has a choice within the loop performs initial operations before the loop outputs results after the loop In the next session we will: introduce methods to perform blocks of code