Analyze the problem statement carefully to determine with what kind of information your program must cope. Find classes of information in your problem statement, not specific pieces of information, and give some examples to supplement the description of your classes.
Now translate the informal class descriptions into a detailed class diagram
that shows all the relationships between classes and interfaces. To do that,
you have to recognize five situations and translate them into boxes and arrows.
1.
Use a primitive type if there is a correspondence between the information
and an atomic type that the language supports.
2.
Use a class when you want to represent information that consists of several other
pieces of information, e.g. a date.
3.
If a field of a class A is itself a class (say B) then class A refers to class
B. When you create an instance of A it contains an instance of B. When a class refers to
another class it is called compound class, when it doesn't it is called
primitive.
4.
When you have a collection of distinct classes and you want to give them a common header
use a union of classes.
5.
If you have a piece of information that consists of an arbitrary number of other pieces
then the class diagram is self-referential.
Now, the class diagram can be turned into class definitions automatically. Each class is
equipped with a constructor. Containment arrows disappear and inheritance arrows become
implements
specifications. Add a purpose statement to each class to explain
what information the class represents.
Translate your informal examples into objects. By this you verify that your class hierarchy can represent the information of the problem statement. Also, make up examples of objects and interpret them in the problem domain.
#| a Minefield is one of: - empty - (cons Mine Minefield) |# (define-struct mine(row col)) ;a mine is a structure: (make-mine Number Number) ;row and col define the position of a mine in the minefield (define mine1 (make-mine 1 4)) (define mine2 (make-mine 12 11)) (define mine3 (make-mine 7 21)) (define mines (cons mine1 (cons mine2 (cons mine3 empty))))- Design a class diagram for the previous data definitions.
- Write down Scheme-like data definitions for the class of data that represents a Sport.
- Design the class diagrams on a piece of paper.
- Make up three examples for each kind of sports.
- Define Java classes that correspond to your class diagram.
- Translate your examples into Java code.
A competition consists of an arbitrary number of sport-events. To represent a sport-event we need a sport and three winners (name and time for each).
- Extend your previous class diagram to include Sport-event and Competition.INCLUDE INSTRUCTIONS FOR SETTING UP HOMEWORK SUBMISSION HERE...