CS 635 Advanced Object-Oriented Design & Programming

Spring Semester, 2006

Assignment 3

Assignment Index

© 2006, All Rights Reserved, SDSU & Roger Whitney

 San Diego State University -- This page last updated 3/27/06

Due April 11

  1. Strategy pattern. You are to implement a OrderableList class. An orderable list is like Java's Vector or ArrayList except that one can indicate an order for the list. For example one may want the list sorted or reverse sorted. Your OrderableList needs the methods listed below. You may need to change the names of the methods to conform to your language. You can add more methods if needed or desired.

add(anInteger) adds a single integer to the list in the correct location. Note you do not have to restrict the list to ints, however it might make things easier for students using Java.

addAll(aCollection) adds all the elements in the collection to the list in the correct location

get(index) returns the element in the index'th location of the list

toString() returns a string representation of the list. If the list contains the elements a, b and c then the string will be: a-b-c.

indexOf(anObject) returns location of anObject in the list, returns -1 if it is not in the list.

order(anAlgorithm) sets the algorithm used to order the list. Implement sorted order, reverse sorted order and random. You can assume that the elements of the list are ints if you like.

  1. Decorator pattern. Create the following three decorators for your OrderableList class.

Fancy String. The toString() method returns (a, b ,c) rather than a-b-c.

Reverse. The order of the elements are reversed.

SubList. Add a method subList(int fromIndex, int toIndex) which returns the elements of the list between fromIndex, inclusive, and toIndex, exclusive.

  1. State & Singleton Patterns. You are to implement a Oracle for a maze game. The game has 5 rooms. A player can ask the Oracle if a given room has gold, a weapon or an orc using the methods listed below. For simplicity sake we use the table below giving the locations of various items. However during the game these locations will change. The Oracle has three modes of behavior: always tells the truth, always lies or answers randomly.

Unknown to the players the state the Oracle starts in depends on which method is called first in the game. If a player first asks about a weapon the Oracle starts in the truth state, if a player first asks about gold the Oracle starts in the lying state, if a player firsts asks about orcs the Oracle starts in the random state. The room that a player first asks about determines how long the Oracle stays in the same state. So if a player asks about room 3, the Oracle will answer three questions in the same state. The fourth question will be answered in the next state.

When in the random state the number of times the Oracle answers yes is recorded. Each time the Oracle enters the random state this number is reset. When it is time to move to a different state, if the number of yes answers is odd the Oracle moves to the truth state otherwise it moves to the lying state.

When in the truth state the room number of first question is recorded. The value is changed for each new truth state. If the room number is odd the next state will be the lying state, otherwise it will be the random state.

When in the lying state the answer to the last question in that state determines the next state. If the answer is yes, then the next state is the random state otherwise it is truth state.

Only one Oracle is allowed in the game.

Oracle methods

orc(anInt) returns the Oracle' answer to whether an orc is in the given room (anInt)

weapon(anInt) returns the Oracle' answer to whether a weapon is in the given room (anInt)

gold(anInt) returns the Oracle' answer to whether a gold piece is in the given room (anInt)



Contains Gold

Contains Orc

Contains Weapon























Percent of Grade

Working Code


Unit Tests


Quality of Code


Proper implementation of Patterns


What to Turn in

Turn in hard copy of your code.

Note to C++ people. C++ classes are have a header and an implementation. Place the header  and implementation in separate files. Do not include any implementation in the header file.

Late Policy

An assignment turned in 1-7 days late, will lose 3% of the total value of the assignment per day late. The eight day late the penalty will be 40% of the assignment, the ninth day late the penalty will be 60%, after the ninth day late the penalty will be 90%. Once a solution to an assignment has been posted or discussed in class, the assignment will no longer be accepted. Late penalties are always rounded up to the next integer value.