Computer Science 252
Problem Solving with Java
Spring 2016, The College of Saint Rose
In this lab, you will gain experience working with a custom object by writing a program that grows and displays some flowers, much like those that bloom throughout the Albany area this time of year (or not).
When you press the mouse on the canvas, a small plant is drawn. As you drag the mouse, the plant grows slowly. When it reaches its full height, a flower blooms. If you then click on that flower's petals before beginning to work on the next flower, its color will change.
You may work alone or with a partner on this lab.
Getting Set Up
To help you get started, we have provided a starter BlueJ project with the class header and some method stubs for the Flower class and a complete version of a WindowController extension named Spring that will manipulate the flowers on the screen using the constructor and methods of the Flower class. You will need to create your own class GrowingRectangle for the practice program.
Working solutions to all programs can be downloaded here.
Practice Program
Before we get in to the programming assignment, there is a practice program for you to complete. Please do this first, as it will help you with some of the essential functionality of the programming assignment.
The program should have this functionality:
Programming Assignment: Spring Flowers
Design Document
To get started, you will develop a written design for this program, no later than our class meeting on Thursday, February 18. Before you write anything down, read this entire lab description carefully. Then develop a design that includes:
Do not start coding before completing this design and having it approved by your instructor. It is often more productive to design a program away from the computer, and you should get into the habit of working in this way. If you arrive at the keyboard with a written idea of how to approach the problem, you will be able to make progress much more quickly than you would otherwise.
Problem Description
The canvas should initially start empty. When you click on the canvas, a flower should start growing with its base centered at that point. Initially it will be just a sprout, the height of which you may choose to be either a constant value or a percentage of the ultimate height of the flower. Its final height is determined by the second formal parameter to the constructor. As you drag the mouse, the stem should grow (upward, obviously). When it reaches its full height, the stem should stop growing and petals should appear. The color for the petals should be chosen randomly. The flower should not grow any more, but if you click on the petals after it has bloomed, the flower will change color. When you are happy with the flower's color, you can grow another one by clicking somewhere else in the window. When the mouse moves out of and then back into the window, the flowers should be removed from the canvas. Only the most-recently-created flower needs to respond to mouse clicks by changing its color.
If the mouse is released before the stem reaches its full height, the stem's growth stops and this plant will never produce a flower.
Your program will be divided into two classes: a window controller called Spring and a Flower class. A complete Spring class, which you should not modify, is provided in the starter folder. Your task is to implement the Flower class so that it works with our Spring. In particular, the Flower class needs to provide:
Your flowers should be at least as realistic as those in the demo solution. But feel free to use more graphics primitives in your Flower class to make the flowers look more attractive. Up to 3 bonus points are available for especially nice flowers.
Important note: your program should not include any loops! The growth of the flowers is controlled by the sequence of mouse drag events.
Submitting
Before 11:59 PM, Tuesday, February 23, 2016, submit your lab for grading. There are three things you need to do to complete the submission: (i) Email a copy of your lab (a .7z or .zip file containing your project directory) to terescoj AT strose.edu. (ii) Demonstrate the execution of your programs for your instructor. (iii) Hand a printout of the Java files that make up the programming assignment (not practice programs) to your instructor. (2 business day grace period for demos and printouts).
Grading
This assignment is worth 60 points, which are distributed as follows:
> Feature | Value | Score |
GrowingRectangle correctness | 10 | |
Spring Flowers Initial Design | ||
Sufficient detail to convey the basic design of Flower | 4 | |
Includes picture of flower layout with dimensions | 2 | |
Spring Flowers Style, Design, and Efficiency | ||
Appropriate comments | 3 | |
Good variable names | 2 | |
Appropriate variable declarations | 3 | |
Good use of constants | 4 | |
Appropriate formatting | 1 | |
Does not generate new objects unnecessarily | 2 | |
Good overall design and methods | 3 | |
Spring Flowers Correctness | ||
Initial stem drawn properly | 4 | |
Stem grows while mouse is dragged | 7 | |
Growth stops at specified height | 4 | |
Flower appears when height is achieved | 7 | |
Color changes when most recent petals clicked | 4 | |
Spring Flowers Extra Credit | ||
Nicer flowers | 3 | |
Total | 60 | |