Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Examples.

Slides:



Advertisements
Similar presentations
Minibridge Cowbridge Comprehensive July 2007 Patrick Jourdain.
Advertisements

1 CSC 222: Computer Programming II Spring 2004 HW1 review arrays vs. vectors class design object-oriented design data objects + functionality example:
Topics in Python Blackjack & TKinter
Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Example - The.
© Glenn Rowe AC Lab 2 A simple card game (twenty- one)
It’s All in the Cards Adding and Subtracting Integers
Java Coding OOP David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Towards Event-driven programming &
Everyday Algorithms David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction to.
Jyotishka Datta STAT 598Z – Sorting. Insertion Sort If the first few objects are already sorted, an unsorted object can be inserted in the sorted set.
Introduction to UML David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. …Unified Modeling Language.
Rules for Classroom Play. Setup 1. Remove blue ACTION cards from the Observatory deck 2. Shuffle both decks well and set Volcano deck to one side 3. Deal.
Activity 1: Where am I? Play in pairs Each player has a number line or bead string and a pack of number cards Each player takes turns to turn over a number.
12 Pontoon1May Pontoon program CE : Fundamental Programming Techniques.
CSC 301H, Introduction to Software Engineering Fall 2009 TA Golnaz Elahi
Java Coding 6 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Collections.
Java Coding 2 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Decisions, decisions…!
Zero to Java in Internet Time David Davenport Computer Engineering Dept., Bilkent University, Ankara Turkey
Java Coding 3 David Davenport Computer Eng. Dept.,
Review: OOP & Arrays David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. …from CS101.
Robo David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction to the engineering.
Chapter 5 Black Jack. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 5-2 Chapter Objectives Provide a case study example from problem statement.
Lecture 5 of Computer Science II Arrays Instructor: Mr.Ahmed Al Astal.
Java Coding David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey.
o Simulate a deck of playing cards o Shuffle the deck o Deal (5) cards into the hand o Turn over the first card o The user must guess whether the next.
VOCABULARY  Deck or pack  Suit  Hearts  Clubs  Diamonds  Spades  Dealer  Shuffle  Pick up  Rank  Draw  Set  Joker  Jack 
Java Coding 4 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Method madness.
Java Coding 5 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. To object or not…
Java Coding 3 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Over & over again!
Java Coding 5 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. To object or not…
Sequencing 1 Shuffle the cards and place in a pile with the numbers facing down. Order the cards from 0 to 11. How fast can you do this?
Catch the Spirit of Mathematical Practices Mathematics Investigations Q-Cards: Rational Numbers The Q-Card game has 8 starter cards, 28 playing cards,
Task Oriented Programming in using Rinus Plasmeijer – Bas Lijnse - Peter Achten Pieter Koopman - Steffen Michels - Jurriën Stutterheim Jan Martin Jansen.
Computational Algorithms David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction.
Sequencing Shuffle the cards and place in a pile with the numbers facing down. Order the cards from 0 to 11. How fast can you do this?
World Religions Tabulate Game. wild cards wild cards ordinary cards.
Java Coding 6 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Collections.
Can you calculate these?. Last lesson you were working with algebraic equivalent fractions Today you will be combining algebraic fractions using all four.
Sequencing 1 Shuffle the cards and place in a pile with the numbers facing down. Order the cards from 0 to 11. How fast can you do this?

Java Coding OOP_3 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Some important Java interfaces +
MA471 Fall 2003 Lecture 2. On With The Games Today we are going to watch each group play a couple of rounds of cards. We will go through the game slowly.
Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Examples.
Java Coding 5 – Part 2 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. To object or not…
Rules for Mini Bridge Lesson 5 Place board correct orientation (NSEW) Count cards (face down) Sort hand Count points Dealer to announce point count Clockwise.
Card Game Z  Agree on a dealer and a score keeper  The dealer should remove all the Jacks, Queens, Kings & Jokers from the pack and then shuffle  The.
© 2004 Pearson Addison-Wesley. All rights reserved6-1 Program Development In your CS102 project, and in many others, the basic activities are:  requirements.
Click to edit Master text styles Stacks Data Structure.
Section 5.5 Application: The Card Game of War. 5.5 Application: The Card Game of War A deck of cards is shuffled and dealt to two players The players.
Java Coding – part 2 David Davenport Computer Eng. Dept.,
A game of precision, quick reaction and observation.
Chapter 5 Black Jack.
Java Coding 3 – part2 David Davenport Computer Eng. Dept.,
@NAMEOFEVENTORBRIDGECLUB
Java Coding 8 David Davenport Computer Eng. Dept.,
Dot Cards Face-Off Game
Let’s Practice Play 2 Missing Digits !
Java Coding 6-extra David Davenport Computer Eng. Dept.,
Engaging children in exciting and engaging mental maths homework.
Go fish for formulas! Chemistry makes much more sense if you know the formulas of substances you will meet in your lessons. In this game you will practice.
1st/2nd Grade Math Games Family Math Night.
3rd/4th grade Family Math Night Games
Java Coding 6 – part2 David Davenport Computer Eng. Dept.,
Task 2 Implementation help
Java Coding 8 David Davenport Computer Eng. Dept.,
Vocab-Rummy A card game with: Could be used for:
Java Coding 4 (part2) David Davenport Computer Eng. Dept.,
Java Coding 6_part3 David Davenport Computer Eng. Dept.,
Java Coding 6 David Davenport Computer Eng. Dept.,
Java Coding 6 David Davenport Computer Eng. Dept.,
Java Coding 5 – Part 2 David Davenport Computer Eng. Dept.,
Presentation transcript:

Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Examples

IMPORTANT… Students… This presentation is designed to be used in class as part of a guided discovery sequence. It is not self- explanatory! Please use it only for revision purposes after having taken the class. Simply flicking through the slides will teach you nothing. You must be actively thinking, doing and questioning to learn! Instructors… You are free to use this presentation in your classes and to make any modifications to it that you wish. All I ask is an saying where and when it is/was used. I would also appreciate any suggestions you may have for improving it. thank you, David. David

Card Games As an example of Object Oriented Design

The Problem… Design & implement a program to play a simple game of cards between four players. To begin, a full pack of cards are shuffled and dealt face-down to the players. The game then proceeds in rounds. For each round, players play the top card from their hand and add it face-up to a pile on the table in front of them. The player who plays the highest value card is the winner of the round and their score is incremented by one. When all of the cards have been played the player with the highest score is declared the winner of the game.

The Problem… Design & implement a program to play a simple game of cards between four players. To begin, a full pack of cards are shuffled and dealt face-down to the players. The game then proceeds in rounds. For each round, players play the top card from their hand and add it face-up to a pile on the table in front of them. The player who plays the highest value card is the winner of the round and their score is incremented by one. When all of the cards have been played the player with the highest score is declared the winner of the game.

Picture it… Simple Game Pack of cards 4 Players Table 4 Scores 4 Cards player score Table player Pack of cards

Classes Simple Game Pack of cards 4 Players 4 Scores 4 Cards on table Player Name Hand of cards Cards Collection of cards Card Face value Suit

The Problem… Design & implement a program to play a simple game of cards between four players. To begin, a full pack of cards are shuffled and dealt face-down to the players. The game then proceeds in rounds. For each round, players play the top card from their hand and add it face-up to a pile on the table in front of them. The player who plays the highest value card is the winner of the round and their score is incremented by one. When all of the cards have been played the player with the highest score is declared the winner of the game.

Simple Game class properties Pack of cards 4 Players 4 Scores 4 Piles of cards on table constructor ( 4 players) creates the game with the given players methods playGame() plays a complete game sets scores getScore( player number) returns players score Represents a single card game played by 4 players

Player class properties Name Hand of cards constructor ( name) creates player with name & empty hand methods getName() returns players name add( Card) add the card to players hand playCard() removes and returns the top card from the players hand Represents a single player for a card game

Cards class properties Collection of cards constructor () creates a collection of cards with no cards in it! methods getTopCard() removes & returns top card from collection addTopCard( Card) adds the card to the collection shuffle() randomises order of cards in collection Represents a set of zero or more playing cards

Card class properties FaceValue Suit constructor ( card number) creates card with given position number in ordered pack! constructor ( faceValue, Suit) creates card with given face value & suit methods getFaceValue() returns faceValue getSuit() returns suit Represents a single playing card

Playing the Game Algorithm for playGame method Create the pack of cards Shuffle the pack Deal all the pack between the players Create empty piles of cards on table Set all players scores to zero For each round (until players have no cards left) Each player plays card by adding it to their pile on table Find biggest value card on top of piles on table Increment scores of players who played cards with biggest value

ToDo… Decide on implementation details For cards collection, for card, … Design other algorithms Shuffle, deal, … Build & test Extend Add GUI (Graphical User Interface) Make interactive Make clever games & playable over Internet!