On this page:
1.1 Instructions
Practice Problems
Problem 1: Our Canine Friends
What to submit
Problem 2: Waffles
What to submit
Problem 3: PR Crisis
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: Friday, May 9th, 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: Our Canine Friends

We are designing the data collection for the American Kennel Club. For each dog we need to collect the following information:

Design the class Dog that represents the information about each dog for the census.

Make at least three examples of instances of this class, in the class ExamplesDog. Two of the examples should be objects named huffle and pearl and should represent the following two dogs:

What to submit

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

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

Problem 2: Waffles

Here is a data definition in DrRacket:

;; A Waffle is one of:
;; -- Plain
;; -- Topped
 
;; A Plain is a (make-plain String)
(define-struct plain (flour))
 
;; A Topped is a (make-topped Waffle String)
(define-struct topped (below topping))
 

Make sure the two sample orders given above are named order1 and order2. Note: the descriptions above are listed in the order that you would order this in real life. Think carefully how this should be represented as data.

What to submit

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

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

Problem 3: PR Crisis

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, which is a String, and a believability (measured as an integer).

Bribe has a target which is a String, and an amount which denote who is being bribed and by how much (as an integer).

An Apology has some excuse which is a String, and a boolean 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 resource’s value is measured as follows: a denial is worth its believability, a bribe is worth its amount, and an apology is either worth 50 or 100, based on its reusability.

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.

What to submit

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

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