Return to Jeff's Main Page

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
My Intro to Object-Oriented Programming  
 
 
 
Class Notes

Wednesday September 6 , 2000
 
CG began class with definitions for binding and environment.   He then began a demonstration of these new concepts (and concepts already learned) through a sample problem which determined the cost of constructing a necklace given prices and quantities for thread and beads.   This problem was attacked using the problem solving strategy called ``problem decomposition'' (see definitions).   CG noted that it will be important in this class to artfully name all variables (variable names always begin in lowercase) within reason.   The sample problem and the definition of problem decomposition took nearly the entire class session.   Here is the code:
class NecklaceApp
/ /Determine the costs of the blue beads. 

double costPerBlueBead = 0.22;
int nrBlueBeads = 20;
double blueBeadCost = costPerBlueBead * nrBlueBeads; 

/ /Determine the cost of the red beads. 

double costPerRedBead = 0.33;
int nrRedBeads = 14;
double redBeadCost = costPerRedBead * nrRedBeads; 

/ /Determine the cost of the thread
double costPerInchOfThread = 0.14;
double lengthOfThread = 24.0;
double costOfThread = costPerInchOfThread * lengthOfThread; 

/ /Solve the original problem by making use of the
/ /solutions to the three main subproblems.
double totalCost = blueBeadCost + redBeadCost + costOfThread; 

/ /Display result. 

IO.print (``The total cost of materials is ``);
IO.print (totalCost);
IO.println (); 

The Environment  

costPerBlueBead ------ > 0.22
nrBlueBeads ------ > 20
blueBeadCost ------ > 4.4
costPerRedBead ------ > 0.33
nrRedBeads ----- > 14
redBeadCost ------ > 4.62
costPerInchOfThread ------ > 0.14
lengthOfThread ----- > 24.0
costOfThread ----- > 3.36
totalCost ------ > 12.38