80 likes | 231 Views
Lecture 9: The Programming Process. Yoni Fridman 7/11/01. Outline. Designing a program Step 1: Understanding the problem Let’s try this step for a realistic poker game Step 2: Building the foundation Let’s try this step Step 3: Filling in the details Let’s try this step
E N D
Lecture 9: The Programming Process Yoni Fridman 7/11/01
Outline • Designing a program • Step 1: Understanding the problem • Let’s try this step for a realistic poker game • Step 2: Building the foundation • Let’s try this step • Step 3: Filling in the details • Let’s try this step • Step 4: Writing code
Designing a Program • So far, we’ve worked with short, simple programs. • For such programs it’s fine to sit in front of the computer and start typing code. • More significant programs can’t be done like this – they must be carefully designed first.
1: Understanding the Problem • First, we must understand the problem – what exactly is our program supposed to accomplish? • For example, assume we are told to write a program that plays a realistic game of poker. • What are the specifications for our program? • How many players should there be? • What style of poker should it play? • What are all the rules that our program should follow? • Let’s write a set of specifications for a poker game.
2: Building the Foundation • Once we have clear specifications, the next step is to “outline” our program. • For example, the outline for our simple Black Jack game of HW3 might look as follows: • Initialize hands • Initialize player’s hand • Initialize dealer’s hand • Do player’s turn … • Do dealer’s turn … • Figure out who won … • Let’s outline our poker game.
3: Filling in the Details • After our program outline is written, we can fill in the details. • We do this by writing pseudocode. Pseudocode is text that’s formatted like a program, but written in English. • Example: Initialize player’s total to zero. Initialize dealer’s total to zero. While player keeps hitting … Deal the player a new card. Add the new card’s value to the player’s total. … • Let’s write our poker game in pseudocode.
4: Writing Code • If your pseudocode is good enough, you can almost translate each line of pseudocode into a Java statement. • This will be your next programming assignment. • Note: Make sure you follow the style sheet’s guidelines on future homeworks.
Homework • HW4: Review questions, due tomorrow. Write up at least three questions to turn in on anything through Lecture 6: For Loops.