Critter exercise: Snake

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

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);
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
EC-241 Object-Oriented Programming
CS 112 Introduction to Programming Critters/Event-Driven Programming; Interface Yang (Richard) Yang Computer Science Department Yale University 308A Watson,
CS 112 Introduction to Programming
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-2: Static Data; More Inheritance reading:
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Critters; Subtype Polymorphism Reading: HW9 Handout, Chapter 9.2.
Copyright 2010 by Pearson Education 1 Assignment 11: Critters reading: HW11 assignment spec.
OOPDA Review. Terminology class-A template defining state and behavior class-A template defining state and behavior object-An instance of a class object-An.
Copyright 2010 by Pearson Education 1 Assignment 11: Critters.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors reading:
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-x: Critters reading: HW9 Spec.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-4: Static Methods and Fields.
Copyright 2010 by Pearson Education Homework 9: Critters (cont.) reading: HW9 spec.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-2: Interacting with the Superclass ( super ) reading:
Building Java Programs Chapter 8 Lecture 8-3: Object state; Homework 8 (Critters) reading:
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-2: Interacting with the Superclass ( super ); Discussion of Homework 9:
Copyright 2010 by Pearson Education Building Java Programs Homework 8: Critters reading: Critters Assignment Spec.
Copyright 2010 by Pearson Education Homework 8: Critters reading: HW8 spec.
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-2: Interacting with the Superclass ( super ); Discussion of Homework 9:
Copyright 2010 by Pearson Education Homework 9: Critters (cont.) reading: HW9 spec.
Class Everything in Java is in a class. The class has a constructor that creates the object. If you do not supply a constructor Java will create a default.
Copyright 2009 by Pearson Education Building Java Programs Chapter 8: Classes Lecture 8-3: More Critters, static.
Copyright 2009 by Pearson Education Building Java Programs Chapter 9: Inheritance and Interfaces Lecture 9-1.
CS 112 Introduction to Programming Method Overriding; Object Hierarchy; Event-Driven Programming Yang (Richard) Yang Computer Science Department Yale University.
CS 112 Introduction to Programming Critters, Polymorphism Yang (Richard) Yang Computer Science Department Yale University 208A Watson, Phone:
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
Building Java Programs
Object-Oriented Programming
CSE 8A Lecture 17 Reading for next class: None (interm exam 4)
Weds, Nov. 26th Reading: Section Handout
Homework 8: Critters reading: HW8 spec.
The software crisis software engineering: The practice of developing, designing, documenting, testing large computer programs. Large-scale projects face.
Building Java Programs
Agenda About Quiz ChameleonCritter class CrabCritter class homework.
More Object Oriented Programming
Can perform actions and provide communication
HW11 Assignment Specification
Lecture 8-3: Encapsulation, this
Pass by Reference, const, readonly, struct
Can perform actions and provide communication
Classes & Objects: Examples
Homework 8: Critters (cont.)
CSE 142 Critters (IPL) behavior: Ant Bird Hippo Vulture
ITunes Lab Copyright © 2012 Pearson Education, Inc.
Adapted from slides by Marty Stepp and Stuart Reges
Building Java Programs
The software crisis software engineering: The practice of developing, designing, documenting, testing large computer programs. Large-scale projects face.
Building Java Programs
Can perform actions and provide communication
Building Java Programs
Building Java Programs
Building Java Programs
Basics of OOP A class is the blueprint of an object.
Building Java Programs
Homework 8: Critters (cont.)
Building Java Programs
Building Java Programs
Homework 9: Critters (cont.)
Building Java Programs
Chapter 9 9-3: Polymorphism reading: 9.3
Building Java Programs
Chapter 11 Classes.
Inheritance in C++ Inheritance Protected Section
Presentation transcript:

Critter exercise: Snake Method Behavior constructor public Snake() eat Never eats fight always forfeits getColor black getMove 1 E, 1 S; 2 W, 1 S; 3 E, 1 S; 4 W, 1 S; 5 E, ... toString "S"

Critter exercise: Hipster All hipsters want to get to the bar with the cheapest PBR That bar is at a randomly-generated board location (On the 60-by-50 world) They go north then east until they reach the bar

Static members static: Part of a class, rather than part of an object. Object classes can have static methods and fields. Not copied into each object; shared by all objects of that class. class state: private static int staticFieldA private static String staticFieldB behavior: public static void someStaticMethodC() public static void someStaticMethodD() object #1 state: int field2 double field2 behavior: public void method3() public int method4() public void method5() object #2 state: int field1 double field2 object #3