Assignment 1: Designing complex data
Goals: Practice designing the representation of complex data.
You may submit one .java file containing the solution to all of these problems, or you can submit one .zip file containing an individual .java file for each of these problems.
Problem 1
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.
name: the name of the statue, as a String
artist: to be represented as a String
year: when the statue was made int
weight: the weight the statue in pounds, represented as a double
whole: a boolean representing whether or not the statue still has all of its parts
Make at least three examples of instances of this class, in the class ExamplesStatue. Two of the examples should be objects named statueOfLibery and venusDeMilo and should represent the following two statues:
Statue Of Liberty, designed by Bartholdi, 1886, 450,000 pounds, whole
Venus de Milo, designed by Alexandros of Antioch, 115 BC, 1984.16 pounds, missing arms
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])
Convert this data definition into Java. Make sure you use the same names for data types and for the fields, as are used in the DrRacket data definitions, converted into Java style standards.
Include in your examples the following soups:
– a "chicken" soup with "carrots" and "celery" and "noodles"
– a "vanilla" soup with "horseradish" and "hot dogs" and "plum sauce"
Make sure the two sample soups given above are named yummy and noThankYou. The rightmost ingredients given above should be the outermost ingredients in your example.
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 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 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 otherwise) it is targeting.
- Define six examples of resources, including:
kuriboh: name "Kuriboh", hp 200, attack 100
jinzo: name "Jinzo", hp 500, attack 400
kurizo: name "Kurizo", monster1 kuriboh, monster2 jinzo
trapHole: description "Kills a monster", not contiunous
The others can be whatever you wish. Define four types of actions, two of each kind.
Name your action examples attack1, attack2, activate1, activate2, etc.
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. }