On this page:
1.1 Instructions
Practice Problems
Problem 1: Problem:   Statues
What to submit
Problem 2: Problem:   Soups
What to submit
Problem 3: Problem:   Oh-Gi-Yu
What to submit
8.5

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 an uppercase 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.

Due Date: Thursday, January 16th, 9:00 pm

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.

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.

Problem 1: Problem: Statues

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

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 statues:

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

Interpretive Reflection

What information or implications could we find by adding a “location” field to statues? The provenance of art is often complex, as objects with significant historical or cultural value were often taken years ago, most notably by European archeologists during colonial periods. Despite colonies long gaining independence, many significant artifacts still exist in European museums today. There is a current movement to repatriate cultural artifacts to their countries of origin.

What to submit

You should submit your data definitions and examples in a file named Statues.java

Remember to check the feedback from the Style and Checker tests in handins!

Problem 2: Problem: Soups

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.

What to submit

You should submit your data definitions and examples in a file named Soups.java

Remember to check the feedback from the Style and Checker tests in handins!

Problem 3: Problem: Oh-Gi-Yu

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 monster resources (as in, not trap cards). 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.

Be sure to only define examples Attacks that are successful.

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 otherwise) 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.

What to submit

You should submit your data definitions and examples in a file named OhGiYu.java

Remember to check the feedback for Style and Checker Tests in handins!