Location Class Gridworld. Location Class Encapsulates the coordinates for an actor’s position in a grid – Row and Column number Rows increase going down.

Slides:



Advertisements
Similar presentations
Overloading Having more than one method with the same name is known as overloading. Overloading is legal in Java as long as each version takes different.
Advertisements

GridWorld Case Study The Classes A Summary by Jim Mims.
Warm-Up Complete the “What Makes a Map Useful?” concept map independently.
GEOGRAPHY REVIEW Thank you, Ms. Wampole!.
Singleton vs utility class  at first glance, the singleton pattern does not seem to offer any advantages to using a utility class  i.e., a utility class.
A. How do we tell the location by letters and numbers?
Direction at your fingertips. A compass rose is a design on a map that shows directions. It shows north, south, east, west, northeast, northwest, southeast,
APPLICATIONS OF TRIG TO NAVIGATION AND SURVEYING 9.5
Help me find the cardinal directions
1 Java Object Model Part 2: the Object class. 2 Object class Superclass for all Java classes Any class without explicit extends clause is a direct subclass.
Map Skills Vocabulary.
1.8 Number Lines 1.9 Opposites and Absolute Values Warm – up: State the numbers that would represent the following: – A gain of 24 yards – A loss of a.
Social Studies Map Skills
GETTING INPUT Simple I/O. Simple Input Scanner scan = new Scanner(System.in); System.out.println("Enter your name"); String name = scan.nextLine(); System.out.println("Enter.
Duke of Edinburgh’s Award
GridWorld Case Study1 Barbara Ericson Georgia Tech Jan 2008.
A compass rose is used to show directions on a map.
Agenda Scope of variables Comparable interface Location class in GridWorld homework.
1 Review for the AP CS Exam  Object Oriented Program Design – Program Design Read and Understand class specifications and relationships among the classes.
© A+ Computer Science - Row = 0 Column = 0.
Map Skills Compass Rose. Vocabulary Words A compass rose is a symbol that helps someone find directions on a map.
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.
Chapter 5 Recursion. Basically, a method is recursive if it includes a call to itself.
© A+ Computer Science - Grid is an interface that details the behaviors expected of a grid. All its methods are abstract methods.
Copyright Curt Hill GridBag Layout Manager A flexible but complicated layout.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Maths SMART Grade 4 © 2012 Alston Publishing House Pte Ltd 8-point compass.
Map Skills Review. How many Cardinal Directions are there? North South East West.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
Conditionals-part21 Conditionals – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
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.
MAP SKILLS What’s on a Map?.
Map Skills.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 3 Designing the Interface with Layout Managers.
Announcements Final Exam: TBD. Static Variables and Methods static means “in class” methods and variables static variable: one per class (not one per.
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.
TOWERS OF HANOI. : If n = 1, move disk 1 from pole 'A' to pole 'B'. else: 1.First, move n-1 disks from pole 'A' to pole 'C', using pole 'B' as.
Improving the Crab Mrs. C. Furman August 19, 2010.
ARRAYS Multidimensional realities Image courtesy of
Bell Ringer How many sig figs should be in the answer when adding ? How many sig figs should be in the answer when you have this equation 2.7*5.632*15?
Measurement and Geometry 43 North South East West South-East South-West North-West North-East
Bell Ringer: On your desk, there is a blank world map. Using the spaces provided on the map, please label the oceans and continents. You may NOT use any.
Unit 3 Locating Places On A Map When giving directions you need to know: Where you are & Where you want to go. A Compass rose show directions in terms.
Maps, Keys, and Legends.
Computer Science 1000 LOGO II. Boolean Expressions like Excel and Scratch, LOGO supports three Boolean operators less than (
A 2-D Array is a structure that storage space both vertically and horizontally. Thus, the array has both rows and columns. 2-D Arrays are used to create.
Social Studies Map Skills
Chapter 5.4 – Angles of elevation and depression
Object-oriented Programming in Java
Chapter 6 More Conditionals and Loops
Sinop is in the north of Turkey.
What type of angle is it?.
Agenda About Quiz ChameleonCritter class CrabCritter class homework.
Barbara Ericson Georgia Tech Jan 2008
Primitive Types Vs. Reference Types, Strings, Enumerations
© A+ Computer Science - GridWorld © A+ Computer Science -
© A+ Computer Science - GridWorld © A+ Computer Science -
A closer look at the world
Map & Compass Skills.
北 N north 西 W west 東 E east south南 S.
© A+ Computer Science - GridWorld The GridWorld case study provides a graphical environment where visual objects inhabit and interact.
© A+ Computer Science - GridWorld © A+ Computer Science -
CSE 142 Lecture Notes Defining New Types of Objects, cont'd.
GridWorld Case Study.
© A+ Computer Science - GridWorld © A+ Computer Science -
Agenda Dancing bug class Class vs object Comparable interface
Maps & Map Keys.
Parts of a Map.
© A+ Computer Science - GridWorld © A+ Computer Science -
Presentation transcript:

Location Class Gridworld

Location Class Encapsulates the coordinates for an actor’s position in a grid – Row and Column number Rows increase going down Columns increase going right – Also has methods that determine relationships between locations and compass directions – Every actor has a direction 0 for north, 45 is northeast, … – Location class also has eight constants that specify the constant direction NORTH, NORTHEAST, …

Location Class public Location(int r, int c) constructs a location with row r and column c public int getRow() returns the row of this location public int getCol() returns the column of this location public Location getAdjacentLocation(int direction) returns the adjacent location in the compass direction that is closest to direction public int getDirectionToward(Location target) returns the closest compass direction from this location toward target Testable API

Location Class return methods public boolean equals(Object other) returns true if other is a Location object with the same row and column values as this location, and false otherwise public int hashCode() returns a hash code (unique key) for this location public int compareTo(Object otherObject) returns a negative integer if this location is less than other (if the row is less than other.row or if the rows are equal and column is less than other.column), zero if the two locations are equal, or a positive integer if this location is greater than other. Locations are ordered in row-major order public String toString() returns a string with the row and the column of this location, in the format (row, col) Testable API

Location Class Compass directions: public static final int NORTH = 0; public static final int EAST = 90; public static final int SOUTH = 180; public static final int WEST = 270; public static final int NORTHEAST = 45; public static final int SOUTHEAST = 135; public static final int SOUTHWEST = 225; public static final int NORTHWEST = 315;

Location Class Turn angles: public static final int LEFT = -90; public static final int RIGHT = 90; public static final int HALF_LEFT = -45; public static final int HALF_RIGHT= 45; public static final int FULL_CIRCLE = 360; public static final int HALF_CIRCLE = 180 ; public static final int AHEAD = 0;

Examples Location loc1 = new Location(5,7); Location locOrig = new Location(0,0); Location loc2 = loc1.getAdjacentLocation(Location.WEST); // (5,6) Location loc3 = loc1.getAdjacentLocaton(Location.NORTHEAST); // (4,8) Location loc4 = locOrig.getAdjacentLocaton(Location.WEST); // (0,-1) int dir = loc1.getDirectionToward(new Location(6,8)); // 135

Turning by an Amount You may have been using multiple calls to the turn() method to turn an Actor – We can use setDirection and Location constants for this instead – setDirection(getDirection() + Location.HALF_RIGHT); // turn 45 degrees

Exercise Set 3 Location loc1 = new Location(4, 3); Location loc2 = new Location(3, 4); 1.How would you access the row value of loc1 ? loc1.getRow() 2.What is the value of b after the following statement is executed? boolean b = loc1.equals(loc2); false 3.What is the value of loc3 after the following? Location loc3 = loc2.getAdjacentLocation(Location.SOUTH); (4, 4) 4.What is the value of dir after the following? int dir = loc1.getDirectionToward(new Location(6,1)); How does the getAdjacentLocation method know which location to return? It first takes the direction passed to it and converts it to the closest 45 degree direction. Then it looks in that direction to return the adjacent location