Differences between revisions 68 and 69
Revision 68 as of 2005-09-09 16:00:06
Size: 14504
Editor: dyn176165
Comment:
Revision 69 as of 2005-09-14 08:50:39
Size: 14523
Editor: dyn176191
Comment:
Deletions are marked like this. Additions are marked like this.
Line 75: Line 75:
}}} }}} ["/Answers#week1"]

TableOfContents

attachment:barkdifferent.jpg

1. Schedule

<project xmlns:pg="http://www.logilab.org/namespaces/pygantt_docbook" id="ooa">
<label>Object Oriented Animals</label>
<task id="JavaZ">
  <label>Java Z</label>
  <task id="workshop1">
    <label>Introduction</label>
    <duration>5</duration>
    <constraint type="begin-after-date">2005/09/07</constraint>
  </task> 
  <task id="workshop2">
    <label>Better living in Objectville: A puppy is born</label>
    <duration>5</duration>
    <constraint type="begin-after-end">workshop1</constraint>
  </task> 
  <task id="workshop3">
    <label>Serious Inheritance and Polymorphism: Bark, but bark different </label>
    <duration>5</duration>
    <constraint type="begin-after-end">workshop2</constraint>
  </task> 
  <task id="workshop4">
    <label> Powerful composition: Armed and Dangerous</label>
    <duration>5</duration>
    <constraint type="begin-after-end">workshop3</constraint>
  </task> 
  <task id="workshop5">
    <label>Something is happening: Romeo and Juliet in Objectville</label>
    <duration>5</duration>
    <constraint type="begin-after-end">workshop4</constraint>
  </task> 
</task>
<task id="uml">
  <label>UML</label>
  <duration>15</duration>
  <constraint type="begin-after-end">JavaZ</constraint>
</task>
<task id="patterns">
  <label>Design Patterns</label>
  <duration>10</duration>
  <constraint type="begin-after-end">uml</constraint>
</task>
</project>

1.1. Week 1: Introduction

Activity
  • My expections
  • Your expectations
  • Armed to the teeth: IDE (JBuilder)
  • Hello World made easy. A showcase.
  • Homework

    Please email your answers to MailTo(j.hu@tue.nl) before 5:00pm, Tuesday, Sept. 13.

  • Reproduce the Hello World example with JBuilder. send me the screenshots of the results:
    • Running "Hello World" in a JFrame. The frame has to be of size 400x300.
    • UML class diagrams from JBuilder
  • Read your favorite Java book, find out what an object, a class, a method and an instance variable is. And filling out the following "Who am I" form:

    What I do Who I am
    I am compiled from a .java file class
    My instance variable values can be different from my buddy's values
    I behave like a template
    I like to do stuff
    I can have many methods
    I represent a ''state''
    I have behaviors
    I am located in objects
    I live on the heap
    I am used to create object instances
    My state can chage
    I declare methods
    I can change at run time
    ["/Answers#week1"]
  • How would you implement a system that does the following:

    There will be shapes on a GUI, a square, a circle and a triangle. When the user clicks on a shape, the shape will rotate clockwise 360 degrees (i.e., all the way around) and play an WAV sound file specific to that particular shape.
    write a proposal in plain English how such a system should be implemented in an object oriented way. No, no Java source code please. But explain why you think your solution is particularly good. When you try to write why, think of the following terms: reusable, robust, readable, extendable, encapsulation ...
  • 1.2. Week 2: Better living in Objectville: A puppy is born

    Activity
  • Understanding objects
  • Well-encapsulated dogs
  • How Objects behave
  • Life and death
  • Homework
  • Questions
    1. What's the big deal about encapsulation?
    2. What happens if the argument you want to pass to a method is an object instead of a primitive?
    3. Can a method declare multiple return values? Or is there some way to returen more than one value?
    4. Does one have to do something with the return value of a method? Can it be ignored?
    5. Guess the output of the following code (You may try out if you want:)

         1   String a = new String("Hello");
         2   String b = new String("Hello");
         3   Foo c = a;
         4   if (a == b) {System.out.println("a == b");}
         5   if (a == c) {System.out.println("a == c");}
         6   if (b == c) {System.out.println("b == c");}
      
  • Develop a small game: Sink a Unit
    • It's you against the computer, but unlike the real Battleshop game, in this one you don't place any ships of your own. Instead, your job is to sink the computer's ships in the fewest number of guesses. Oh, and we are not going to sink ships. We kill units.
    • Goal
      Sink all of a computer's Units in the fewest guesses.
      Setup
      Whe the game program is launched, the computer places 2 Units in 10 virtual cells. Imaging a floor of 10 rooms, and a Unit occupies 3 neighboring rooms on this floor. When that's complete, the game asks for your first guess. attachment:SinkAUnit.png
      How you play

      You don't have to build a GUI. Let's work from the command line. Here is a possible scenario:

        c:\> java SinkAUnit
        Enter a guess: 1
        miss
        Enter a guess: 5
        hit
        Enter a guess: 6
        miss
        Enter a guess: 4
        hit
        Enter a guess: 3
        kill! You sunk Communication Unit!
        Enter a guess: 7
        hit
        Enter a guess: 8
        hit
        Enter a guess: 9
        kill! You sunk Mobility Unit!
        You sunk all the two units with 8 guesses. Not bad.
        c:\>

      Here is my design of the Unit class:

         1 public class Unit {
         2   int[] locationCells;
         3   int numOfHits = 0;
         4 
         5   public void setLocationCells(int[] locs) {
         6     locationCells = locs;
         7   }
         8 
         9   public String checkYourself(String stringGuess) {
        10     int guess = Integer.parseInt(stringGuess);
        11     String result = "miss";
        12     for (int i = 0; i < locationCells.length; i++) {
        13       if (guess == locationCells[i]) {
        14         result = "hit";
        15         numOfHits++;
        16         break;
        17       }
        18     }
        19     if (numOfHits == locationCells.length) {
        20       result = "kill";
        21     }
        22     System.out.println(result);
        23     return result;
        24   }
        25 }
        26 }
      

      To get the user input from the command line, I have a InputHelper class:

         1 import java.io.*;
         2 
         3 public class InputHelper {
         4   public String getUserInput(String prompt) {
         5     String inputLine = null;
         6     System.out.print(prompt + " ");
         7     try {
         8       BufferedReader br = new BufferedReader(
         9           new InputStreamReader(System.in)
        10           );
        11       inputLine = br.readLine();
        12       if (inputLine.length() == 0) {
        13         return null;
        14       }
        15     }
        16     catch (IOException ioe) {
        17       System.out.println("IOExecption: " + ioe);
        18     }
        19     return inputLine;
        20   }
        21 }
      
      Your task
      1. Prepare the Unit class ( I have already done for you ).
      2. Complete the following test class to test the Unit class

           1 public class TestDrive {
           2   public static void main (String[] args){
           3     Unit unit = new Unit();
           4     int[] locations = {2, 3, 4};
           5     unit.setLocationCells(locations);
           6     //..... complete this code
           7   }
           8 }
        
        try out whether the Unit prints and returns right message with different guess, for example "2", "5", "7", etc.
      3. Write a complete game, which randomly places a unit in 3 neibouring cells of the 10 cells. The user guesses where the unit is and tries to sink it. You might find the following piece of code helpful when placing the unit randomly:

           1        int randomNum = (int) (Math.random() * 8);  //why 8?
           2        int[] locations = {randomNum, randomNum+1, randomNum+2};
        
      4. A unit should have a name, for example, "Communication", "Mobility" (Do not try to sink "Home"!). improve the code of the class Unit to incorporate a name. Try to sink the Unit Communication.
      5. Improve your game to place two units in the cells. try to sink both of them.
      6. Analyze the code of the class Unit. Is there any problem? what if the Unit has been hit three times at the same cell?
      7. Did the princple of encapsulation help in developing this game? Where and when?
  • 1.3. Week 3: Serious Inheritance and Polymorphism: Bark, but bark different

    Activity
  • Dogs: Barking is an important part of our cultural identiy.
  • 1.4. Week 4: Powerful composition: Armed and Dangerous

    Activity
  • Dogs have got sunglasses, and cats too.
  • Dogs team up.
  • 1.5. Week 5: Something is happening: Romeo and Juliet in Objectville

    Activity
  • Love: Dogs, more dogs
  • Hate: Dogs like to chase cats
  • 1.6. Week 6: ...

    2. Assignment Describtion

    2.1. Assignment Introduction

    So you have done Java A and even B. Congratulations. Have you also found that Java offers something that is more than just a programming language? Do you know that Java can also make a dog bark and a cat scared? More, as a designer, you might also be able to make your ingenious design dance and sing? Better, the thinking behind Java may help you think differently.

    2.2. Target Competency Area(s), Competencies and Level(s)

    • Integrating technology.
    • Design and Research processes
    • Analyzing complexity.

    2.3. Entrance Level :Level of Prior Competency Development (Optional)

    Completed Java A and B.

    2.4. Learning Objectives

    Master object orientation and design patterns as ways of analyzing user requirements and complex products, as tools for communication with other designers and engineers, not just as a programming principle.

    With this assignment, we will try to wrap up your knowledge about Java, or any other object-oriented programming language you know (Java, C++, Object Pascal, Python, Ruby ...), to get the essence of object oriented design, to turn yourself from a craftsman back to a designer: Use object oriented principles as a tool to slice the complex into the simple, and put them together back again in a structured way.

    2.5. Learning Activities

    • Tutorials (20 hours)
      • Java Z (week 1-5, 10 hour hands-on workshops ) We start simple. So we will first run hands-on workshops to program some dogs and cats, to lift your Java B to Java Z. Then by looking at the dogs and cats, we will find many patterns arising from the ways they behave and the ways we want them to behave. Simple principles emerge. That is object-oriented design.
      • Object-oriented design and UML(week 6-8, 6 hour lectures/workshops) We will sum up the object-oriented principles we learnt from the dogs and cats, put them together to see how these principles can help us in designing a system, from requirement analysis, system design, implementation to testing and delivery. The students will find a Swiss army knife to be handy: UML (unified modelling language), de facto tool for object-oriented design.
      • Introduction to design patterns (week 9-10, 4 hour lectures). Problems appear often in a pattern, so do the solutions. If you have heard of Java Listeners, you know something about it already. We will explore a bit more.
    • Literature (10 hours)
    • Individual Java Z (30 hours)
    • UML design case (20 hours)

    2.6. Deliverables

    • Your favourite animals in Java
    • Report on the UML design case

    2.7. References

    2.7.1. Previous run

    • ["/200503"] Object Orientation and Design Patterns

    2.7.2. Online Resources

    2.7.3. References

    JunHu: ObjectOrientedAnimals/200509 (last edited 2008-10-03 20:18:30 by localhost)