Week 1: August 29 and 31, 2007
Week 2: September 5 and 7, 2007
Week 3: September 10, 12 and 14, 2007
Site IP addresses -------------------------------------------------- wam.umd.edu 128.8.10.141 128.8.10.142 128.8.10.143 glue.umd.edu 128.8.10.68 128.8.10.71 --------------------------------------------------
Week 4: September 17, 19 and 21, 2007
Unix Commands -------------------------------------------------------------------------------- 1. cd <-- change to home directory 2. cd file1 <-- change to directory file1 3. ls and ls -ls and ls -tl <-- list contents of a directory 4. mkdir file1 <-- make a directory called file1 5. rmdir file1 <-- remove directory file1 6. cp file1 file2 <-- copy file1 to file2 7. mv file1 file2 <-- move file1 to file2 -------------------------------------------------------------------------------- Note. Directories cannot be removed unless they are empty. Let's suppose that you have created a file and now you want to remove it. Try: 8. rm file1 <-- remoove/delete file1 Text editor commands -------------------------------------------------------------------------------- 1. vi filename <-- use vi editor to change contents of filename. For example, the command sequence: prompt >> cd ../pub prompt >> vi Welcome.html prompt >> vi resume.html prompt >> vi ce-systems.html moves your shell to the public directory and then systemantically creates the HTML files for your home page, resume and trip page. Notice that each file name has the "html" extension -- web browsers need this information. The class reader contains a list of basic editor commands. --------------------------------------------------------------------------------
Week 5: September 24, 26 and 28, 2007
Applications->Utilities.
For convenience, I suggest that you drag the Terminal icon to the finder window and/or the dock (this is Apple's counterpart of a short-cut in Windows).
By default, the Terminal window will run the bash shell. My recommendation is to change this setting to tsch. The command is:
prompt >> chsh -s /bin/tcsh user-name
Now, when you log in, the file .tcshrc will be automatically executed. Here are a few basic shell commands:
# aliases alias a alias alias cd '\!:0-$; set_prompt' alias cp 'cp -i' alias du 'du -ch' alias find 'find / -name \!* -print' alias grep 'grep -n' alias h 'history' alias rm 'rm -i' alias set_prompt 'set prompt = "`/bin/pwd` \!>> "' # Aliases specific to Apple PowerPC alias gv 'open -a Preview' alias safari 'open -a Safari' # set path and shell variables set filec set history=200 set savehist= (200 merge) setenv SVN_EDITOR vi test -r /sw/bin/init.csh && source /sw/bin/init.csh
If you want to know a lot more about Unix on the Mac, I suggest that you pick up a copy of McElhearn K., The Mac OS X Command Line: Unix under the Hood, SYBEX Inc, 2005.
prompt >> scp name-of-file login-name@wam.umd.edu:
Week 6: October 1, 3 and 5, 2007
Week 7: October 8, 10 and 12, 2007
Week 8: October 15, 17 and 19, 2007
Week 10: October 29 and 31. November 2, 2007
Week 11: November 5, 7 and 9, 2007
Solve problems 15, 17, 18, 19, and 21 in the Green Lecture Notes. For each problem hand in a copy of your source code, and a script showing input/output for a typical program run.
Due. 9am, November 16. Note. I will hand out solutions next Friday so that you have them available for midterm 2. Hence, this is a hard deadline (i.e. no extensions).
Hints.
Series = 1/3 + 1/(2*5) + 1/(3*7) + 1/(4*9) ....
Summing up the first 10 terms can be computed with something like:
double dSum = 0.0; for ( int i = 1; i <= 10; i = i + 1) dSum = dSum + 1.0/(i*(2*i+1.0));
The trick is to find a formula for the i-th term in the series, and then, it's just a matter of walking along the series and summing terms.
In my numerical experiments I use 100,000 terms and then just abbreviate the output showing a few of the first and last terms.
float [] fRainfall = { 1.1F, 0.8F, ..... 2.0F, 2.0F, 2.4F };
Also in the computation of statistical quantities you need return floats from the various methods. By default these calculations will be a double. So instead of writing something like:
return Math.sqrt(fSum/fA.length - fMean*fMean);
cast the result to type float, e.g.,
return (float) Math.sqrt(fSum/fA.length - fMean*fMean);
I believe that if both arguments to Math.min() and Math.max() are floats, then the result will automatically be a float. Hence there is no need to cast results to type float.
1.0 1.0 1.0 5.0 6.0 5.0 7.0 3.0 4.0 3.0 3.0 2.0 3.0 1.0
and then read the coordinates from the file. Here is an outline of my solution:
/* * ========================================================================== * PolygonAnalysis.java : This Java 2 program reads vertex coordinates for a * polygon from a datafile and computes a variety of properties..... * ========================================================================== */ import java.lang.Math; import java.util.*; import java.io.*; import java.text.*; public class PolygonAnalysis { // Create two-dimensional array to store polygon coordinates. static float[][] polygon = new float[7][2]; public static void main( String args[] ) throws IOException { float fXmin, fXmax, fYmin, fYmax; float fR, fRmin, fRmax; float fPerimeter = 0; float fArea = 0; // Read polygon data from "polygon.txt" and then print ... polygonInput(); polygonPrint(); // Compute and print min/max "x" and "y" coordinates ..... details of max/min coords removed .... // Compute and print min/max distance of coordinates from origin ...... details of max/min distance calculation removed .... // Compute and print the polygon perimeter ...... details of perimeter calculation removed .... // Compute and print the polygon area ...... details of area calculation removed .... } /* * ===================================================================== * Method polygonInput() : Read data coordinates from "polygon.txt" * and store in "polygon" array. * * Note. This input procedure assumes that the polygon is arranged into * two columns of input, each containing seven items: * * 1.0 1.0 * 1.0 5.0 * 6.0 5.0 * 7.0 4.0 * 4.0 3.0 * 3.0 2.0 * 3.0 1.0 * * The input procedure reads a complete line of input and then uses the * StringTokenizer to indentify "tokens" separated by blank spaces. * This strategy avoids the need for a fixed format of data input. * * Input : None. * Output : None. * ===================================================================== */ static void polygonInput() throws IOException { float f1, f2; String sline; int i = 0; FileReader inputFile = new FileReader( "polygon.txt" ); BufferedReader in = new BufferedReader( inputFile ); try { while( i <= 6 ) { // Read a new row of polygon coordinates -- this is a string. sline = in.readLine(); StringTokenizer st = new StringTokenizer(sline); // Extract the floating-point no's from the string. int j = 0; while( st.hasMoreTokens() ) { polygon[i][j] = Float.parseFloat( st.nextToken() ); j = j + 1; } i = i + 1; } } catch (FileNotFoundException e){} catch (EOFException e){} in.close(); } /* * =========================================================== * Method polygonPrint() : print details of polygon to screen. * * Input : polygon ... declared at top of the class. * Output : None. * =========================================================== */ static void polygonPrint() { for (int i = 0; i < polygon.length; i++) { .... details of polygon print removed .... } } }
Week 12: November 12, 14 and 16, 2007
Week 13: November 19 and 21, 2007
Week 14: November 26, 28 and 30, 2007
Solve problems 24, 25 and 36 in the Green Lecture Notes. For each problem hand in a copy of your source code, and a script showing input/output for a typical program run.
Also, please fill in the missing details in java code for modeling of a wheel cross section using triangle objects.
Figure. Cross Section Model of a Wheel.
A detailed description of the wheel program can now be found on the java examples web page. Click here to download a zip file of the abbreviated code. Unzip the file and look in the folder that is created. You should find the following files:
appletviewer DemoWheel.html
All of the required modifications are located in DemoWheel.java.
Please hand in completed details of DemoWheel.java and a screendump of your revised model. To assure authenticity, I suggest that you modify the problem parameters (e.g., change the number of intervals in the radial direction).
Due Date. 9am, December 10. No extensions.
Week 15: December 3, 5 and 7, 2007
Problem 24
An appropriate class declaration is:
public class Rectangle { protected Vertex vertex1; // First corner point.... protected Vertex vertex2; // Second corner point.... // Constructor methods .... public Rectangle() { vertex1 = new Vertex(); vertex2 = new Vertex(); } ... etc ...
My recommendation is that you implement a second constructor method where the coordinates are passed as arguments.
Problem 25
For problem 25, extend your code in problem 24. I would hand in two copies:
(1) for problem 24, and (2) an extended copy for problem 25.
Problem 36
This problem contains two parts.
First, you have to develop source code for rectangular blocks.
As indicated in the problem setup, a rectangular block is a rectangle with density
and thickness (hence you can compute mass).
Therefore, a suitable class definition is:
public class Block extends Rectangle { protected double density; // block density... protected double thickness; // block thickness... // Constructor methods .... public Block( double dX1, double dY1, double dX2, double dY2 ) { super(); vertex1.dX = dX1; vertex1.dY = dY1; vertex2.dX = dX2; vertex2.dY = dY2; } ... etc ...
In part 2, you need to build an arraylist of blocks. This is the block tower problem; here is a skeleton of source code:
/** * ================================================================= * BlockTower.java: This java simulates assembly of the block tower. * * Written by: Mark Austin December 2007 * ================================================================= */ import java.lang.Math; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class BlockTower { public static void main( String args[] ) { boolean TowerStable = true; int offset = 0; // Main loop for assembly of the block tower ... int BlockNo = 1; List blockList = new ArrayList(); while ( TowerStable == true ) { // Compute incremental offset for i-th block ..... offset = (int) ( Math.floor ((BlockNo - 1)/5.0) + (BlockNo-1)%5 ); if ((BlockNo-1)%5 == 4 ) offset = offset - 2; // Compute (x,y) coordinates of block vertices... // ... details of source code removed ..... // Create new block ... // ... details of source code removed ..... // Add block to tower .... // ... details of source code removed ..... // Compute (x,y) coordinates of tower centroid ... // ... details of source code removed ..... // Test for stability of tower ... // ... details of source code removed ..... // Update parameters .... BlockNo = BlockNo + 1; } // Print details of block tower .... // ... details of source code removed ..... } }
Computing the offset of the blocks is quite tricky (took me a couple of tries to get it right), so I am just leaving that part in the program. The abbreviated output is:
Add block 1 ========================= Total Mass =5.0 FirstMoment(X) =12.5 FirstMoment(Y) =2.5 Centroid(X) =2.5 Centroid(Y) =0.5 Tower of blocks is stable .... details of output removed .... Add block 14 ========================= Total Mass =70.0 FirstMoment(X) =350.0 FirstMoment(Y) =490.0 Centroid(X) =5.0 Centroid(Y) =7.0 Crash!! Tower of 14 blocks is unstable Details of Block Tower ================================ Block: Vertex(0.0, 0.0) Vertex(5.0, 1.0) density = 1.0 thickness = 1.0 area = 5.0 mass = 5.0 .... details of block tower removed .... Block: Vertex(5.0, 13.0) Vertex(10.0, 14.0) density = 1.0 thickness = 1.0 area = 5.0 mass = 5.0
Answer. 14 blocks.
Note. For each problem, hand in a copy of your program source code and a script of I/O for typical program usage. To create a script, type something like:
prompt >> script output-file
Now all input/output on the screen will be echoed to the file "output-file". To terminate the script, type:
prompt >> exit
Now print "output-file" and hand it in.
A
collection
is an object that groups multiple elements into a single unit.
Units include:
Collections are used to store, retrieve, manipulate, and communicate aggregate data. Typically, they represent data items that form a natural group.
/** * ============================================================== * ArrayTest3.java: Demo ArrayList Example in Handout... * * Written by: Mark Austin April 2006 * ============================================================== */ import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class ArrayTest3 { public static void main( String args[] ) { // Create and print a simple array of strings ..... List stringList = new ArrayList(); stringList.add("A"); stringList.add("Red"); stringList.add("Indian"); stringList.add("Thought"); stringList.add("He"); stringList.add("Might"); stringList.add("Eat"); stringList.add("Toffee"); stringList.add("In"); stringList.add("Church"); System.out.println("Use for loop to walk along list" ); System.out.println("=================================" ); for ( int i = 0; i < stringList.size(); i = i + 1 ) System.out.println("Name = " + stringList.get(i) ); System.out.println("Use Iterator to walk along list" ); System.out.println("=================================" ); Iterator iterator1 = stringList.iterator(); while ( iterator1.hasNext() != false ) { String s = (String) iterator1.next(); System.out.println("Name = " + s ); } } }
Week 17: .....
Developed in September 2007 by Mark Austin
Copyright © 2007, Department of Civil and Environmental Engineering,
University of Maryland