Goals: Practice designing the representation of complex data.
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
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:
Homework 1 Problem 1: The Statue.java file
Homework 1 Problem 2: The Soup.java file
Homework 1 Problem 3: The OhGiYu.java file
Due Date: Friday, May 8th, 10:00pm EST
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 2.4 on page 17
Problem 3.1 on page 25
Problem 4.4 on page 34
Problem 5.3 on page 43
Problem 10.6 on page 102
Problem 11.2 on page 113
Problem 14.7 on page 140
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 statueOfLiberty and venusDeMilo and should represent the following two graphic novels:
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?
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])
Draw the class diagram that represents this data definition. You may draw this as ASCII-art and include it in your submission, if you wish. Or you can just draw it on paper and not submit it. Regardless, we think it will help you in visualizing how the data is organized.
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. Make sure that the constructor arguments are given in the same order as shown.
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.
Name the class that holds the examples of your soup data ExamplesSoup.
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.
- Define six examples of resources, including:
The others can be whatever you wish.
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
Define four types of actions, two of each kind.
Name your action examples attack1, attack2, activate1, activate2, etc., and your examples class ExamplesGame.
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.