Assignment 4. Aggregate Objects, Command-Line Arguments, ArrayLists. COMP-202B, Winter 2011, All Sections. Due: Tuesday, March 22, 2011 (13:00)

Similar documents
Assignment 5: Part 1 (COMPLETE) Sprites on a Plane

ASSIGNMENT 4 Classes and Objects

Programming Project: Game of Life

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination

CS 134 Programming Exercise 9:

ASSIGNMENT 5 Data Structures, Files, Exceptions, and To-Do Lists

UNIT 9C Randomness in Computation: Cellular Automata Principles of Computing, Carnegie Mellon University

Programming Exercise

ASSIGNMENT 6. COMP-202, Winter 2015, All Sections. Due: Tuesday, April 14, 2015 (23:59)

ASSIGNMENT 5. COMP-202, Winter 2015, All Sections. Due: Tuesday, March 31st, 2015 (23:59)

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

ASSIGNMENT 4. COMP-202C, Summer Due: Monday June 29th, 2015 (23:30)

Lecture 3. Lecture

ASSIGNMENT 5 Objects, Files, and a Music Player

CS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class

ASSIGNMENT 5 Objects, Files, and More Garage Management

Introduction to Programming Using Java (98-388)

CIT 590 Homework 10 Battleship

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

ASSIGNMENT 3. COMP-202, Winter 2015, All Sections. Due: Tuesday, February 24, 2015 (23:59)

University of California San Diego Department of Electrical and Computer Engineering. ECE 15 Final Exam

CSE 142, Autumn 2018 Programming Assignment #9: Critters (20 points) Due Tuesday, December 4th, 9:00 PM

CS112 Lecture: Working with Numbers

News and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.!

MORE ARRAYS: THE GAME OF LIFE CITS1001

CS108, Stanford Handout #3. HW1 CodeCamp

ASSIGNMENT 4. COMP-202, Fall 2014, All Sections. Due: November 9 th, 2014 (23:59)

ASSIGNMENT 2. COMP-202A, Fall 2013, All Sections. Due: October 20 th, 2013 (23:59)

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

CPSC 217 Assignment 3

CS61BL: Data Structures & Programming Methodology Summer Project 1: Dots!

CSCI-1200 Data Structures Fall 2017 Lecture 13 Problem Solving Techniques

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

//If target was found, then //found == true and a[index] == target.

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

ISY00245 Principles of Programming. Module 7

Remaining Enhanced Labs

We have written lots of code so far It has all been inside of the main() method What about a big program? The main() method is going to get really

CSci 1113, Fall 2015 Lab Exercise 11 (Week 13): Discrete Event Simulation. Warm-up. Stretch

Class 15. Object-Oriented Development from Structs to Classes. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

CS201 - Assignment 7 Due: Wednesday April 16, at the beginning of class

CS 2510 Exam 3 SOLUTION Spring 2011

Conway s Game of Life Wang An Aloysius & Koh Shang Hui

Lesson 6A Loops. By John B. Owen All rights reserved 2011, revised 2014

COMP : Practical 8 ActionScript II: The If statement and Variables

Assignment 4: Dodo gets smarter

APCS Semester #1 Final Exam Practice Problems

9/19/2018 Programming Data Structures. Polymorphism And Abstract

CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists

Computer. CSE 373 Summer 2017 Due 5:00pm on Friday, July 14th

Chapter 4 Defining Classes I

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Assignment 5. INF109 Dataprogrammering for naturvitskap

Assignment3 CS206 Intro to Data Structures Fall Part 1 (50 pts) due: October 13, :59pm Part 2 (150 pts) due: October 20, :59pm

CMPSCI 187 / Spring 2015 Hangman

CSE 142 Sp02 Final Exam Version A Page 1 of 14

Solutions to Quiz 1 (March 14, 2016)

Instructions for Crossword Assignment CS130

Critters. Critter #2 Attack.ROAR Attack.POUNCE Attack.SCRATCH. Critter #1

CS 142 Style Guide Grading and Details

CMSC 202H. Classes and Objects: Reusing Classes with Composition

CS 2110 Summer 2011: Assignment 2 Boggle

Use lists. Use loops. Use conditionals. Define and use functions. Create and use code modules

2D Arrays. Lecture 25

Quiz 1 (March 14, 2016)

Chapter 6 Introduction to Defining Classes

Deliverables. Problem Description

Inheritance and Interfaces

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Carleton University COMP1406/1006, Summer 2013 Tutorial 2

CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance

Defining Your Own Classes

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

Critter #1 Attack.ROAR random winner #2 wins #1 wins Attack.POUNCE #1 wins random winner #2 wins Attack.SCRATCH #2 wins #1 wins random winner

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

An Introduction to C++

Lecture 19: Signatures, Structures, and Type Abstraction

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

CS 106A, Lecture 27 Final Exam Review 1

CS 2210a Data Structures and Algorithms Assignment 5 Solving a Labyrinth Due Date: December 6, 11:59 pm Total marks: 20

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018

1 Getting started with Processing

Variables One More (but not the last) Time with feeling

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

Making use of other Applications

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Course Outline. Introduction to java

Enums. In this article from my free Java 8 course, I will talk about the enum. Enums are constant values that can never be changed.

Object Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

CPSC 233: Assignment 4 (Due March 26 at 4 PM)

ASSIGNMENT 2 Conditionals, Loops, Utility Bills, and Calculators

Extensibility Patterns: Extension Access

Project 3: Implementing a List Map

Transcription:

Assignment 4 Aggregate Objects, Command-Line Arguments, ArrayLists COMP-202B, Winter 2011, All Sections Due: Tuesday, March 22, 2011 (13:00) You MUST do this assignment individually and, unless otherwise specified, you MUST follow all the general instructions and regulations for assignments. For example, all the methods asked for in this specification should be public, and any helper methods you define should be private. Graders have the discretion to deduct up to 10% of the value of this assignment for deviations from the general instructions and regulations. Part 1: Part 2, Question 1: Part 2, Question 2: Part 2, Question 3: 0 points 64 points 20 points 16 points 100 points total We recommend that you compile and run the code for this assignment in the command-prompt/terminal rather than through Eclipse. You can still use the Eclipse editor if you want, but run your code in the terminal. Running the code through Eclipse is of course possible, but you might find it inconvenient. Part 1 (0 points): Warm-up. Contains Essential Information. Warm-up Question 1 (0 points) Write a class called CommandTest that contains one main() method. This program should assume that all the command-line arguments given by the user are numbers, and it should add those numbers together and display the result. If no command-line arguments are given, display 0. You will have to use the parseint() method from the Integer class (which is part of the Java Standard Class Library) to convert the command-line arguments to integers. Example run: $java CommandTest 0 $java CommandTest 1 2 3 6 Write another class called StringCommandTest that contains one main() method. If no commandline arguments are given, display an angry message to the screen and terminate the program with System.exit(0). This part of your code will look something like: if(no arguments){ System.out.println("Raaaaa!"); System.exit(0); } 1

Google can tell you what System.exit(0) does, if you re interested. After this, your program should copy each of the given command-line arguments into an ArrayList of String and check whether the ArrayList contains the String elmo : if so print yes, otherwise print no. (Hint: use the contains() method from the ArrayList class.) Finally, without using the previously defined ArrayList, count how many of the command-line arguments are equal, in a case-insensitive manner, to the String elmo. The String class has an instance method that will check String equality in a case-insensitive manner. Example run: $java StringCommandTest Raaaa! $java StringCommandTest 1 2 3 Elmo no 1 $java StringCommandTest Elmo 5 elmo bigbird ELMO bert ernie 10 yes 3 $java StringCommandTest ernie no 0 Warm-up Question 2 (0 points) Write a class called Point; each object which belongs to this class represents a point in two-dimensional space. Each point can be specified uniquely by two real numbers: its x-coordinate and its y-coordinate. Your Point class should provide the following public INSTANCE methods: A constructor, which takes as parameters two values of type double; these values represent the x and y coordinates of the newly-created Point, in this order. An accessor method called getx(), which takes no parameters, and returns a value of type double that represents the x-coordinate of the target Point. An accessor method called gety(), which takes no parameters, and returns a value of type double that represents the y-coordinate of the target Point. A method called computedistance(), which takes as parameter a Point object, and returns a value of type double. This method computes the distance between the target Point and the parameter Point, and returns this distance. The distance d between two points p 1 and p 2 in two-dimensional space is given by the following equation: d = (x 2 x 1 ) 2 + (y 2 y 1 ) 2 In the above equation, x 1 and y 1 respectively represent the x and y coordinates of point p 1, while x 2 and y 2 respectively represent the x and y coordinates of point p 2. You MAY assume that the parameter Point is not a null reference. A method called equals(), which takes as parameter a Point, and returns a value of type boolean. This method returns true if the parameter Point represents the same point in two-dimensional space as the target Point, false otherwise. Two points are the same if and only if their x- coordinates are equal and their y-coordinates are equal. Two coordinates should be considered equal if the absolute value of their difference is less than 10 10. If the parameter Point is a null reference, then this method MUST return false. A method called tostring(), which takes no parameters and returns a String which is a textual representation of the target Point. This text representation should have the following format: (x, y) where x and y are replaced by the actual x and y coordinates of the target Point. Note that Point objects are immutable, meaning that the state of a Point object MUST NOT change once the object is created. This implies that, other than the constructor, the methods of the Point class MUST NOT change the state of the target Point, and no method or constructor should ever change the state of any parameter Point; it might be useful to declare the attributes of a Point object as final to achieve this goal. Page 2

Also note that you MUST respect proper encapsulation practices; that is, the attributes and methods of your class MUST be declared using the proper visibility modifiers. Once you have completed your Point class, test it by writing a class called ComputeDistance, which defines only a main() method that does the following: Uses command-line arguments to read the x and y coordinates of two points p 1 and p 2 from the keyboard and create Points from these values. For example, java ComputeDistance 4 5 1-1 should create a Point with coordinates 4 and 5, and a Point with coordinates 1 and -1. Display both Points in the following format: (x, y) Compute the distance between the two Points, and display it. Sample session: $java ComputeDistance 0 0 3 4 p1 == (0.0, 0.0) p2 == (3.0, 4.0) The distance between p1 and p2 is: 5.0 Part 2 The questions in this part of the assignment will be graded. The questions in this section must be completed in order. You cannot start Question N before having correctly completed and tested Question N 1, where 2 <= N <= 3. Overview Your goal for Assignment 4 is to gradually implement a finite version of Conway s Game of Life. Before proceeding, please skim the Wikipedia article on this topic: https://secure.wikimedia.org/wikipedia/ en/wiki/conway\%27s_game_of_life Wikipedia says: From a theoretical point of view, [the Game] is interesting because it has the power of a universal Turing machine: that is, anything that can be computed algorithmically can be computed within Conway s Game of Life. (... ) [The Game] is interesting for computer scientists, physicists, biologists, economists, mathematicians, philosophers, generative scientists and others to observe the way that complex patterns can emerge from the implementation of very simple rules. If you want to see a demonstration of Conway s Game of Life, check out http://www.youtube.com/watch?v=xcubvj0pw-e and http://www.bitstorm.org/gameoflife/. The questions in this assignment correspond to phases of program development: first, we implement a minimal prototype that does almost nothing, then we gradually add on and test additional program features. Within each question, you should use your judgement to break down the implementation process further into small phases: compile and test often; write comments as you write code (not after!), and gradually build up your code to the final goal. You should read this entire document before starting to plan or implement your ideas. Note that your final assignment submission MUST include a plain-text file called readme.txt in which you clearly list which parts of the assignment you did and did not complete, as well as what kinds of problems you encountered and could not solve. Page 3

Question 1: Phase 1 Game of Doing Nothing Learning Objectives: Implementing simple aggregate classes. Using aggregate objects. Iterating over 2D arrays. Manipulating Strings. Using static variables in a library class. (64 points) In this question you will implement part of the Environment and Cell classes. You will also write a class that serves as the starting point of your program, GameOfLife, and add a method to the already existing file called Patterns.java. Don t feel like you have to completely finish Cell, for example, before you start Environment or GameOfLife. Ideally, you should be implementing and testing small parts of all the classes bit by bit, depending on how the classes fit together. Cell A Cell has a status (alive or dead, i.e. coordinates within its home. true or false), a home (of type Environment) and integer Good idea: add two static constants to the Cell class and use them in all the other classes: ALIVE = true and DEAD = false. That way, your program will be easier to understand and you won t risk making a silly mistake like using true instead of false to mean dead. The Cell class has one constructor and a bunch of instance methods. The Cell constructor initializes all the attributes of this Cell with the values of its four parameters: a boolean status, an Environment, a vertical coordinate, a horizontal coordinate. The coordinates are integers. The method isalive() accepts no parameters and returns a boolean indicating the status of this Cell. The method setstatus() accepts a boolean parameter and updates the status of this Cell accordingly. The method tostring() accepts no parameters and returns a String representation of this Cell. If the Cell is alive, it s represented with the letter o, otherwise it s represented with a period. Environment An Environment contains a population of Cell objects and governs whether they live or die. A population of Cell objects is a 2D grid in which each Cell occupies exactly one square. Once an Environment is initialized with a population grid, the size of the grid does NOT change. The Environment class has the following instance methods. The Environment constructor accepts two parameters, an integer height and width, and uses these parameters to initialize a population of Cell objects that are all dead. The getcell() method accepts two parameters, a vertical coordinate and a horizontal coordinate (integers), and returns the Cell that resides at those coordinates in the population grid. The iswithinboundsv() accepts an integer and returns true if the integer is a valid vertical coordinate in the population grid of this Environment. The iswithinboundsh() accepts an integer and returns true if the integer is a valid horizontal coordinate in the population grid of this Environment. Page 4

The tostring() method accepts no parameters and returns one String that represents the current state of the population of this Environment. This method has no side-effects. Example: if you call the tostring() method on an Environment e whose population grid is 5 cells tall and 20 cells wide with only one live cell at vertical coordinate 0 and horizontal coordinate 1, you will see the following if you were to print the result via System.out.print(e.toString()):.o... Patterns The Patterns class is partially defined in the file Patterns.java, available on the course website. So far it contains several public static constants that represent Game-of-Life patterns as 2D integer arrays. You will complete the Patterns class by adding the following static method to it. The makepattern() method accepts an Environment, two integers (vertical and horizontal coordinates, respectively), and a 2D integer array that represents a pattern. It updates the given Environment to contain the given pattern of live Cell objects at the given coordinates. The given coordinates correspond to the location of the top-left corner of the pattern in the Environment. If the given Environment is already filled with other patterns of live Cell objects, makepattern() simply overwrites the existing Cell configuration. If the given coordinates are invalid for the given Environment, makepattern() returns false. Otherwise, once a pattern is successfully added to the given Environment, makepattern() returns true. For example, if someenvironment is an Environment that only contains dead Cell objects and whose population grid is 5 cells tall and 20 cells wide, the call makepattern(someenvironment, 1, 2, TOAD) will result in someenvironment.tostring() looking like this:...ooo.....ooo... GameOfLife This class is the starting point of your program. For now, this class will contain a main() method, as well as a method for displaying an Environment to the screen. The class should declare a private static variable, called world, of type Environment and initialized to null. This variable will be visible to all methods in the class, which will be useful in Questions 2 and 3. Write a method called displayworld() that takes in two integers: steps and speed. Your method should just print the current state of world. It will contain one line of code that doesn t use the input parameters at all. In Questions 2 and 3, you will extend this method to perform a more complex task. Write a main() method that initializes the world variable to point to an Environment whose population grid has height 24 and width 80. It should then use the makepattern() method to add one or more patterns to world. (Play around with this part however you like.) Finally, it should call the displayworld() method to display the initial state of world to the screen. Page 5

Question 2: Phase 2 A Working Game of Life Learning Objectives: (20 points) Implementing complex operations within aggregate classes. Using this and null. Understanding the difference between a deep copy and a shallow copy of an aggregate object. Parsing command-line arguments. Iterating over 2D arrays. Overloading constructors; using overloaded constructors. Do not attempt this part of the assignment until you have successfully completed Question 1. In this question you will extend and change the classes you defined in Question 1 to implement the rules that define Conway s Game of Life. Your program will use command-line arguments to determine the initial state of the game and to display the evolution of the game to the screen. This is the really fun part. :) Unfortunately, I think it s also the hardest part. :( Remember: you should be implementing and testing small parts of all the classes bit by bit, depending on how the classes fit together. Cell Add a method called getnumliveneighbours() to the Cell class. This method returns an integer that represents the number of live neighbours around this Cell. For example, in the illustration below, the Cell specially marked with an x has 4 live neighbours, the Cell marked with a z has 1 live neighbour and the Cell marked with a z has 1 live neighbour. The Cell marked with a w has no live neighbours....o...xoo...y..ooo.z......w... Add a method called getcellcopy() to the Cell class. This method accepts an Environment e as a parameter and returns a new Cell with the same attributes as this Cell, except that its home attribute is set to e. This method will play an essential role in the algorithm used for updating the state of an Environment according to the rules of the Game of Life. Environment Add a second constructor to the Environment class. This constructor should accept c, a 2D array of Cell objects, as input and assign a copy of c to the population attribute of this Environment. Add a private instance method to Environment and call it updatecellstatus(). This is where you will implement the rules of the Game of Life. The updatecellstatus() method returns nothing and accepts a vertical coordinate, a horizontal coordinate, and a 2D array of Cell objects. It then updates the status of the Cell that appears at the given coordinates in the given array according to the following rules (taken almost directly from the above-mentioned Wikipedia article): Any live cell with fewer than two live neighbours in the most recent environment state dies, as if caused by under-population. Any live cell with two or three live neighbours in the most recent environment state lives on to the next generation. Any live cell with more than three live neighbours in the most recent environment state dies, as if by overcrowding. Any dead cell with exactly three live neighbours in the most recent environment state becomes a live cell, as if by reproduction. Page 6

The most recent environment state can be thought of as the state of the current generation of cells. The updatecellstatus() method is computing the state of the next generation based on the state of the current generation. Add an instance method to Environment and call it updatepopulation(). This method returns nothing and has no input parameters. It first saves a copy of this Environment in a local variable named snapshot and then updates the status of each Cell in this Environment with the help of the snapshot. Hint: If you suspect that your implementation is not updating Cell status correctly, try temporarily changing the tostring() method of the Cell class to represent a Cell as its number of live neighbours instead of a. or an o. When you display your Environment to the screen with this version of the tostring() method, do the numbers make sense? GameOfLife Recall that your original displayworld() method accepted two parameters but never used them. Now, you will use them. The first parameter represents a number of steps x, and the second parameter represents the number of times y to display each step. Change your previously defined displayworld() method so that it successively prints the first x states of the Environment saved in world, repeating each state y times. Have it print an empty line in between each displayed state. Now you need to your program to process command-line arguments from the user. Here s an example of how your program should run: java GameOfLife blinker 0 0 sparky 5 40 GLIDER 10 10 100 2 The above line means that the user wants to create an Environment whose initial state is created by adding a blinker at coordinates 0 0, then adding a sparky at vertical coordinate 5 and horizontal coordinate 40, then adding a glider at coordinates 10 10. The user then wants your program to display the first 100 states of Environment evolution (including the initial state), printing each state twice in a row. Printing a state many times in a row makes the animation seem slower, so the last command-line argument corresponds to speed. You will now add static methods to analyze and respond to the user s command-line arguments. Add a method called printusage() to the GameOfLife class. This message doesn t return anything; it just prints the following message: Usage: java GameOfLife [pattern1] [vcoord1] [hcoord1]... [patternn] [vcoordn] [hcoordn] [steps/history] [speed/direction] Throughout your program, you do not have to check that the user s command-line arguments satisfy the format shown in the example above, unless otherwise stated. Add a method called parsepatterns() to the GameOfLife class. This method accepts three Strings as parameters: the first String represents the name of a pattern from the Patterns class; the second String represents a vertical coordinate; the third one represents a horizontal coordinate. Use the parseint() method from the Integer class to convert the second and third parameters to integers. If the first String matches (in a case-insensitive fashion) the name of a pattern declared as a constant in the Patterns class, add that pattern to the Environment stored in world and return true. If it doesn t match any pattern names in Patterns, return false. Update the main() method as follows. If no command-line arguments are supplied by the user, display a message about how to properly use your program (see printusage() above) and terminate the program with System.exit(0). Otherwise, initialize world to height 24 and width 80. Then loop through the first 3n arguments supplied by the user, and use the parsepatterns() method to add patterns to world based on these arguments. Page 7

If a supplied argument doesn t fit the structure accepted by parsepatterns(), display Program terminated: unknown pattern. to the screen and terminate the program with System.exit(0). Finally, use the last two arguments to print the evolution of world to the screen with displayworld(). Question 3: Phase 3 Game of Life with History Learning Objectives: Building and iterating over ArrayLists. Parsing command-line arguments. Defining static variables in a main class. Observing differences in program efficiency. Overloading methods; using overloaded methods. (16 points) By now, you should have a program that correctly displays the evolution of The Game of Life based on input received through command-line arguments. Do not attempt this part of the assignment until you have successfully completed Question 2. In this question you will extend and change the classes you defined in Question 2 to implement a historyrecording feature with ArrayLists. Your program will use more command-line arguments to determine whether to play the evolution of the Game of Life forward or in reverse. Remember: you should be implementing and testing small parts of all the classes bit by bit, depending on how the classes fit together. GameOfLife We want the user of your program to be able to give a command like this: java GameOfLife sparky 5 40 GLIDER 0 0 history reverse The above line means that the user wants to create an Environment whose initial state is created by adding a sparky at vertical coordinate 5 and horizontal coordinate 40, then adding a glider at coordinates 0 0. The user then wants your program to record the evolution of world in a history until the state of world reaches a maximum number of steps, or reaches a fixed point (stops changing), and then display the content of the history to the screen in reverse and report how many states were recorded in history. FYI, for the above input, 207 states should be recorded in history. When you run your completed program, you will notice that the history forward command is much slower than simply displaying the state evolution directly (as is done by your program in Question 2). Step 1: add the following private static constants to the GameOfLife class. int DEFAULT SPEED = 5 int DEFAULT LENGTH = 1000 Step 2: implement the following extensions and static methods. Declare a private static variable, called history, and initialize it to null. This variable will be visible to all methods in the class, and it should be an ArrayList of String. Add a method called recordsimulation() to the GameOfLife class. This method accepts an integer as a parameter and returns nothing; the integer represents the maximum number of states to record in history. The method should store each state of Environment evolution as a String in history until either the states no longer change (the system is no longer evolving) or the maximum number of states is reached, whichever comes first. Write a second method called displayworld(). This method is similar to the first displayworld() method that you wrote for Question 2, except that it displays states saved in history. It accepts Page 8

as input an integer speed, which represents how many times in a row to display each state, and it returns nothing. Have it print an empty line in between each displayed state. Write a method called displayworldreverse(). It does the same thing as the method described immediately above except that it displays the states saved in history in reverse order. As above, it accepts as input an integer speed, which represents how many times in a row to display each state, and it returns nothing. Write a void method called parsecommands() that accepts two Strings as parameters. If the first String is equal to the String "history", call the recordsimulation() method on DEFAULT LENGTH and display the simulation fowards or in reverse, depending on the value of the second String parameter. If the second parameter is nonsense, call the printusage() method. Otherwise (if the first String is not equal to "history") use the two parameters to call displayworld() so that the evolution of world is displayed directly (instead of being played from history). All String comparisons should be done in a case-insensitive manner. Finally, you will put all this together by updating the main() method in the GameOfLife class. Now your main() method should use the parsecommands() method to process the last two command-line arguments. In addition, after displaying the evolution of world as required, your main() method should display a message about the number of states recorded in history if history was requested by the user. For example "207 states were recorded in history.". You re done! Page 9