Computer Science 120
Introduction to Programming
Fall 2011, Siena College
Before you know it, the snow will melt and the flowers will bloom. But for now, we'll rely on you to write a program to display some spring flowers.
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 festive spring flower appears. 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.
Lab Preparation
To make our limited lab time as productive as possible, please do the following before coming to your lab meeting:
As part of the design, you should also draw the layout for one of the flowers your program will generate, including the graphical objects that it will include and labelling important dimensions and locations.
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.
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, but as you drag the mouse around, it should grow. 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.
A working solution for this program will appear below. Click inside the applet to interact with it.
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 constructor should expect three parameters: the Location where the Flower's stem should be planted, a double specifying the maximum height of the Flower, and the canvas. The Flower class should define the following methods used by the controller to implement the functionality described above:
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 two bonus points may be awarded for especially nice flowers.
Submitting Your Work
Before the start of your next lab session, submit your Java program for grading. There are three things you need to do to complete the submission: (i) place a copy of your Java program into your csis120/hw folder under hw4, (ii) print a copy of your program and hand it to your lab instructor, and (iii) demonstrate the execution of your program for your instructor.