CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
 
Wait , WAIT !!What's that word ? ( Class Notes ( without definitions ) )

Wednesday September 6 , 2000
 
Problem
A necklace is constructed from 20 blue beads and 14 red beads.   Each blue bead costs $ 0.22 while each red bead costs $ 0.33.   The cost of the thread is $ 0.14 per inch,  and 24 inches are required. 

Informal solution Description
To determine the total material cost (i.e,  to solve the problem) we need only use problem decomposition and solve the following subproblems:

  • Find the cost of the blue beads.
  • Find the cost of the red beads.
  • Find the cost of the thread.
Some times problem decomposition is applied at many levels in solving a problem.   In this case,  we can apply it to solving each of the problems.
  • we can find the blue bead cost by
    • Determining the number of blue beads.
    • Determining the cost of each blue bead.
  • we can find the red bead cost by
    • Determining the number of red beads.
    • Determining the cost of each red bead.
  • we can find the thread cost by
    • Determining the price per inch of thread.
    • Determining the length of the thread.
Note:   that each of the subpoints are trivial. 

It is time to write the program! 

Remark
We concieved of the solution in a ``top-down'' manner.
Remark
When coding the solution we will have to type the Java in a ``Bottom-up'' manner.
Remark
Whenever you write a program in this class you must artfully name all values - within reason. 

< CLASS > --- > TheNecklasApp 

< PROGRAM > --- >

/ /Determine the cost 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 ( ``total cost of materials is:   ``);
IO.print (totalCost);
IO.println (); 

The Enviornment
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 

Something for you to consider doing...
Go to the ``CS1 at Oswego'' site,  click on ``Documentation'' and find your way to the emacs command summary.
Print your vary own,  approximatly,  8 page manual,  one page at a time.
Put it in your notebook.   Bring it to lab. 

Another Problem
The squares in the following figure are congruent.   Their collective area is 187.32 square units.   What is the perimiter of the figure? 

Remark
This problem can readily be solved by application of the problem solving strategy known as ``Global Directed Planning.''
Remark
Goal Directed planning is a ``procedural'' variant of problem Decomposition,  which we discussed last class.