14525
Comment:
|
14505
|
Deletions are marked like this. | Additions are marked like this. |
Line 100: | Line 100: |
}}} | }}} |
Line 129: | Line 129: |
}}} | }}} |
Line 157: | Line 157: |
}}} | }}} |
Line 180: | Line 180: |
}}} | }}} |
Line 187: | Line 187: |
int[] locations = { 2, 3, 4}; |
int[] locations = {2, 3, 4}; |
Line 197: | Line 196: |
}}} | }}} |
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
Please email your answers to MailTo(j.hu@tue.nl) before 5:00pm, Tuesday, Sept. 13.
- 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:
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
- What's the big deal about encapsulation?
- What happens if the argument you want to pass to a method is an object instead of a primitive?
- Can a method declare multiple return values? Or is there some way to returen more than one value?
- Does one have to do something with the return value of a method? Can it be ignored?
Guess the output of the following code (You may try out if you want:)
- 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
- Prepare the Unit class ( I have already done for you ).
Complete the following test class to test the Unit class
try out whether the Unit prints and returns right message with different guess, for example "2", "5", "7", etc.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:
- 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.
- Improve your game to place two units in the cells. try to sink both of them.
- Analyze the code of the class Unit. Is there any problem? what if the Unit has been hit three times at the same cell?
- Does 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
1.4. Week 4: Powerful composition: Armed and Dangerous
- Activity
1.5. Week 5: Something is happening: Romeo and Juliet in Objectville
- Activity
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
[http://w3.tue.nl/en/services/dienst_ict/organisatie/groepen/wins/campus_software/ms_visio/ Download MS Visio from TU/e]
[http://w3.tue.nl/en/services/dienst_ict/organisatie/groepen/wins/campus_software/borland_jbuilder/ Download Jbuilder 2005 from TU/e]
[http://java.sun.com/docs/books/tutorial/ The Java Tutorial]
[http://www.javaworld.com/javaworld/jw-04-2001/jw-0406-java101.html Object-oriented language basics]
[http://www.uml.org/ Official OMG UML site], but do not try to read the entire UML specification.
[http://bdn.borland.com/article/0,1410,31863,00.html Borland's UML Tutorial]
[http://odl-skopje.etf.ukim.edu.mk/uml-help/ UML Totorial in 7 days] by Slobodan Kalajdziski;
[http://www3.software.ibm.com/ibmdl/pub/software/rational/web/whitepapers/2003/intro_rdn.pdf Introduction to the Unified Modeling Language] (PDF) by Terry Quatrani;
[http://www2.ing.puc.cl/~jnavon/IIC2142/patexamples.htm Non-Software Examples of Software Design Patterns]
[http://www.holub.com/goodies/uml/ Allen Holub's UML Quick Reference]
[http://www.phruby.com/stencildownload.html UML 2.0 stencils for Visio 2003]
[http://www.objectcentral.com/oobook/oobook.htm Essense of Object Oriented Programming]
[http://www.csc.calpoly.edu/~dbutler/tutorials/winter96/crc_b/ Object-Oriented Analysis and Design using CRC Cards]
- recommended to read