CS12230 Introduction to Programming Extra example– More on responsibilities 1.

Slides:



Advertisements
Similar presentations
Chapter 7. Binary Search Trees
Advertisements

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)
1 Todays Objectives Announcements Homework #1 is due next week Return Quiz 1 – answers are posted on the Yahoo discussion page site Basic Java Programming.
CS12230 Introduction to Programming Lecture 4-x – Consolidation 1.
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
CS12230 Introduction to Programming Tying things together.
Microsoft® Small Basic Advanced Games Estimated time to complete this lesson: 1 hour.
PLANNING THE TIC TAC TOE GAME BY NEEL DAVE. TIC TAC TOE INSTRUCTIONS Tic Tac Toe Instructions The basic concept of Tic Tac Toe 1.This is a game for two.
Integer Tic Tac Toe Let’s Begin Rules: 1.Erase all x’s and o’s from the previous game before you begin. 2.Decide which player will be x’s and which will.
Top-Down Design CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
ELECTION NIGHT CITS1001. Example development Understanding the problem Understanding the solution Structuring the solution Implementing the solution (Testing.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Representing a Game Board In a game, we represent the action taking place using an array – In a very simple game, we use individual variables to represent.
CS 106 Introduction to Computer Science I 11 / 13 / 2006 Instructor: Michael Eckmann.
Design Example. Requirements Make a program that simulates the game of blackjack For now, we ignore money/betting…. just simulate game play But… this.
Priority Queues and Heaps. Overview Our last ADT: PriorityQueueADT A new data structure: heaps One more sorting algorithm: heapsort Priority Queues and.
CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 05 / 03 / 2010 Instructor: Michael Eckmann.
1 Objects and Classes Introduction to Classes Object Variables and Object References Instantiating Objects Using Methods in Objects Reading for this Lecture:
Learning Shape in Computer Go David Silver. A brief introduction to Go Black and white take turns to place down stones Once played, a stone cannot move.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 02 / 11 / 2009 Instructor: Michael Eckmann.
Miscellaneous OOP topics Java review continued. Simple data types & wrapper classes Simple data types are the built-in types provided as part of the Java.
Using Reduction for the Game of NIM. At each turn, a player chooses one pile and removes some sticks. The player who takes the last stick wins. Problem:
Great Theoretical Ideas in Computer Science.
A Storyteller’s Tale Many years ago, wandering storytellers travelled from village to village telling stories in exchange for food, shelter, and money.
CS 106 Introduction to Computer Science I 04 / 13 / 2007 Friday the 13 th Instructor: Michael Eckmann.
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.
Putting together a complete system Chapter 10. Overview  Design a modest but complete system  A collection of objects work together to solve a problem.
Catch the Spirit of Mathematical Practices Mathematics Investigations Q-Cards: Rational Numbers The Q-Card game has 8 starter cards, 28 playing cards,
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Game theory Impartial Games.  Two-person games with perfect information  No chance moves  A win-or-lose outcome  Impartial games ◦ Set of moves available.
CSC 205 Programming II Lecture 18 The Eight Queens Problem.
Making Decisions uCode: October Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
Chapter 9 Putting together a complete system. This chapter discusses n Designing a complete system. n Overview of the design and implementation process.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW AI for games: min-max search COMP #
Linked Lists part 1 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
Unit Testing CSIS 3701: Advanced Object Oriented Programming.
More on OO Programming Our programs will no longer just be a main method or a main which calls a collection of other methods –instead, a program will be.
Multiples and Factors. Multiples A multiple is a number that is in the times tables. A multiple is a number that is in the times tables. Multiples of.
1.Reading from Keyboard 2.Main programs 3.Responsibilities 1 CS12230 Introduction to Programming Lecture 2or3-Other things.
By Mr. Putnam. In Catfall, the goal of the game is to touch the falling cats with the mouse. Every time you touch a cat, your score goes up by one point.
CSE 143 Lecture 18 More Recursive Backtracking slides created by Marty Stepp
An Introduction to Programming and Object Oriented Design using Java 2 nd Edition. May 2004 Jaime Niño Frederick Hosch Chapter 8: Putting a System Together.
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
Chomp. How is the game played Human player goes first choose a square, all to the right and down are “eaten” computer takes a turn whoever is forced to.
The Lovely Game of NIM. Version 1 - Classic NIM You will need seven objects, such as counters or blocks. It is a game for two players. Place the 7 counters.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Java Scanner Class Keyboard Class. User Interaction So far when we created a program there was no human interaction Our programs just simply showed one.
Lecture 3: More on Classes Textbook: Chapter 2 Recap: –Classes vs. Objects –Q: What comes first a class or an object? –Q: Do we need a class to create.
CONDITIONALS CITS1001. Scope of this lecture if statements switch statements Source ppts: Objects First with Java - A Practical Introduction using BlueJ,
CS1020 L AB 3 (L INKED L IST ) Problem 1: Balls Problem 2: Josephine Problem 3: Keyboard.
Chapter 4 - Finishing the Crab Game
Introduction to Computer Science / Procedural – 67130
CS305J Introduction to Computing
CompSci 230 Software Construction
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Lesson 2: Building Blocks of Programming
Dynamic Memory A whole heap of fun….
CS18000: Problem Solving and Object-Oriented Programming
GAMBLER’S RUIN in a FAIR GAME
Console.WriteLine(“Good luck!”);
Java Programming Language
Can you put the symbols in?
Try starting with fewer objects to investigate.
Structure diagrams for lab 13
Presentation transcript:

CS12230 Introduction to Programming Extra example– More on responsibilities 1

Recap: Responsibilities Our first examples were mostly about storing information in a simple class – methods used are: constructors, gets, sets, toString, readKeyboard That’s fine but we need more! Once you have more than one class you also typically notice that the different classes have different responsibilities 2

More on responsibilities example to read (code in directory) Nim is played by 2 players who use a pile of sticks. The idea is that the players take it in turns taking away number of sticks (up to a maximum) until the person who takes the last stick is the loser. Eg. 12 to start – 3 as maximum player 1 takes 3, player 2 takes 3, player 1 takes 3, player 2 takes 2, player 1 takes last and loses! 3

Let’s play it And on board draw a rough object diagram Class diagram is next slide 4

Classes: Game, Player, Pile Player – Knows: name, how many just taken (and the pile) – Does: take a turn by removing sticks from Pile Pile – Knows: number of sticks left – Does: reduces its number of sticks Game – Knows about players and pile, who just played and who’s next – Does: Conducts the play until done, giving turns Stops play when winner Who was winner 5 Knows – instance variables Does – methods

6 Player -String name +Player (String n) +void takeTurn() Game -Player p1 -Player p2 -Pile pile +Game() +void playGame() +void oneTurn() +boolean isOver() +Player whowon() Pile -int sticks +Pile (int initialNum) +void take(int n) +boolean isEmpty

Code is on next couple of slides it is pretty hard but actually almost all doable at this point – look at it in your own time the code is in the 2-week2-directory 7

8

9

Another example to think about Xs and Os is played by 2 players who put marks on a board. Each player in turn puts their symbol on the board until either someone wins or the board is full. Classes? Game, Player, Board Responsibilities? 10

So what have we done this week? Reinforced basic classes and objects Linking – when one object has 0 or 1 object attributes Reading from the keyboard with Scanner Instance variables vs. local variables The dreaded null pointer Examples that have an Application and DO things Notes up to and including 06 11