Agenda About Quiz ChameleonCritter class CrabCritter class homework.

Slides:



Advertisements
Similar presentations
GridWorld Case Study The Classes A Summary by Jim Mims.
Advertisements

GridWorld Case Study Part 3 GridWorld Classes and Interfaces A Summary by Jim Mims.
GridWorld Case Study Part 2 Bug Variations A Summary by Jim Mims.
Object Oriented Programming with Java
© A+ Computer Science - GridWorld © A+ Computer Science -
A subclass can add new private instance variables A subclass can add new public, private or static methods A subclass can override inherited methods A.
Critters A Study in Design Patterns. Design Patterns  Not specific algorithms or data structures  A general reusable solution to a common problem.
Location Class Gridworld. Location Class Encapsulates the coordinates for an actor’s position in a grid – Row and Column number Rows increase going down.
1 CSC 222: Computer Programming II Spring 2005 Inheritance  derived class, parent class  inheriting fields & methods, overriding fields and methods 
Using a different image than normal Multiple images for a class Controlling the mouse click Controlling the keys pressed Launching an input dialog box.
CSSE221: Software Dev. Honors Day 6 Announcements Announcements Questions? Questions? Hint on BallWorlds’ changing the x and y coords in 2 nd half of lecture.
© 2003 Walter Savitch These slides are for the exclusive use of students in CSE 11 at UCSD, Winter quarter They may not be copied or used for any.
Pulling out a common superclass Barb Ericson Georgia Tech.
Chapter 13 – Aggregation, Composition, and Inheritance
Inheritance using Java
GridWorld Case Study1 Barbara Ericson Georgia Tech Jan 2008.
Georgia Institute of Technology Extending the Case Study Barbara Ericson January 2005.
1 Review for the AP CS Exam  Object Oriented Program Design – Program Design Read and Understand class specifications and relationships among the classes.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
© A+ Computer Science - Row = 0 Column = 0.
GridWorld Case Study Barbara Ericson March 24, 2007.
Java Arrays  Java has a static array capable of multi-dimensions.  Java has a dynamic array, which is also capable of multi-dimensions.  The ArrayList.
LECTURE 9: INTERFACES & ABSTRACT CLASSES CSC 212 – Data Structures.
© 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.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
The GridWorld Case Study Program Section 1 - Overview of the Class Hierarchies Section 2 - The Actor Class Section 3 - The Rock and Flower Classes Section.
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:
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
CS1101 Group1 Discussion 6 Lek Hsiang Hui comp.nus.edu.sg
GridWorld Case Study The case study is a program that simulates actions and interactions of objects in a two- dimensional grid. During a single step of.
Java Inheritance 1/13/2015. Learning Objectives Understand how inheritance promotes software reusability Understand notions of superclasses and subclasses.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
Object Oriented Programming (OOP) is a style of programming that incorporates these 3 features: Encapsulation Polymorphism Class Interaction.
GridWorld.
Exposure Java 2012 APCS Edition Chapter 13 Slides
Re-Intro to Object Oriented Programming
OOP: Encapsulation &Abstraction
Java Inheritance.
GridWorld Part 4 Meet the Critters.
Barbara Ericson Georgia Tech Jan 2008
AP "Case Studies" A big program for AP students to understand
CS 302 Week 11 Jim Williams, PhD.
Critter exercise: Snake
Interface.
Homework 8: Critters (cont.)
© A+ Computer Science - GridWorld © A+ Computer Science -
© A+ Computer Science - GridWorld © A+ Computer Science -
A closer look at the world
תירגול 9 אובייקטים.
CS 302 Week 9 Jim Williams.
Building Java Programs
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Agenda About Homework for BPJ lesson 36 About practice of last class
Building Java Programs
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
GridWorld Part 4 Meet the Critters.
© A+ Computer Science - GridWorld The GridWorld case study provides a graphical environment where visual objects inhabit and interact.
Chapter 14 Abstract Classes and Interfaces
© A+ Computer Science - GridWorld © A+ Computer Science -
GridWorld Case Study.
CMPE212 – Reminders Quiz 1 marking done. Assignment 2 due next Friday.
More on Creating Classes part 3
© A+ Computer Science - GridWorld © A+ Computer Science -
Agenda Dancing bug class Class vs object Comparable interface
Building Java Programs
© A+ Computer Science - GridWorld © A+ Computer Science -
Unit 3 - Introduction to Inheritance - Example
Presentation transcript:

Agenda About Quiz ChameleonCritter class CrabCritter class homework

Quiz State variables of subclass Static vs static final Accessor vs mutator methods An accessor method is used to return the value of a private field A mutator method is used to set a value of a private field Accessor methods in Location class getCol, getRow, getAdjacentLocation, toString

Mutator methods in World class add(..), remove(..), addGridClass(..), addOccupantCass(..) GridWorld : programming (j) : display old message + new new message aWorld.setMessage( aWorld.getMessage + “ “ + aBug.getLocation.toString()); (o) Remove a bug aworld.remove(aBug.getLocation()); (Y) get adjacent empty location of critter and stores one to actorLoc. ArrayList<Location> locArry= aGrid.getEmptyAdjacentLocations(aCritter.getLocation() ; Location actorLoc = locArry.get(0);

Critter’s act() method public void act() { if (getGrid() == null) return; ArrayList<Actor> actors = getActors(); processActors(actors); ArrayList<Location> moveLocs = getMoveLocations(); Location loc = selectMoveLocation(moveLocs); makeMove(loc); }

ChameleonCritter class The ChameleonCritter class gets the same neighboring actors just like a Critter, but it doesn’t process actors by eating them. Instead, when a ChameleonCritter processes actors, it randomly selects one and changes its own color to the color of the selected actor.

ChameleonCritter class What is its super class? State variable(s)? Constructor(s)? Method(s)? Overriding method(s)? What is the difference between ChameleonCritter and Critter?

Critter class public void processActors(ArrayList<Actor> actors) { for (Actor a : actors) if (!(a instanceof Rock) && !(a instanceof Critter)) a.removeSelfFromGrid(); }

ChameleonCritter class public void processActors(ArrayList<Actor> actors) { int n = actors.size(); if (n == 0) return; int r = (int) (Math.random() * n); Actor other = actors.get(r); setColor(other.getColor()); }

Critter class public void makeMove(Location loc) { if (loc == null) removeSelfFromGrid(); else moveTo(loc); }

ChameleonCritter class public void makeMove(Location loc) { setDirection( getLocation().getDirectionToward(loc)); super.makeMove(loc); }

CrabCritter class A CrabCritter is a critter that eats whatever is found in the locations immediately in front, to the right-front, or to the left-front of it. It will not eat a rock or another critter(inherited from the Critter class). A CrabCritter can move only to the right or to the left. If both locations are empty it randomly selects one. If a CrabCritter cannot move, then it turns 90 degrees, randomly to the left or right.

CrabCritter class What is its super class? State variable(s)? Constructor(s)? Method(s)? Overriding method(s)? Why does CrabCritter need to override those methods in its parent class?

Homework Please download the homework file “Homework – Jan 7” from course slides and finish it by Thursday. It has to be hand written.

Example for 2nd part Actor Bug State variables: grid, location, direction, color Constructor(s): Actor() Method(s): getColor(), setColor(), getDirection(), setDirection(), getGrid()….. extends Bug State variables: grid, location, direction, color Constructor(s): Bug(); Bug(color..) Method(s): ……….