design patterns assignments
Is there any place to find multiple assignments for implementing design patterns( along with solutions ?)
My idea is to get the hands on in a proper way. I would like to implement those in Java. at the moment I just need basic design patterns , not J2EE patterns.
开发者_如何学编程I'm actually looking for the complete application to be developed which uses most of the design patterns. (All design patterns in a single assignment)
Build Me An Antfarm!!
You want an assignment? I'll give you one. It's due Tuesday, February 22 at 9:00PM Pacific time. You are going to build me an antfarm, and you're going to use some common design patterns to do it.
This does not have EVERY design pattern, because that's just silly. It does, however, have enough that the interactions will be complex while being simple enough to implement quickly. Once this is done, we can look at adding in more features to our ant farm!
I will add requirements (with what revision they were added) as needs arise.
Here's the requirements:
Functional Requirements:
- A meadow can have many ant farms in them. For this assignment, only ever allow one meadow to take place.
- A meadow should be capable of spawning a logically unlimited number of antfarms.
- An antfarm should be comprised of a network of antfarm rooms.
- An antfarm should have rooms for spawning more ants.
- Ants should be able to battle other ants. When they do, the loser of the battle should die (it's antfarm can no longer command it), and the winner of the battle should get the attributes of the ant.
- An antfarm should only have one species of ant. Each species should have some kind of bonus to them. Perhaps they harvest food faster. Perhaps they have a higher chance to kill other ants.
- If a member of an ant colony kills the queen of another colony, the killer's queen should assume control of the dead queen's population of ants. all ants should now also have the attributes of both species of ant. (So if one species was strong, and the other species was efficient, now both populations are merged into a single population that is both strong and efficient.)
- Ants should have to rest every so often. When they do, they should consume food. An antfarm should be limited in capacity of how many ants can rest at a time based on the number of rooms (X amount per resting room).
- The simulation should end when, at the end of a tick, there is 1 or less active colonies/queens. This means you should spawn at least 2 colonies before your first tick.
- Rooms in the Antfarm should require a certain (probably large) number of worker-ticks to build. So, if it would take 1 worker 100 ticks to dig a room, it would take 50 workers 2 ticks, etc. But there should be a significant cost to building a room, since rooms determine how much you can rest. (This requirement added in spec revision 1.)
Technical Requirements: (Design patterns bolded)
- The Meadow class MUST be a singleton.
- An antfarm should be a built by building rooms into an antfarm. (Builder pattern)
- Drones and Warriors should only be created with the factory pattern by AntRooms, and Queens by the factory pattern by Meadows for purposes of a new colony.
- Use the decorator pattern to keep track of an ant's attributes.
- Antfarms should be templated (using Java generics) to hold any type of ant, and the antfarm should specify at runtime which type of ant it holds.
- The simulation should be tick-based. (Mediator pattern) Each tick, every ant (in a random order) should perform some action based on its surroundings. Drones should look for food, warriors should hunt enemies (or go back for food if hungry) and queens should spawn an egg.
Interface requirements:
The interface to the ant farm should be a command line interface with the following commands:
spawn X Y T
- should create a new colony at position X,Y of species T. The output should give an identifier for the colony so it can be controlled later.- Example
spawn 14 -32 Killer
creates a colony of "Killer" ants at position x14 y-32. give I R A
- should give the colony identified by I (at creation) resource R of amount A.- Example
give 1 food 50
gives colony 1 50 food. Example
give 3 warrior 10
gives colony 3 10 warriors that spawn at colony 3's base.tick [T]
- should perform T tick operations. For convience, allow T to not be specified, and simply tick once.- Example
tick 10
Example
tick
summary I
- should give a summary of colony I. A summary gives information about that colony.- Example
summary 1
might give the following output:
Output:
Species: Killer
Workers: 14
Warriors: 10
Ant Kills: 18
Colony kills: 2 (2:Pansy 4:Gatherer)
Ticks alive: 143
Status: Alive
- Example
summary 2
might give the following output:
Output:
Species: Pansy
Workers: 4
Warriors: 0
Ant Kills: 2
Colony kills: 0
Ticks Alive: 25
Status: Killed by 1:Killer
If you run into any difficulty, post a comment about it. I'll try to give you some hints like blank classes, method headers, or just general ideas about how to make these design patterns interact with eachother.
Good luck, and HAVE FUN!!
http://www.allapplabs.com/java_design_patterns/java_design_patterns.htm
The above site caters to few design patterns and it also has loads of examples with solutions
You can also take problems from the book "Head first design patterns". It has a lot of puzzle problems at the end of each chapter.
精彩评论