Synopsis
I wasn't here today because I was out of town on business but a friend gave me a copy of the notes to add to my own.
What was talked about was what to do on the class notes section of the site. Of the options presented I am doing a mix of rendering the lectures as they are given and when necessary doing a paragraph on topics that are touched on and that is not directly related to the notes (eg. lab notes, site notes etc. ).
Also discussed was that on the Programming Challenge 1 blue.shapes. * is off limits. You need to compute things manually. blue.shapes. * can be used in Challenge 2.
As for topics covered in this class, the Rectangle class was introduced and problems shown on how to use this class to do various tasks.
|
Specification of the Rectangle class.
Constructor
new Rectangle (< double length >, < double width >) - > Rectangle
Operator
< Rectangle > .length () - > < double >
< Rectangle > .width () - > < double >
< Rectangle > .area () - > < double >
< Rectangle > .perimeter () - > < double >
< Rectangle > .diagonal () - > < double >
Commands
< Rectangle > .display ()
|
Suppose we have a city block of length 480 and width 300 partitioned into 16 rectangular lots as shown in the figure below (not shown here).
Tasks:
1) Model the block and a lot in terms of rectangles.
double blockLength = 480;
double blockWidth = 300;
Rectangle block = new Rectangle (blockLength, blockWidth);
double lotLength = blockLength / 8;
double lotWidth = blockWidth / 2;
Rectangle Lot = new Rectangle (lotLength, lotWidth);
|
2) Display the distance from one corner of the block to the far corner.
IO.println (block.diagonal ());
|
3) Declare a variable called PC and bind it to the percent of the block take up by one lot.
double pc = (lot.area () /block.area ()) * 100;
|
Problem:
What is the surface area of a cylinder of height 28.5 and diameter 11.6?
Note:
The surface area of the cylinder is equal to:
\beingul
Area of the top +
Area of the bottom +
Area of the side
Note:
We are using
problem decomposition
.
Note:
We can ``explode'' the cylinder into its parts. Two circles and a rectangle. Take the circumference of the top and bottom rectangle and the length /width of the inner rectangle.
The Java Program
Class > - > SurfaceAreaApp
Needs > - > import blue.shapes. *;
Program > - >
/ /Establishing the given information
double cylinderHeight = 28.5;
double cynlinderDiameter = 11.6;
/ /Create the top
double topRadius = cylinderDiameter / 2.0;
Circle top = new Circle (topRadius);
/ /Create the bottom
double bottomRadius = topRadius;
Circle bottom = new Circle (bottomRadius);
/ / < type > < id > = < expression >
/ /int i = 3;
/ /Circle top = new Circle (topRadius);
/ /Create the side
double sideHeight = cylinderHeight;
double sideLength = top.perimeter ();
Rectangle side = new Rectangle (sideHeight, sideLength);
/ /Compute the surface area of the of the cylinder
double sa = top.area () + bottom.area () + side.area ();
/ /Display the result
IO.println ( ``The surface area = ``+ sa + ``square units.'');
|
A note on string manipulation:
< string > + < string > - > < string >
Ex: ``sun'' + ``shine'' - > ``sunshine''
? on
knowledge
Ex.cont
< string > + < double > - > < string >
The double is converted to a string
Ex:
``x = '' + 5.2
means ``x = '' + ``5.2''
means ``x + 5.2''