For a program to compute the desired result it must proceed through a series of logical steps, transforming the inputs into outputs. Figuring out what those logical steps should be is the task of the programmer. |
Projects are multipart tasks that span a couple of weeks in which a significant computation is developed. |
Sign Finder accepts the day and month of a person’s birth and returns the person’s Zodiac sign | ||
In formulating the logic of the computation, specify the inputs and outputs first | ||
Input: A month and a day | ||
Output: The name of the Zodiac sign |
The radio buttons and the text box of the GUI are the means of presenting input | |||
The computation takes place when the OK is clicked | |||
Since clicking a radio button, entering the text box and clicking the OK command button are “events”, the program can be developed by considering what computation is needed in response to each event | |||
Month Radio Button -- set up the data for that month | |||
Day Value Entry -- save the data for later | |||
OK Command Button -- Determine the sign and print it | |||
How is the sign determined from the month and day? |
Notice that a person born in a given month could have one of two signs, depending on the day of birth | |
A July birthday | |
could be either | |
Cancer or Leo | |
Every month is | |
similar: There | |
are two signs | |
possible |
On The Selection Of A Month ...
When a month is chosen, remember the two signs that apply and the day when they change … when the birth day is chosen it is possible to pick the sign |
On The Specification Of The Day ...
The day is simply a number that is typed in | |
It should be saved in a variable for later use |
With the month chosen and the day chosen, it is possible to figure out the sign | |||
If the day is on the midpt or before, it’s the earlier sign | |||
If the day is after the midpt, it’s the later sign | |||
Having Brained Out The Logic ...
The following steps achieve the result | |||
Create the GUI | |||
Declare the four variables | |||
loSign, a string | |||
hiSign, a string | |||
midpt, an integer | |||
dayPick, an integer | |||
Set loSign, hiSign and midpt in radio buttons | |||
Set dayPick to the text input | |||
For the OK click event, incorporate the If-statement and set the visibility of the two labels |