On this page:
1.1 Instructions
Practice Problems
Problem 1
Problem 2
Problem 3
Design
6.10

Assignment 1: Designing complex data

Goals: Practice designing the representation of complex data.

1.1 Instructions

Be very, very careful with naming! The solution files expect your submissions to be named a certain way, so that they can define their own Examples class with which to test your code. Therefore, whenever the assignment specifies:
  • the names of classes,

  • the names and types of the fields within classes,

  • the names, types and order of the arguments to the constructor, or

  • filenames,

...be sure that your submission uses exactly those names. Additionally, make sure you follow the course style guidelines. For now the most important ones are: using spaces instead of tabs, indenting by 2 characters, following the naming conventions (data type names start with a capital letter, interfaces begin with a capital I, names of fields and methods start with a lower case letter), and having spaces before curly braces.

You will submit this assignment by the deadlines using the course handin server. Follow A Complete Guide to the Handin Server for information on how to use the handin server. You may submit as many times as you wish. Be aware of the fact that close to the deadline the server may slow down to handle many submissions, so try to finish early. There will be a separate submission for each problem - it makes it easier to grade each problem, and to provide you with the feedback for each problem you work on.

The three submissions will be organized as follows:

Due Date: Friday, May 8th, 10:00pm EST

Practice Problems

Work out these problems from How to Design Classes on your own. Save them in an electronic portfolio, so you can show them to your instructor, review them before the exam, use them as a reference when working on the homework assignments.

Problem 1

Design a class Statue to represent the following information about statues:

Everywhere in this assignment that you see italic, fixed-width text, it is intended to be the name of a field, identifier, class name or interface name you must define...but you likely must modify that name a bit to conform to our Java naming conventions: hyphenated-names are written in camelCase, and interface names begin with an uppercase I.

Everywhere that you see fixed-width text, it is exactly the name you must use.

Make at least three examples of instances of this class, in the class ExamplesStatue. Two of the examples should be objects named statueOfLiberty and venusDeMilo and should represent the following two graphic novels:

Note: If the year 2019 is represented as 2019, and 1886 as 1886, what number makes sense to use for 115 BC?

Problem 2

Here is a data definition in DrRacket:

;; A Soup is one of:
;; -- Broth
;; -- Ingredient
 
;; A Broth is a (make-broth String)
(define-struct broth [type])
 
;; An Ingredient is a (make-ingredient Soup String)
(define-struct ingredient [more name])
 

Make sure the two sample soups given above are named yummy and noThankYou.

Name the class that holds the examples of your soup data ExamplesSoup.

Problem 3

We’ve been asked to help build a new, totally original, deck-building game, Oh-Gi-Yu. To start, we’re designing representations for the resources a player can have and the actions they can take during their turn. A player can have three kinds of resources: Monster, Fusion, and Trap.

A Monster has a name, such as Bright Magician, hp (short for hit points, measured as an integer), and an attack rating (measured as an integer).

Fusion has a name, such as Green-Eyes Epic Dragon, monster1 and a monster2 of which it is comprised. Note that these can only be Monsters, not other Fusions.

A Trap has some description and a flag continuous denoting whether its effect is instant or occurs over a period of time.

As the game is under construction, the player can only perform two kinds of actions right now: they can Attack one monster with another (be it a fusion or non-fusion monster), or they can Activate a trap card.

An Attack involves an attacker and a defender, both of which are resources. To succesfully attack, the attacker’s attack value must be worth more than the defender’s hp. A Fusion’s hp and attack is derived from the sum of its monsters’ hp and attack.

Note: You do not have to implement this calculation in code, but be sure to only define examples Attacks that are succesful.

We’re placing a lot of restrictions on the data, such as attacks only involving monsters, and attackers needing to have more attack points than defenders have HP, but aren’t actually enforcing these in the code. The ways to enforce these constraints will be further explored later in the semester.

An Activate has a trap (which should be a Trap) and a target (a Monster, Fusion or Trap) it is targeting.

Name your action examples attack1, attack2, activate1, activate2, etc., and your examples class ExamplesGame.

Design

Note that we have described a data definition which groups monsters, fusions, and trap cards all as resources. Keeping in mind the actions described above, was this a good data design? If so, why, and if not, why not? Leave a brief comment below your examples in your examples class with your answer, and if you think it’s a poor design choice, briefly theorize about an alternative design that would make more sense.