# Introduction to Java The GridWorld Study

Section 2: AP Test Preparation: Lecture 3 | 54:18 min

Lecture Description

In this lesson, our instructor Tom Quayle goes through an introduction on the GridWorld Study. He starts with an overview of GridWorld and then goes over the testable APIs. He explains the location class, grid interface, actor class, rock class, boxbug cl

Table of Contents

Section 1: AP Computer Science

About the AP Computer Science Exam

17m 11s

- Intro0:00
- Roadmap0:16
- Java Editor0:45
- The AP Computer Science Exam1:30
- When It's Administered1:31
- Final Score1:49
- College Credit2:08
- Format of AP Exam Questions2:20
- Two Sections2:26
- Section 12:31
- Section 22:40
- Scoring3:23
- Multiple Choice Questions3:57
- Example4:04
- Check Answer in Java Editor5:06
- Keep in Mind6:21
- Multiple Choice, Multiple Answers6:58
- Evaluate Each Roman Numeral Separately7:08
- Example Multiple Choice Question7:34
- Java Editor8:35
- Free Response Questions12:25
- Example12:40
- Java Editor14:35
- AP Java Subset17:06
- What It Is17:37
- Primitive Types18:49
- Arithmetic Operators19:11
- Assignment Operator19:46
- Combined Arithmetic / Assignment Operators19:51
- Increment / Decrement Operators20:13
- Relational Operators20:36
- Logical Operators21:06
- Numeric Casts21:44
- Numeric Wrapper Classes22:39
- Math Library Methods23:08
- String Operations23:50
- User Input25:33
- Output27:17
- Program Invocation28:13
- Arrays29:06
- Lists29:52
- Control Structures30:47
- Methods31:27
- Classes32:10
- Inheritance33:09
- Exceptions34:22
- Tips for Taking the Exam34:55
- Before the Exam35:04
- During the Exam36:58
- Summary39:27

Types, Variables, & Arithmetic Operators

23m 20s

- Intro0:00
- Roadmap0:11
- Primitive Data Types0:37
- Int1:48
- Double2:42
- Boolean3:53
- Variables4:04
- Declaring a Variable4:16
- Assigning a Value6:01
- Declaring and Assigning on the Same Line6:36
- Casting7:00
- Mixing Types7:10
- Automatic Casting8:31
- Find Variables - Constants9:21
- Final Variables9:40
- Constants Written in All Capitals10:43
- Arithmetic Operators11:59
- Five Arithmetic Operators12:10
- Result Depends on Type of Operands13:49
- Assignment Operators14:59
- Compound Assignment Operators15:13
- Examples15:43
- Increment / Decrement Operators17:08
- Add 1 (++)17:37
- Subtracts 1 (--)18:25
- Summary21:41

Equality, Relational, & Logical Operators

22m 34s

- Intro0:00
- Roadmap0:11
- Equality and Relational Operators1:09
- Equal to1:15
- Not Equal to2:25
- Relational Operators2:40
- Logical Operators3:44
- Three Operators: And, Or, Not3:53
- AND Defined4:18
- OR Defined4:50
- NOT Defined5:19
- Example: And5:43
- Example: Or6:23
- Example: Not6:41
- Truth Tables7:16
- Truth Tables for AND7:30
- Truth Tables for OR8:05
- Truth Tables for NOT8:47
- Short-Circuit Evaluation10:03
- Example10:32
- This Behavior Can be Useful in Program Design12:29
- De Morgan's Laws13:53
- First Law14:04
- Second Law14:29
- Operator Precedence15:28
- List of Operators in Highest to Lowest Precedence15:38
- Evaluation on Operators17:30
- Summary20:26

Input, Output, & Errors

24m 7s

- Intro0:00
- Roadmap0:11
- Getting Input from the User0:42
- For AP Questions, Will Look Like One of the Following0:54
- One Method of Getting Input From the User2:50
- Scanner Class3:20
- Providing Output to the User4:38
- Only 2 Included in AP Subset5:06
- Example: Print Two Strings on the Same Line5:45
- Example: Print a String and an Integer6:16
- Example: Print a Blank Line6:40
- Java Code Example7:04
- Escape Sequences11:10
- Backslash Character Followed by One or More Additional Characters11:23
- Newline Character11:49
- Double Quote Character12:39
- Backslash Character13:48
- Java Code Examples: Printing Escape Sequences14:43
- Exception Handling16:25
- Describe As16:33
- Exceptions Within the AP Subset That Provides Structured Way to Handle Errors17:18
- Java Code Example19:40
- Summary22:21

Conditional Statements

28m

- Intro0:00
- Roadmap0:09
- Conditional Statements0:55
- Based on Value of a Boolean Expression1:40
- Switch Statement2:42
- The If Statement2:59
- Structure of If Statement3:06
- The If-Else Statement4:46
- The If-Else Statement6:02
- If expression - False6:34
- Nested If-Else Statements7:13
- 'Nest'7:28
- Nested If-Else Statements7:56
- First Thing to Determine9:28
- Code10:24
- The Extended If Statement13:14
- Code15:45
- The Switch Statement18:54
- The Way It Works19:37
- Example: Switch Statement in a Java Program22:44
- Summary27:03

Loops

32m 29s

- Intro0:00
- Roadmap0:07
- Repeating an Action0:53
- Example1:03
- Repeating an Action1:21
- Use Brute Force Method1:32
- The While Loop2:16
- To Repeat An Action2:55
- Example: While Loop4:57
- The Do Loop5:53
- Example: Do Loop8:00
- Distinction of Do Loop & While Loop9:04
- The For Loop10:30
- The Way It Works10:41
- Example: The For Loop12:43
- The Enhanced for Loop14:18
- The Way It Works14:42
- Example:Enhanced for Loop16:32
- Nested While Loops19:06
- Example19:33
- Example: Nested While Loop (Code)20:47
- Nested For Loops22:36
- Example22:51
- Example: Nested For Loop (Code)23:29
- The Return Statement24:30
- Example25:03
- The Break Statement26:21
- The Continue Statement28:01
- Summary30:56

Strings

42m 20s

- Intro0:00
- Roadmap0:25
- Literal Strings1:27
- Class: Strings1:38
- String Is Immutable2:11
- Example2:53
- Literal Strings3:27
- String Variables4:24
- Example: String Variable5:56
- String Concatenation7:03
- Example7:37
- Example: String Concatenation8:26
- String Concatenation10:00
- Assignment Operator10:11
- Example10:48
- Example: String Concatenation11:25
- String Length13:05
- Example: String Length14:16
- String Comparison16:04
- Equals Method16:37
- Example: String Comparison17:08
- String Comparison21:40
- String.Equals: Case-Sensitive21:49
- Equals Ignore Case: Case-Insensitive22:14
- Example: Case-Sensitive and Case-Insensitive Comparison22:46
- String Comparison25:38
- Compare To (String.compareTo)25:53
- Example27:27
- Example: Sting Comparison Using the compareTo Method28:15
- Taking a Subset of a String30:34
- Substring Method30:59
- 2 Versions31:08
- 1st Version: Takes One Parameter31:27
- 2nd Version: Takes Two Parameters32:41
- Example: Substring34:02
- Searching Within a String36:04
- indexOf Method36:12
- 1st Version: Takes One Parameter36:26
- 2nd Version: Takes Two Parameters37:27
- Searching Within a String38:36
- lastIndexOf Method38:53
- 1st Version: Takes One Parameter39:08
- 2nd Version: Takes Two Parameters39:28
- Summary40:43

Arrays

47m 2s

- Intro0:00
- Roadmap0:14
- Declaring and Creating an Array0:49
- Array Defined0:55
- 1st Way to Declare and Create and Array1:10
- 2nd Way to Declare and Create and Array2:15
- Referring to Elements in an Array5:12
- Integer Expression5:39
- Code Example: Declaring and Creating Arrays7:26
- Referring to Elements in an Array9:12
- Example9:45
- Code Example: Looping Through an Array of Ints12:23
- Referring to Elements in an Array15:35
- Enhanced for Loop15:42
- Code Example: Looping Through an Array of Strings With an Enhanced for Loop17:19
- Referring to Elements in an Array19:25
- ArrayIndexOutOfBoundsException19:37
- Code Example: Array Index Out of Bounds Exception21:03
- Resizing Arrays23:05
- Example23:33
- Code Example: Resizing Arrays25:15
- Copying Arrays28:13
- Passing an Array to a Method30:09
- Example30:15
- When Calling This Method: Pass in an Array33:40
- Code Example: Passing an Array to a Method34:06
- Returning an Array From a Method36:02
- Create a Method36:12
- Calling This Method38:42
- Code Example: Returning an Array to a Method39:24
- Two-Dimensional Arrays42:23
- Length Method43:17
- Number of Columns43:42
- Summary45:00

Classes & Objects

47m 33s

- Intro0:00
- Roadmap0:46
- Classes and Objects2:03
- Class2:17
- Object2:34
- Constructors3:43
- Constructors5:34
- Methods7:11
- Example: getName Method7:44
- Methods8:45
- Example9:08
- Example in Java Program10:19
- Data Fields12:48
- Way to Find Data Fields13:10
- Data Fields13:50
- Example: Instantiate Two Objects with Different Instance Data14:43
- Return Type16:21
- A Primitive Type16:37
- An Object of a Class Type16:49
- Return Type17:25
- Access Control18:19
- Public, Protected and Private19:31
- Assumptions Made in AP Java Subset20:00
- Access Control20:58
- Definition of Public21:08
- Definition of Protected21:18
- Definition of Private21:28
- Guidelines on What to Make Public/ Private21:36
- Accessors and Modifiers24:47
- Accessor25:35
- Modifier or Mutator26:24
- Static vs. Instance27:15
- Static Member27:26
- Example: Static vs. Instance27:59
- Code Example30:19
- Passing Data to Method34:00
- Code Example36:17
- Getting Data Back From Methods37:28
- To Make Use of a Return Value37:53
- Code Example38:51
- Overloaded Methods39:39
- Signature Includes40:19
- Signature Does Not Include40:45
- Example: Overloaded Methods43:52
- Overloaded Methods44:19
- Summary45:00

Inheritance & Polymorphism

31m 30s

- Intro0:00
- Roadmap0:42
- Inheritance1:14
- Subclass1:56
- Superclass2:07
- Inheritance3:08
- Example3:36
- Inheritance4:44
- Subclass Does Not Inherit…6:05
- Inheritance7:06
- To Override a Method7:17
- Inheritance8:59
- Example10:24
- Class Hierarchies11:31
- Multiple Level Hierarchies for Subclass12:41
- Abstract Classes14:35
- Example15:59
- Polymorphism20:19
- Example20:34
- Interfaces22:33
- Interfaces Example25:13
- Defines 3 Methods25:27
- Summary29:26

Lists

33m 15s

- Intro0:00
- Roadmap0:16
- Lists0:52
- Wrapper Classes1:10
- The List Interface2:37
- Cannot Instantiate a List3:26
- The ArrayList Class5:01
- The Way It Works7:45
- The ArrayList Class8:34
- Primary Methods Needed To Use for ArraryList8:53
- Code Examples16:26
- The LinkedList Class21:01
- To Instantiate a LinkedList…21:59
- Code Example24:05
- ArrayList vs. LinkedList25:25
- Internal Storage Implementation of ArrayList25:35
- Internal Storage Implementation of LinkedList26:01
- Pros/Cons of Each26:23
- Summary32:10

Numeric Wrapper Classes & Mathematical Functions

23m 14s

- Intro0:00
- Roadmap0:11
- Numeric Wrapper Classes0:42
- To Get Around Storing Limitation1:19
- Setting and Getting Values2:30
- Double Class3:57
- Comparing Values5:07
- Equals Method5:22
- Comparing Values7:16
- CompareTo Method: Integer Class7:29
- CompareTo Method: Double Class9:24
- Minimum and Maximum Values10:28
- Integer Class: Publib Static Final10:56
- Double Class12:19
- Automatic Conversion12:53
- Autoboxing13:12
- Example13:36
- Get Method14:52
- The Math Class15:59
- Math.E16:18
- Math.PI16:25
- Example16:34
- The Math Class17:07
- Working With Random Numbers18:42
- Example19:47
- Summary22:14

Algorithms: Iteration

25m 43s

- Intro0:00
- Roadmap0:13
- Iteration0:36
- Iteration Defined0:39
- For Loop / While Loop0:50
- Example1:11
- Iteration3:11
- Two-Dimensional Range3:19
- Using Two Nested While Loops5:00
- Finding Minimum and Maximum Values5:54
- Finding Minimum and Maximum Values Examples7:50
- Finding Minimum and Maximum Values Example12:52
- Inserting in Order15:19
- Inserting in Order Code17:42
- Loop Invariants21:53
- Example23:17
- Summary24:37

Algorithms: Recursion

27m 30s

- Intro0:00
- Roadmap0:09
- Recursion0:44
- Calculating Factorials2:49
- n! and How It's Defined3:01
- Recursive Implementation of the Factorial Function in Java3:34
- Calculating Factorials4:34
- Calculate 4!4:35
- Factorial Function in Java7:22
- Calculating Fibonacci Numbers9:19
- Fibonacci Numbers Defined9:30
- Recursive Implementation10:33
- Implementation in Java10:44
- Calculating Fibonacci Numbers11:28
- Calculate Fibonacci(4)11:29
- Fibonacci in Java14:59
- Other Recursive Functions17:35
- Other Recursive Functions21:32
- Calculate Mystery(4)21:33
- Mystery in Java22:29
- Important Considerations23:49
- Recursive Methods25:15
- Summary26:41

Algorithms: Sorting

29m 42s

- Intro0:00
- Roadmap0:08
- Sorting0:55
- Definition of Sorting1:05
- Cant Sort Any of the Following1:14
- Selection Sort3:49
- Definition of Selection Sort3:58
- 'Search-and-Swap' Algorithm5:05
- Selection Sort Example7:46
- Insertion Sort10:57
- Insertion Sort Example13:02
- Merge Sort15:14
- Recursive Sorting Algorithm16:15
- Merge Sort Example18:03
- Quick Sort20:34
- Recursive Sorting Algorithm21:36
- Quick Sort Example23:35
- Summary27:19

Algorithms: Searching

32m 37s

- Intro0:00
- Roadmap0:08
- Searching0:40
- Sequential Search2:22
- Performed on Any Array2:29
- Sequential Search Algorithm Using a For Loop4:24
- Java Example6:28
- Binary Search8:51
- Binary Search Algorithm Using a While Loop12:03
- Java Example16:59
- Binary Search20:38
- Recursive Method20:53
- Java Example: Using Binary Search25:34
- Search Considerations28:16
- Binary Search29:14
- Summary31:14

Program Design & Development

29m 29s

- Intro0:00
- Roadmap0:41
- Object-Oriented Programming1:20
- Definition1:35
- Encapsulation2:26
- Polymorphism4:43
- Top-Down Design and Development5:56
- Top-Down Design6:10
- Top-Down Development6:51
- Reusable Code8:47
- Definition8:58
- Example to Reusable Code10:33
- Team Development11:36
- Team Development15:03
- Adding Another Developer15:23
- Data Structure19:28
- Definition19:35
- Examples19:44
- User Interface20:53
- Definition21:00
- Specifications24:19
- Definition24:29
- 2 Important Purposes for Specifications25:25
- Summary27:27

Standard Classes & Interfaces

32m 53s

- Intro0:00
- Roadmap0:13
- Object1:46
- Methods1:57
- Equals Method2:06
- toString Method2:16
- What Else To Know2:28
- Integer3:19
- Constructor3:32
- Methods3:51
- Constants4:28
- What Else To Know5:05
- Double6:14
- Constructor6:35
- Methods6:50
- What Else To Know7:06
- String8:16
- Methods8:40
- What Else To Know12:10
- Math15:24
- Methods15:36
- What Else To Know18:13
- List20:02
- Methods20:30
- ArrayList22:45
- What Else To Know23:27
- Test-Taking Tips26:05
- Summary29:47

Section 2: AP Test Preparation

Multiple Choice Question Tips & Practice

55m 47s

- Intro0:00
- Roadmap0:23
- AP Computer Science Exam Structure1:32
- Two Sections1:40
- Contribution to Score3:35
- Multiple Choice Strategies and Tips4:50
- Example Question 19:07
- Example Question 213:34
- Example Question 316:12
- Example Question 421:44
- Example Question 526:41
- Example Question 634:12
- Example Question 739:41
- Example Question 842:09
- Example Question 946:31
- Example Question 1050:35
- Summary54:49

Free Response Question Tips & Practice

40m 55s

- Intro0:00
- Roadmap0:27
- AP Computer Science Exam Structure1:15
- Two Sections1:20
- Contribution to Score2:09
- Free Response Strategies and Tips3:23
- Free Response Strategies and Tips Continued6:17
- Free Response Strategies and Tips Continued10:22
- Free Response Strategies and Tips Continued13:00
- Free Response Strategies and Tips Continued15:42
- Example Free Response Question17:41
- Example Free Response Question Narrative Continued18:30
- Example for Problem19:29
- Example Set-Up for Problem19:56
- Example Set-Up for Problem Continued21:48
- Code24:14
- Code Continued: First Method25:36
- Second Method26:28
- Additional Narrative27:04
- Definition of Part A: What They Want You to Write27:33
- Definition of Part B: What They Want You to Write28:50
- Requirements for Part A31:06
- Part A: One Possible Solution31:49
- Requirements for Part B34:06
- Part B: One Possible Solution34:48
- Summary39:52

The GridWorld Study

54m 18s

- Intro0:00
- Roadmap0:19
- Overview of GridWorld0:51
- Definition of GridWorld1:00
- Important part of AP Exam3:14
- Need to Understand It5:16
- Overview of GridWorld: Testable APIs8:00
- API Defined8:06
- Testable APIs8:52
- Testable Code9:22
- 4 Classes9:57
- Location Class10:21
- Location Class: 8 Public Constants That Help with Direction11:36
- Row Numbering12:32
- Column Numbering13:13
- Location Class: 7 Public Constants That Represent Turns13:31
- Location Class: Methods Useful in Navigating Through the Grid15:25
- getAdjacentLocation15:34
- getDirectionToward16:21
- Location Class: 3 Other Useful Methods16:58
- Equals Method17:05
- CompareTo Method17:35
- ToString Method18:16
- Grid Interface18:41
- Represents18:50
- Grid Interface: Useful Methods20:34
- getNumRows Method20:42
- getNumCols Method20:52
- isValid Method21:00
- Grid Interface: Useful Methods22:16
- Put Method22:23
- Remove Method22:13
- Get Method23:26
- Grid Interface: Useful Methods23:44
- GetOccupiedLocations Method23:55
- GetValidAdjacentLocations Method24:21
- GetEmptyAdjacentLocations Method25:02
- GetOccupiedAdjacentLocations Method25:24
- Grid Interface: Useful Methods25:37
- GetNeighbors Method25:44
- Actor Class26:27
- Constuctor: Actor27:02
- GetColor Method27:31
- SetColor Method27:38
- GetDirectionToward Method27:46
- SetDirection Method28:09
- GetGrid Method28:27
- GetLocation Method28:40
- PutSelfInGrid and RemoveSelfFromGrid Method28:51
- MoveTo Method30:03
- Act Method30:17
- ToString Method31:24
- Rock Class31:46
- 3 Methods31:58
- Flower Class32:35
- 3 Methods32:51
- Bug Class33:53
- Includes These Methods34:34
- How the Move Method Works36:38
- CanMove Method38:53
- BoxBug Class40:49
- Behavior41:00
- 2 Private Variables41:20
- Constructor for BoxBug41:55
- BoxBug Class Methods42:16
- Critter Class43:41
- How It Works44:03
- Next Step45:38
- 3rd Step47:01
- Last Step in Act Method48:33
- ChameleonCritter Class49:00
- Redefines Some Characteristics of Critter Class49:26
- Another Difference51:02
- Summary52:25

Multiple Choice Questions About GridWorld

41m

- Intro0:00
- Roadmap0:16
- Multiple Choice Strategies and Tips0:45
- Structure0:49
- Points Worth1:47
- Some Strategies and Tips3:29
- No Penalty for Wrong Answer6:10
- Some Strategies and Tips Specifically on GridWorld Questions6:29
- Some Strategies and Tips Specifically on GridWorld Questions9:37
- GridWorld Testable APIs and Code13:17
- Testable APIs13:25
- Testable Code13:47
- Example Question 114:32
- Example Question 217:11
- Example Question 322:53
- Example Question 426:17
- Example Question 534:11
- Summary39:47

Free Response Questions About GridWorld

39m 31s

- Intro0:00
- Roadmap0:14
- Free Response Strategies and Tips0:49
- Format0:56
- Points1:18
- Quick Reference Guide1:49
- Not Required to Do in Order2:48
- Multiple Parts3:33
- All Answers Must Be Written in Java5:00
- Partially Correct Solutions Can Be Awarded Partial Credit7:49
- Write Neatly10:40
- Don't Waste Time12:52
- GridWorld Testable APIs and Code14:55
- Testable APIs15:05
- Testable Code15:53
- GridWorld Testable APIs and Code16:37
- GridWorld Free Response Question16:41
- Example17:34
- Example Free Response Question18:23
- Question18:54
- Visual Diagram of the Game Board20:00
- Visual Chart21:08
- Narration Continues21:56
- The Piece Class22:59
- Narration Continues23:59
- What You Will Need to Do24:28
- The Rest of the Definition for DropGame25:08
- Part A: Requirements25:55
- Part B: Requirements28:44
- Part A: Question (Again)31:54
- Part A: One Possible Solution32:19
- Part B: Question (Again)35:30
- Part B: One Possible Solution35:47
- Summary38:34

Final Tips for Taking the Exam

27m 38s

- Intro0:00
- Roadmap0:10
- AP Computer Science Exam Structure0:46
- Two Sections0:49
- Scoring1:24
- Multiple Choice Strategies and Tips2:15
- Answer Questions for Descriptive Paragraph First2:38
- No Penalty for Wrong Answer3:42
- Free Response Strategies and Tips4:00
- Each Part Graded Separately4:57
- All Answers Written in Java5:54
- Partially Correct Solutions8:32
- Write Neatly10:33
- Draw a Single Line Through Mess-Ups13:09
- Additional Resources14:49
- Download the Project Files for GridWorld15:20
- Download Reference Documents15:39
- Remember, You Can Watch This Lesson More Than Once15:54
- What to Bring to Your Exam16:19
- What Not to Bring to Your Exam18:47
- The Night Before Your Exam22:00
- The Day of Your Exam24:23
- Summary26:44

Glossary of Terms to Know

36m 31s

- Intro0:00
- Roadmap0:16
- Abstract Class1:28
- Array2:29
- Casting3:43
- Class4:39
- Conditional Statement5:35
- Constructor6:28
- Escape Sequence7:18
- Exception8:24
- Final Variable8:59
- Inheritance10:19
- Instance11:36
- Interface12:33
- Iteration13:08
- List14:05
- Logical Operator15:11
- Loop16:20
- Loop Invariant17:06
- Method17:30
- Numeric Wrapper Class18:55
- Overloading20:38
- Polymorphism21:10
- Primitive Data Type23:22
- Public and Private24:06
- Random25:03
- Recursion27:07
- Return Type28:08
- Searching28:59
- Signature30:14
- Sorting30:51
- Static32:40
- String33:37
- Subclass and Superclass34:30
- Glossary35:37

Loading...

This is a quick preview of the lesson. For full access, please Log In or Sign up.

For more information, please see full course syllabus of Introduction to Java

For more information, please see full course syllabus of Introduction to Java

Next Lecture

Previous Lecture

0 answers

Post by Fancong Mo on May 6, 2016

Hi, would you mind solve the following question for me?

Prove the following propositions:

Suppose a, b, c ? Z. If a2+b2=c2, then a or b is even.

The product of any five consecutive integers is divisible by 120.

1 answer

Last reply by: Professor Quayle

Sat Mar 21, 2015 10:20 PM

Post by Jimmy Jones on March 21, 2015

I believe te grid world case study is not going to be used anymore? Will there be an alternative in the ap comp science 2015 test?

1 answer

Last reply by: Professor Quayle

Wed Jul 10, 2013 12:39 PM

Post by Darius Smith on July 8, 2013

AP stands for Assoc. Programmer?

3 answers

Last reply by: Professor Quayle

Fri Mar 29, 2013 2:01 AM

Post by Alex Moon on March 25, 2013

Hello, during my practice with free response questions, I had aa few questions myself.

This assignment asks me to create AttractingCritter class, where I have to mudify among other things,

getActors (). Basically, I had to get a list of all actors on the grid and return it.

CORRECT RESPONSE

public ArrayList <Actor> getActors()

{

ArrayList<Location> occupiedLocs = getGrid().getOccupiedLocations();

ArrayList<Actor> a = new ArrayList <Actor> ;

for ( Location i: occupiedLocs)

a.add(getGrid().get(i));

return a;

}

MY RESPONSE

public ArrayList <Actor> getActors()

{

ArrayList<Location> occupiedLocs = new ArrayList();

ArrayList<Actors> a = new ArrayList <Actor>;

occupiedLocs = getGrid().getOccupiedLocations()

for(i=0 ; i<occupiedLocs.size(); i++)

a.set(i,get(occupiedLocs.get(i)));

return actors;

}

As you can see, the main difference is the fact that I used "a.set(i,get(occupiedLocs.get(i)))",

setting each of the slots for ArrayList a with however many actors there are in the ArrayList occupiedLocs,

while collegeboard used "a.add(getGrid().get(i)), simply adding additional actors into ArrayList a.

Question 1: since ArrayList a has just been created, would it be illegal to use set(index)? Or is there always one

empty slot after the last array, that would let me keep extending the array using iteration of the set method?

---Gernerally speaking----

Question 2: Is it not necessary to write "new ArrayList<Location>()" when instantiating new ArrayLists, as long as

the values of the ArrayList is ddecided upon instantiation?

Question 3:

Apparently, checking just "getloc) == null" does not work. It must be "getGrid().get(loc).

Is getGrid() method necessary whenever I refer to Locations or objects?

When is getGrid() required, and when is it not?

Question 4: What is the function of "this"? If there is no specified object preceding a method that is called,

does it function just as if it had "this." in front of it? (example: this.getLocation())

--------------------------------------------------------------------------------------

Sometimes, collegeboard asks me to trim any zeros in the array before nonzero numbers start (regardless of zeros later on,

In 0,0,0,4,9,0,2 only trim first 3 zeros)

The answers display usage of the while loop to count the zeros untill a nonzero number comes in ,

falsifying the samples[I] == 0 statement, allowing the program to move on.

I used a for loop to iterate through the array, and used if statement to increment a variable for every zero and used else

statement to move on to the rest of the method, and ending it with a return statemnt to prevent rechecking for zeros.

for( i =0 ; samples.length; i++)

{

if (samples[i]== 0)

count++

else

{

for (j=0; samples.length-k;j++)

{...}

return;

}

}

Question 5: Is the while loop the only way to end loops, for the purpose of extracting information collected through

the loop to be used within the method, without ending the entire method(such as with a return statement)? If not, is my

process going to work in the same manner?

For this problem, I very much wanted to create another method just to return the number of starting zeros, but of course,

the question only asks to implement one method.

----------------- General ----------------

6: Does an empty string contain " "? I thought it would contain null. Does null mean that something is empty, such as

the contents of ArrayLists , arrays, and strings? What is the difference between "empty" and "null"

in thse cases? When would something be considered null?

Im glad that I have such a dedicated instructor as a teacher. Thank you for your prompt responses!

3 answers

Last reply by: Professor Quayle

Wed Mar 27, 2013 4:46 PM

Post by Alex Moon on March 19, 2013

Thanks for the informative lectures! I just have a couple questions.

This is in Critter Class

processActors(ArrayList <Actor> actors)

{for(Actor a: actors)

{ if (!(a instance of Rock) &&! (a instance of Critter))}

}

1. What in the world is "a instance of Rock"? I have never seen this expression, and it seems strange to be in a form without periods. Is it a boolean method asking " Is object "a" a Rock?"? Is it differnet from ==?

2. It is advised that one use "removeSelfFromGrid()" instead of "put()" or "remove()" methods. I understand that the "put()" or "remove()" does not tell the object itself what is going on, but then, what is the purpose of "put" and "remove" if you cannot use them in this case?How are they used?

In my Barron's Review book, it mentions this case

public class ClassOne

{...

methodOne()

}

public class ClassTwo extends ClassOne

{...

methodTwo()

}

ClassOne c2 = new ClassTwo()

3. What is the effect of casting c2 to ClassOne and using the ClassTwo constructor? In short, what is purpose/effect of casting to one class and using constructor of its subclass?

......

4. What is the difference between List<E> and ArrayList<E>?

......

For Free Response

The free response section makes students define various classes and methods.

5. Is it all right to initiate most variables for methods like "number", "n", "temp" to private variables? (Even if you don't need to)

6. What would be a convenient way to tell if a variable I need to instantiate in the FRQ would be instance variables or should be public, or nothing at all in terms of access level?

Some questions require the implementation of a constructor of a subclass.It turns out that the subclass constructor acts differently from the superclass constructors some times and act same in other times.

7. Do I get penalized if I don't mention "super()" and just rewrite the superclass constructor as part of the subclass constructor, if it did not specifically ask to use super()?

likewise, do I get penalized if I don't use super.processActors and instead rewrite the code for the superclass processActors in the subclass?

8. What is the effect of having a "return" statement at the end of a program when it does not need one? Is it illegal to use "return" in void methods?

Thank you so much. Test date is closing in, and I am in much need of your wisdom!