On this page:
Instructions
Practice Problems
Problem 1: “Painting”
6.10

Assignment 2: Designing methods for complex data

Goals: Learn to design methods for complex class hierarchies. Practice designing the representation of complex data.

Instructions

Be very, very careful with naming! Again, 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,

  • the names, types and order of arguments to methods, or

  • filenames,

...be sure that your submission uses exactly those names. Additionally, make sure you follow the style guidelines that the handin server enforces. 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, 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.

Your submissions for this homework will be organized as follows:

Due Date: Wednesday, May 13th, 10:00pm EST

Practice Problems

Work out these problems 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 1: “Painting”

Define the file Paint.java that will contain the entire solution to this problem. You will need to import java.awt.Color at the top of your file, just like you import the tester library.

Well, not precisely. The math in this problem will deal with additive colors, like mixing light, whereas paint is more properly subtractive color... If the nuances of color mixing intrigue you, there’s plenty more to learn about how computers model color.

For this problem we will use classes that represent paint on a painter’s palette. Each blob of paint is either a Solid or a Combo. A Solid has a name and a Color. A Combo has a name and an operation which is some kind of IMixture, describing the recipe for how the combo was made.

There are three kinds of mixtures: Darken (darkens a paint color), Brighten (brightens a paint color), and Blend (mixes two paint colors together).