Making Decisions uCode: October 2014. Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.

Slides:



Advertisements
Similar presentations
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
Advertisements

Summer 2012 Instructor: Hassan Khosravi
CS 206 Introduction to Computer Science II 02 / 27 / 2009 Instructor: Michael Eckmann.
101.  Computers DO NOT think for themselves. For them to do anything they need to be told what to do.  Simply put computer programming is when you tell.
Copy in Agenda and TOC Turn in your homework equation sheet.
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
Two examples of Problem Solving in Programming H. Chad Lane University of Pittsburgh CS7: Introduction to Programming.
Basic Programming II. Outline Standard Deviation Function (SD) Complex Guessing Game.
CSC1016 Coursework Clarification Derek Mortimer March 2010.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
COMP 14: switch, Developing Programs June 2, 2000 Nick Vallidis.
Python (yay!) November 16, Unit 7. Recap We can store values in variables using an assignment statement >>>x = We can get input from the user using.
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
School of Computing Science CMT1000 Ed Currie © Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 5B: Branch Statements - Making.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Complexity (Running Time)
Main task -write me a program
CS 206 Introduction to Computer Science II 10 / 08 / 2008 Instructor: Michael Eckmann.
CIS101 Introduction to Computing Week 12 Spring 2004.
Ch 1.4 – Equations & Inequalities
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
The Book Sock Riley A. 9PA.  Describe the problem you want to solve. The real world-problem may be one that all the people in your neighborhood face,
Lecture 15 Practice & exploration Subfunctions: Functions within functions “Guessing Game”: A hands-on exercise in evolutionary design © 2007 Daniel Valentine.
From Scratch to Python Learn to program like the big boys / girls!
An Introduction to Textual Programming
CS161 Topic #15 1 Today in CS161 Lecture #15 Practicing! Writing Programs to Practice Write a game program (1 player) of Mad Math Reuse the functions to.
X = 11 X 2 = 9 X = 3 Check: X = 3 x 3 +2 = 11 We can solve this equation by:
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
Program Design CMSC 201. Motivation We’ve talked a lot about certain ‘good habits’ we’d like you guys to get in while writing code. There are two main.
Invitation to Computer Science, Java Version, Second Edition.
©Robomatter – Distribution or copying without permission is prohibited. 3B STEM Computer Science 1 ©Robomatter – Distribution or copying without permission.
 Make sure you are subscribed to announcements on Moodle.  Activity 4 will be due 48hrs after your lab ends.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
By the end of this session you should be able to...
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.
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
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.
Problem Solving Engineering Technology Mr. Austin.
Discussion 4. Labs public MyPoint(double xInit, double yInit ) { MyPoint p = new MyPoint(0, 0); } ClassProblem.java recursive java.lang.StackOverflowError.
Word problems DON’T PANIC! Some students believe they can’t do word problem solving in math. Don’t panic. It helps to read the question more than once.
Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon.
Writing & Graphing Inequalities Learning Objective: To write and graph inequalities on the number line because I want to be able to represent situations.
Writing & Graphing Inequalities Learning Target: Today I am learning how to write and graph inequalities on the number line because I want to be able.
1 CS161 Introduction to Computer Science Topic #9.
How to Help in Early Years Maths. By the end of Reception these are the expectations. Children count reliably with numbers from 1 to 20, place them in.
MODULE 3 LESSON 15. OBJECTIVE Explore a situation with more than 9 groups of ten.
Decision Structures and Boolean Variables. Sequence Structures Thus far, we’ve been programming “sequence structures” Thus far, we’ve been programming.
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.
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Week 61 Introduction to Programming Ms. Knudtzon C Period Tuesday October 12.
Do Now Draw a picture to represent these fractions: Homework: –Write a paragraph about the difference between an improper fraction and a proper fraction.
LECTURE 20: RECURSION CSC 212 – Data Structures. Humorous Asides.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Fall 2001(c)opyright Brent M. Dingle 2001 Simple Sorting Brent M. Dingle Texas A&M University Chapter 10 – Section 1 (and some from Mastering Turbo Pascal.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Week91 APCS-A: Java Problem Solving November 2, 2005.
Conditionals.
CONDITIONALS CITS1001. Scope of this lecture if statements switch statements Source ppts: Objects First with Java - A Practical Introduction using BlueJ,
Grade Three: Fractions Unit 7 Finding Fair Shares.
Writing & Graphing Inequalities Learning Target: Today I am learning how to write and graph inequalities on the number line because I want to be able.
Control Structures: Conditionals, If/Else and Loops David Millard
CS1371 Introduction to Computing for Engineers
Algorithm Discovery and Design
Presentation transcript:

Making Decisions uCode: October 2014

Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real world. o Methods o Parameter o Variables o Classes

Overview Today we will talk about: Part I 1.Reading code/comments 2.Designing a program Part 2 1.Making decisions in code

Reading Code What do you do when you want to know how to build a rocket? o Look it up on Google o Ask Mom, Dad, or Rocket Scientist o Go to the library and check out a book on building rockets o Take apart a rocket similar to the one you want to build The point is : If you do not know how to do something, you ask for help. o Reading the code from someone else can help you find your solution. o Good code will have comments – read them

Designing a Program It is much easier to go somewhere when you know where you are going. o Understand your problem o Design a solution o Implement and test your solution o Re-evaluate your solution “Designing a solution is messy and does not follow a straight road.”

Understand Your Problem Figure out what it is that you want to do o Ask lots of questions! o Write things down o Draw pictures

Understand the Problem Problem : We are going to build a number guessing game program. Player 1 will select a secret random value between 0 and some number and write it down so that player 2 cannot see it. Player 2 will make guesses one number at a time. Player 1 can only say too high, too low or correct. To Do : Play the game several times with your partner. Switch places every so often.

Design a Solution This is point at which you start putting your program together on paper. o A problem can break down into smaller problems (guess what; smaller problems are easier to solve!!!). o Look for similar solutions to parts of your problem. To Do : Make an ordered list of steps describing how to play the game from start to finish.

Implement & Test Your Code Once you have an idea where you are going to go, you may open BlueJ and start working. o Write code for a small problem then test it to make sure it works. Vocabulary Implement – write the code to solve your solution. Test – run your program to see if the code works as you expect.

Guessing Game Plan To play one round of the Guessing Game 1.Get a maximum range value from the player. 2.Get the random number. 3.Tell the user a number between 0 and the maximum range value the player inputted. 4.Play the game until the player guesses the secret number. 1.Get the player’s guess. 2.Evaluate the guess and tell the player whether their guess is too big, too small, or just right. 5.Exit the program.

Consider Alternatives Quite simply, given the step you just wrote into code, does your code work the way you expect??? o Yes? Great move on to the next step. o No? Well take a look at what you have done and do something different. To Do : 1.Select a random number and store it. 2.Print out the number to guess to test it. You will need to remove this later.

Solution to first task public void playGame() { // Assume player will play at least one game. // Initialize value to y for yes. play = 'y'; while(play == 'y'){ // If the user wants to play // Get the random number to guess and assign it to // the variable that will hold the secret number. secretNumber = getRandomNumber(maxNumToGuess); // … code has been removed … }

Summary Part I Up to now we have discussed getting help and the process for solving a problem. Reading someone else’s code that solves a similar problem can help you a lot. Following a step by step process can help you to face a problem with confidence and knowledge that you can solve it. Understand ing a problem will give you the ability to break it into steps. Each step is a smaller problem that will lead you to a solution to the original problem. Design ing a solution to a small problem is easier than finding a solution to a larger one. Implement and test your code according to the steps in your list. Evaluate your program to make sure it works as you expect.

Part II: Making Decisions What do you do when you want to buy the latest iPhone 6? A.Ask mom or dad if they can buy it? B.Check to see if you have enough money in your wallet to buy it. They key is asking a question to which the answer is either “yes” or “no”. So your question might look something like this: If “money in my wallet” greater or equal to $600 then Buy the iPhone 6.

Part II: Making Decisions So your code might look something like this: Pseudo-Code : If “money in my wallet” greater or equal to $600 then Buy the iPhone 6. Code : Line 1: int cashOnHand = 650; Line 2: if( cashOnHand >= 600 ){ Line 3: buy(“iPhone 6”); Line 4: }

Asking the Question Questions have to be asked so that you get a yes/no answer. Relational Operators You can ask a yes/no question by comparing values:, ≠, =  you know these from math. The good news you can use them when programming. MathJava Equivalent << >> ≤<= ≥>= === ≠!=

Exercise 10 > 5 yes girl == Girl no y != n yes 40 <= 41 yes 3 < 3 no 800 != 800 no 55 >= 55 yes int grade = 85; grade > 90 no 33,333 == 33,333 yes Answer yes/no to answer the given questions?