CS12230 Introduction to Programming Lecture 4-x – Consolidation 1.

Slides:



Advertisements
Similar presentations
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Advertisements

Finding The Unknown Number In A Number Sentence! NCSCOS 3 rd grade 5.04 By: Stephanie Irizarry Click arrow to go to next question.
Advanced Piloting Cruise Plot.
Chapter 1 The Study of Body Function Image PowerPoint
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Chapter 1 Image Slides Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Maureen Curran and Mary Lou Aalbers Hazelwood School District Teacher tips.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
10 Copyright © 2005, Oracle. All rights reserved. Reusing Code with Inheritance and Polymorphism.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
My Alphabet Book abcdefghijklm nopqrstuvwxyz.
Multiplying binomials You will have 20 seconds to answer each of the following multiplication problems. If you get hung up, go to the next problem when.
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Addition Facts
1 Learning Touchmath *Graphics taken from
Year 6 mental test 5 second questions
Lecture 10 Flow of Control: Loops (Part 2) COMP1681 / SE15 Introduction to Programming.
ZMQS ZMQS
1. 2 Its almost time to take the FCAT 2.0! Here are some important explanations and reminders to help you do your very best.
1. 2 Its almost time to take the Computer Based Exam Biology EOC! Here are some important explanations and reminders to help you do your very best.
Data Structures ADT List
1 Joe Meehean. Ordered collection of items Not necessarily sorted 0-index (first item is item 0) Abstraction 2 Item 0 Item 1 Item 2 … Item N.
ABC Technology Project
Page 1 – Spring 2010Steffen Vissing Andersen Software Development with UML and Java 2 SDJ I2, Spring 2010 Agenda – week 7, 2010 • Pakages • Looking back.
© Charles van Marrewijk, An Introduction to Geographical Economics Brakman, Garretsen, and Van Marrewijk.
VOORBLAD.
15. Oktober Oktober Oktober 2012.
Review Pseudo Code Basic elements of Pseudo code
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Squares and Square Root WALK. Solve each problem REVIEW:
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
Do you have the Maths Factor?. Maths Can you beat this term’s Maths Challenge?
© 2012 National Heart Foundation of Australia. Slide 2.
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Chapter 5 Test Review Sections 5-1 through 5-4.
SIMOCODE-DP Software.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
1. 2 It’s almost time to take the Computer Based Exams (FCAT 2.0 and EOC)! Here are some important explanations and reminders to help you do your very.
Januar MDMDFSSMDMDFSSS
Week 1.
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
A SMALL TRUTH TO MAKE LIFE 100%
1 Unit 1 Kinematics Chapter 1 Day
PSSA Preparation.
How Cells Obtain Energy from Food
CpSc 3220 Designing a Database
Towers of Hanoi
Traktor- og motorlære Kapitel 1 1 Kopiering forbudt.
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.
CS12230 Introduction to Programming Extra example– More on responsibilities 1.
Presentation transcript:

CS12230 Introduction to Programming Lecture 4-x – Consolidation 1

What have we learned: Design Java Rest of these slides 2 examples – nightclass and nim 2

Simple Nim is a two-player game in which players take turns removing objects from a pile. On each turn, a player must remove at least one stick, and may remove any number of objects up to some maximum. The Loser is the player who takes the last stick. Example with 7 sticks, maximum of 3 per turn: player 1 takes left player 2 takes left player 1 has to take the last one and loses (See wikipedia for more interesting versions) 3

ANALYSIS 4

Use Case Diagram 5 - put in initial info - play game 2 users Describes what happens in broad terms Shows who the users are (sometimes more than one kind)

DESIGN 6

Design Tools Diagrams: – Object diagram – Class diagram NEW: – Pseudocode or flow charts 7

Object Diagram 8 nim pile p1 p2 pile “fred” pile “bill” 12 :Game :Pile :Player :NimGame Could amalgamate Game and NimGame by putting main() in Game A snapshot of a program at some time – different at different times

Class Diagram 9 Application Pile -int numsticks Player -String name -Pile pile Game -Player p1, p2 -Pile pile A static description of the kinds of things (classes) in a program

Pseudocode or Flowchart Playgame: While ! Game over -play one turn 10 Put in initial info: – this is constructor of Game -Make pile -Make player1 -Make player 2 -Link up players and pile Play one turn: -get num sticks from curent_plr -current_ plr.takeTurn(num) These are all in Game (and more too) Game over: Is the pile empty? A way of describing the behaviour of a program

Pseudocode (continued) 11 This is in Player - Remember: responsibilities takeTurn (int num): -pile.remove(num) remove (int num): -do a bunch of checking -piletotal=piletotal-num This is in Pile - Remember: responsibilities

12

Notice how you can rely on the objects to call other objects to fulfil responsibilities Eg. in Player we have void takeTurn(int num){ pile.remove(int num) } With a little extra checking 13

JAVA 14

Java Notes Basic syntax of classes Being able to link Flow of control We have also done collections (not used in Nim) 15

So, start with Use Case and ‘top level’ class In main() //can be in Game or in another class Game nim=new Game(val,max,a,b); nim.playGame(); In Game class elaborate as you go – use methods of THIS class if complicated public Game (int initial, int max, String p1n, String p2n) { etc…. public void playGame () { while (!gameOver()) { onePlay(); } System.out.println("\n\n***THE WINNER IS***: "+winner()); } 16

But can also pass responsibilities to objects of OTHER classes public boolean gameOver () { //true if the number of sticks is zero return pile.getSticks() == 0; } public void onePlay () { // find out how many player wants, // check and fix if necessary, // take that many away from the pile 17

18 Notice how by referring back to the documentation, we know what objects can do. If the method at the next level is needed and not there – then write it. Example in Game: public void onePlay () { if (!gameOver()) { System.out.println("Player " + currentPlayer.getName() +" how many?"); int numTaken =in.nextInt(); if (numTaken maxOnATurn) { System.out.println("bad-taking 1“); numTaken=1; } currentplayer.takeTurn(numTaken); etc.

Think about it as a play With the object diagram as a picture of the actors And the actors telling other actors what to do 19 nim pile p1 p2 pile “fred” pile “bill” 12 :Game :Pile :Player :NimGame

20

21

A nightclass A night class has a teacher and students We want to be able to administer the list and the information with a simple java program 22

ANALYSIS - Use Case Diagram 23 - put in initial info -Add students -Remove students -Check information administrator Describes what happens in broad terms Shows who the users are (sometimes more than one kind)

DESIGN - Diagrams 24 Object diagram Class diagram How do you do the various use-cases

The lines here are NOT the same as the ones we have talked about (they are ‘refers to’ but they do give some flavour – in class do this properly!) 25

IMPLEMENTATION - java 26 See the codein the nightclass Not the readKeyboard() method for Teacher and Student as an alternative to setting values Fill in some of the missing parts