Designing classes that represent lists and trees
Note: The solution to the exercise 3 is in your handout. You may use it as a guide. Remember to include a class diagram and examples of instances for each class you design.
Consider a revision of the problem in exercise 2:
Develop a program that assists real estate agents. The program deals with listings of available houses. ...Make examples. Develop a data definitions for listings of houses. Implement the definition with Java classes. Translate the examples into Java instances.
+----------------+ | AReadingList |<-----------------+ +----------------+ | / \ | --- | | | | | +---------+---------+ | | | | +---------+ +------------------+ | | MTLoB | | ConsLoB | | +---------+ +------------------+ | +-------| Book fst | | | | AReadingList rst |--+ | +------------------+ v +-----------------+ | Book | +-----------------+ | String author | | String title | | int price | | int year | +-----------------+
Figure: A class diagram for reading lists
+----------------+ | AWR |<---------------+ +----------------+ | / \ | --- | | | | | +---------+---------+ | | | | +---------+ +-------------------+ | | MTWR | | ConsWR | | +---------+ +-------------------+ | +----| WeatherRecord fst | | | | AWR rst |--+ | +-------------------+ v +-----------------------------+ | WeatherRecord | +-----------------------------+ | Date d |-----------------+ | TemperatureRange today |--+ | | TemperatureRange normal |--+ | | TemperatureRange record |--+ | | double precipitation | | | +-----------------------------+ | | | | v v +---------------------+ +------------+ | TemperatureRange | | Date | +---------------------+ +------------+ | int high | | int day | | int low | | int month | +---------------------+ | int year | +------------+
Figure: A class diagram for weather reports
Consider a revision of the problem in exercise 2:
Develop a program that assists a bookstore manager with reading lists. ...The diagram in figure 3 represents the data definitions for classes that represent reading lists. Implement the definitions with classes. Create two book lists that contain at least one of the books in exercise 2 plus one or more of your favorite books.
Take a look at figure 3, which contains the data definition for weather reports. A weather report is a sequence of weather records (see exercise 2). Translate the diagram into a collection of classes. Also represent two (made-up) two weather reports, one for your home town and one for your college town, in Java.
Containment in Union -- Trees
Bob 1917 | +--+--+ +--+--+ +--+--+ | | | Angela Robert Annie 1936 1935 1938 | | | +----+----+ +----+----+ | | Janet Paul 1958 1956 | | +----------+----------+ | Peter 1980
Figure: A family tree
Consider the following problem:
Develop program that helps with recording a person's ancestry tree. Specifically, for each person we wish to remember the person's name and year of birth, in addition to the ancestry on the father's and the mother's side, if it is available.See Figure 3 for an example of the relevant information.Develop the class diagram and the Java class hierarchy that represents the information in an ancestry tree. Then translate the sample tree into Java code. Also draw your family's ancestor tree as far as known and represent it as a Java object.
+--------------+ | Coach | +--------------+ +------| Player p | | | APT players |-+ +---------------+ | +--------------+ | | +---------+ | | | | | | | | v v v | | | +-------------+ | | | | APT | | | | +-------------+ | | | / \ | | | --- | | | | | | | +-----------+-----+ | | | | | | | | +------------+ +--------------+ | | | | MTTeam | | PhoneTree | | | | +------------+ +--------------+ | | +------+ +--------| Player p | | | | | | APT call1 |---+ | v v | APT call2 |------+ +--------------+ +--------------+ | Player | +--------------+ | String name | | int phone | +--------------+
Figure: A class diagram for a phone tree
Take a look at the class diagram for a program that manages a phone tree (like those for a soccer team)(Figure 3). To inform the team about rainouts and schedule changes, the league calls the coach, who in turn calls the team captain. Each player then calls at most two other players.
Translate the following examples into pictures of phone trees:
Player coach = new Player("Bob", 5432345); Player p1 = new Player("Jan", 5432356); Player p2 = new Player("Kerry", 5435421); Player p3 = new Player("Ryan", 5436571); Player p4 = new Player("Erin", 5437762); Player p5 = new Player("Pat", 5437789); APT empty = new MTTeam(); APT pt = new PhoneTree( p2, new PhoneTree(p3, empty, empty), new PhoneTree(p4, new PhoneTree(p5, empty, empty), new PhoneTree(p1, empty, empty))); Coach ch = new Coach(coach, pt);Now develop Java code that corresponds to the given data definition.
Think of how you would design the classes that represent a grade book. Follow the design recipe to design Java classes that represent this information.