During this lab session:
This activity helps the student develop the following skills, values and attitudes: ability to analyze and synthesize, capacity for identifying and solving problems, and efficient use of computer systems.
This lab is based on chapter 1 of [FREEMAN]. You will need to have installed Mono and NUnit. It can be developed individually or in pairs.
chapter01
and place inside it
the contents of this file: strategy.zip.
Any new files you create must also go into this directory.
Headfirst.Strategy.MexicanQuack
that implements the quack behavior interface. Its quack method must
return the following string: "Quack, Quack, Ajua".
Headfirst.Strategy.RancheroDuck
that inherits from the duck class. Its flying behavior must be
provided by the fly with wings class, while its quack behavior must
be provided by the Mexican quack class. Its display method must
return the following string: "I'm a Ranchero duck".
Headfirst.Strategy.ComposableDuck
that also inherits from the duck class. The constructor for this
class should receive as parameters both the flying and quacking
behaviors. Its display method should return a string like this:
"I'm a duck composed of X and Y", where X
and Y are the names of the flying and quacking behavior
classes, respectively.
Check your code using the following test cases:
namespace Headfirst.Strategy { using NUnit.Framework; [TestFixture] public class TestStrategy { [Test] public void TestMexicanQuack() { IQuackBehavior q = new MexicanQuack(); Assert.AreEqual("Quack, Quack, Ajua", q.Quack()); } [Test] public void TestRubberDuck() { Duck d = new RubberDuck(); Assert.AreEqual("I'm a rubber duckie", d.Display()); Assert.AreEqual("I can't fly", d.PerformFly()); Assert.AreEqual("Squeak", d.PerformQuack()); } [Test] public void TestMallardDuck() { Duck d = new MallardDuck(); Assert.AreEqual("I'm a real Mallard duck", d.Display()); Assert.AreEqual("I'm flying!!", d.PerformFly()); Assert.AreEqual("Quack", d.PerformQuack()); } [Test] public void TestRancheroDuck() { Duck d = new RancheroDuck(); Assert.AreEqual("I'm a Ranchero duck", d.Display()); Assert.AreEqual("I'm flying!!", d.PerformFly()); Assert.AreEqual("Quack, Quack, Ajua", d.PerformQuack()); } [Test] public void TestComposableDuck() { IFlyBehavior f = new FlyNoWay(); IQuackBehavior q = new SimpleQuack(); Duck d = new ComposableDuck(f, q); Assert.AreEqual( "I'm a duck composed of Headfirst.Strategy.FlyNoWay and " + "Headfirst.Strategy.SimpleQuack", d.Display()); Assert.AreEqual("I can't fly", d.PerformFly()); Assert.AreEqual("Quack", d.PerformQuack()); } } }
To hand in your lab work, follow these instructions:
readme.txt
text file and place it in the
chapter01
directory. Include in this file the
name and student ID of the authors.
chapter01
directory. Call this file
chapter01.zip
.
This activity will be evaluated using the following criteria:
100 | The code works as requested. |
---|---|
60-90 | The code works, but has some flaws. |
20-50 | The code doesn't work, but it seams that some amount of time was spent on it. |
DA | The program was plagiarized. |