Assignment 1: Designing complex data
Goals: Practice designing the representation of complex data.
1 Instructions
This homework should be done with your partners.
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,
You will submit this assignment by the deadlines using the Gradescope handin server Follow their documentation for information on how to use it, if you have not before. 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 GraphicNovel.java file
Homework 1 Problem 2: The Sundae.java file
Homework 1 Problem 3: The ExamplesGame.java file
Due Date: Thursday, September 6th, 10: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.
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
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.
title: the name of the graphic novel, as a String
author: to be represented as a String
artist: to be represented as a String
year: when the book was published int
cost: the cost of the graphic novel in US dollars, represented as a double
monochrome: a boolean representing whether or not the book is in black and white
Make at least three examples of instances of this class, in the class ExamplesGraphicNovel. Two of the examples should be objects named maus and logicomix and should represent the following two graphic novels:
Maus, written and drawn by Spiegelman, 1980, $17.60, black and white
Logicomix, written by Doxiadis, art by Papadatos, 2009, $21.00, colored
Problem 2
Here is a data definition in DrRacket:
;; A Sundae is one of: ;; -- Scoop ;; -- Topping ;; A Scoop is a (make-scoop String) (define-struct scoop [flavor]) ;; A Topping is a (make-topping Sundae String) (define-struct topping [inner 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 sundaes:
– a "chocolate" scoop topped by "rainbow sprinkles" topped by "caramel" topped by "whipped cream"
– a "vanilla" scoop topped by "chocolate sprinkles" topped by "fudge" topped by "plum sauce"
Make sure the two sample sundaes given above are named yummy and noThankYou.
Name the class that holds the examples of your delicious ice cream data ExamplesSundae.
Problem 3
We’ve been asked to help build a new deck-building game, PR Crisis. 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: Denial, Bribe, and Apology.
A Denial has a subject, such as knowledge or action, and a believability (measured as an integer).
Bribe has a target and an integer value (which denote who is being bribed and by how much).
An Apology has some excuse and a flag reusable denoting whether the player could use the apology again and no one would notice.
As the game is under construction, the player can only perform two kinds of actions right now: they can Purchase a resource from the common pool, or they can Swap a resource in their hand from the discard pile.
To purchase an item, the player must pay an associated cost, which must be a positive integer. They then receive the purchased resource item.
Every swap action has a consumed resource and a received resource. The value of the received resource must be no more than 2 greater than the value of the consumed resource. A denial is worth its believability, hush money is worth its value, and an apology is either worth 50 or 100, based on its reusability (reusable apologies are worth 100).
- Define six examples of resources, including:
iDidntKnow: subject "knowledge", believability 51
witness: target "innocent witness", value 49
iWontDoItAgain: excuse "I won't do it again", not reusable
The others can be whatever you wish. Define four types of actions, two of each kind.
Name your action examples purchase1, swap2, etc., and your examples class ExamplesGame. You haven’t learned yet how to check the described consistency requirements in Java, but make sure your examples follow them.