Presentation is loading. Please wait.

Presentation is loading. Please wait.

12 Pontoon1May 15 12 Pontoon program CE00858-1: Fundamental Programming Techniques.

Similar presentations


Presentation on theme: "12 Pontoon1May 15 12 Pontoon program CE00858-1: Fundamental Programming Techniques."— Presentation transcript:

1 12 Pontoon1May 15 12 Pontoon program CE00858-1: Fundamental Programming Techniques

2 12 Pontoon2May 15 Objectives In this session, we will: analyse a problem that uses methods implement the solution using concepts introduced so far

3 12 Pontoon Pontoon specification a simple game based upon the card game Pontoon player will play the game against the computer cards are allocated numeric values Ace = 11, Jack = 10, Queen = 10, King = 10 although in Pontoon, Ace can be either 11 or 1, we will only use 11 Cards 2 -10 have their face value player and computer are dealt two cards in turn initially then can take additional cards player takes all additional cards before computer computer must take additional cards if score less than 15 score over 21 "busts" winner has highest score that is 21 or under computer's score beats player's if equal May 153

4 12 Pontoon Analysis – break down relatively large problem break down into smaller chunks analyse, implement and test each chunk: deal initial hands deal additional cards to player check if player bust deal additional cards to computer check if computer bust check for winner also need to consider how to represent cards May 154

5 12 Pontoon //play a game of pontoon import java.util.*; public class Pontoon { public static void main (String args[]) { //deal initial hands //deal additional cards to player //deal additional cards to computer //check if anyone bust //check for winner if no-one bust } May 155

6 Representing cards each card has a rank and an integer score not concerned with suit of card value is randomly generated need to: output rank based on value determine score based on value 12 Pontoon6May 15 ValueRankScore 1Ace11 2 – 10 face value 11Jack10 12Queen10 13King10

7 12 Pontoon Testing: Deal initial hands add output statements to display scores after each card dealt run program and ensure: 2 random card values generated for player 2 random card values generated for computer rank displayed correctly scores calculated correctly May 157

8 12 Pontoon Testing: Deal additional cards to player run program and ensure: user asked whether they want new card after initial hand dealt loop entered when user first types 'y' loop continued when user next types 'y' loop terminated when user types anything else May 158

9 12 Pontoon Testing: Deal additional cards to computer add statement to set computerScore to 0 before loop run and ensure loop is entered at least twice change statement to set computerScore to 14 run and ensure loop is entered when score is 14 (boundary case) change statement to set computerScore to 15 run and ensure loop is not entered when score is 15 (boundary case) remove added statement May 159

10 12 Pontoon Testing: Check if anyone bust add statement to set player’s score to 21 before checking to see if anyone bust run program and ensure player doesn’t bust change statement to set player’s score to 22 run program and ensure that player busts remove statement add statement to set computer's score to 21 before checking to see if anyone bust run program and ensure computer doesn’t bust change statement to set computer's score to 22 run program and ensure that computer busts remove statement May 1510

11 12 Pontoon Testing: Check win add statements after checking if anyone bust to set player’s score and computer’s score so that player's score is higher than computer's run program and ensure that player wins change statements so computer's score and player's score are equal run program and ensure that computer wins change statements so computer's score is higher than player's score run program and ensure that computer wins remove added statements May 1511

12 12 Pontoon12May 15 Summary In this session we have: analysing a fairly large problem to determine what is required implementing a solution that: generates random numbers uses while loops uses if statements uses methods to implement parts of the solution In the next session we will: use arrays to store data


Download ppt "12 Pontoon1May 15 12 Pontoon program CE00858-1: Fundamental Programming Techniques."

Similar presentations


Ads by Google