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 9 of [FREEMAN] and chapter 7 of [ALBAHARI]. It can be developed individually or in pairs.
The file menuiterator.zip contains the Java source code for the example on pages 360 to 375 of [FREEMAN]. Translate the Java code into C#, with the following considerations:
chapter09
.
All methods that print something to the standard output (using
System.out.print
or
System.out.println
) should instead return a string.
Returning strings rather than displaying values simplifies
unit testing.
In other words, a Java method like this:
void sayHello() { System.out.println("Hi!"); }
should be rewritten in C# as:
string SayHello() { return "Hi!" + Environment.NewLine; }
Note that if you need an end of line terminator, you should use
the System.Environment.NewLine
property.
List<T>
class when converting from
Java's ArrayList
class.
The C# equivalent of Java's Iterator
interface is
IEnumerator
. You'll need to rename and adjust your
code accordingly. For the CompositeIterator
class,
have it implement the generic IEnumerator<T>
interface.
MenuComponent
class should implement the
IEnumerable<T>
interface. The
GetEnumerator
method should take the place of the
createIterator
method.
foreach
statement instead of the
while
statement to iterate over each element contained
in an enumerable object.
System.NotSupportedException
in C# when
the Java code uses UnsupportedOperationException
.
MenuTestDriva
Java class into an NUnit
test class. The expected "output" (returned strings) should be
verified using Assert.AreEqual
.
To hand in your lab work, follow these instructions:
readme.txt
text file that includes the name
and student ID of the authors. Copy this file to the
chapter09
folder.
chapter09
directory. Call this file
chapter09.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. |