Week 1: August 31, September 2, 2005
Week 2: September 5, 7 and 9, 2005
Week 3: September 12, 14 and 16, 2005
Week 4: September 19, 21 and 23, 2005
` After four and a half years of labor, InPhase is preparing for the September 2006 pilot launch of a holographic disc drive that can read and write 300 GB discs, and is planning a 5 GB chip for consumers the following year. The technology will initially be used for high-end archiving in data centers, financial organizations, and medical facilities, while high-definition digital video broadcasting and movie distribution for digital theaters is another market InPhase is aiming for. Addressing unresolved issues about the technology's cost and reliability is critical if holographic storage is to successfully penetrate the mainstream. Almaden Research Center's Hans Coufal says holographic storage is "very impressive but is still some ways away from a viable product." For more info, click here .
Week 5: September 26, 28 and 30, 2005
Week 6: October 3, 5 and 7, 2005
Week 7: October 10, 12 and 14, 2005
Hints. In problem 3.4 you will need to use a looping construct to systematically increment x from 0 m to 1 m in increments of 0.2 m. See pg's 122-124 of the class reader for examples of "for" and "while" looping constructs.
If you are on the wam or glue systems, you will need to type:
tap java
This will make the java compilers available to the machine that you are logged on to. Then to compile and run a program type something like:
javac Peace.java java Peace
In problem 3.5 you will need to prompt a user for input from the keyboard. One approach is to use method keyboardInput() to read a line of text from the keyboard and return it to the calling program as a string. For the relevant details, see pg. 142 of the class handout. See sections 18.11.9 and 18.11.10 in Austin/Chancogne for an explanation of keyboardInput() and the process of converting the string to an appropriate numerical format.
When you compile a program containing keyboardInput() the compiler will complain that the method "read" has been deprecated -- this means that while "read" still works, a new better approach is now available. For details on the new approach, see the ReadTextFromConsole program program on the java examples page.
For each problem, hand in a copy of your program source code and a script file showing the I/O of typical program runs. The procedure for creating a script file is explained in FAQ 21 (see pg. faq-9 of the class reader).
We are behind schedule ... and I messed up with the dates....
New Due date: October 28, 9am.
Week 9: October 24, 26 and 28, 2005
Week 10: October 31. November 2 and 4, 2005
For each problem, hand in a copy of your program source code and a script file showing the I/O of typical program runs. The procedure for creating a script file is explained in FAQ 21 (see pg. faq-9 of the class reader).
Note. The syntax for the Math.min and Math.max functions is:
Math.min ( double , double ) Math.max ( double , double )
Arguments can also be of type float and integer (int). Hence, Math.min(2,3) should return 2.
My solution to the windforce problem does not contain objects .. hence, the function declaration is:
static double windForce ( .... )
and not public double windForce ( .... ). Sorry about that.
Homework 3 will be due November 4, 9am.
Week 11: November 7, 9 and 11, 2005
Hints. Problem 3.16 is the most straightforward. You will need an array to store the seven nodal points for the polygon. The nodal points have been organized so that when you traverse the polygon perimeter, you will travel in a clockwise direction. Your solution procedure for the area calculation should exploit this fact. Click here for a skeleton code for the solution. This code reads the coordinates from a file polygon.txt .
For problem 3.18, download, compile, and run the Complex.java file. Notice how code the main() method systematically exercises the operations for complex number arithmetic. Then, write a file GeometricSeries.java that prompts a user for the appropriate input and then computes the series summations by calling methods in Complex.java.
To help you get started, here is a skeleton of code for GeometricSeries.java . A sample script of program i/o is:
Script started on Fri Nov 11 08:36:43 2005 prompt >> prompt >> java GeometricSeries Welcome to the Geometriic Series Computer ----------------------------------------- Please enter complex number "a" Coefficent a : Real : 1.0 Coefficent a : Imaginary : 2.0 Please enter number of terms in series "a" No of terms in series : 3 The complex no you have entered is :s = 1.0+2.0i No of terms in series is = 3 Summation with basic for-loop ======================================= Summation 1 = -13.0+4.0i Summation using Horner's formula ======================================= Summation 2 = -13.0+4.0i Summation with geometric-series formula ======================================= Summation 3 = -13.0+4.0i prompt >> prompt >> java GeometricSeries Welcome to the Geometriic Series Computer ----------------------------------------- Please enter complex number "a" Coefficent a : Real : -1.0 Coefficent a : Imaginary : 3.0 Please enter number of terms in series "a" No of terms in series : 12 The complex no you have entered is :s = -1.0+3.0i No of terms in series is = 12 Summation with basic for-loop ======================================= Summation 1 = -788535.0-383985.0i Summation using Horner's formula ======================================= Summation 2 = -788535.0-383985.0i Summation with geometric-series formula ======================================= Summation 3 = -788535.0-383985.0i prompt >> prompt >> exit script done on Fri Nov 11 08:37:20 2005
Notice that because we are working with complex number arithmetic here, "1" needs to represeted as "1 + 0i"....
For problem 3.12, I suggest that you start with the Vector.java, Node.java and LineSegment.java code on the "java examples" web page. I will cover the mathematical details of the solution in class. You will need to add and test a few methods to the Vector.java file:
// Compute magnitude of vector .... public double length() { .... // Vector addition and Subtraction ... public Vector2D add( Vector2D v1 ) { .... public Vector2D sub( Vector2D v1 ) { .... // Scale vector by a constant ... public Vector2D scale( double scaleFactor ) { .... // Normalize a vectors length... public Vector2D normalize() { .... // Dot product of two vectors ..... public double dotProduct ( Vector2D v1 ) { .....
Now you can write a new method:
public double distanceToPoint( Node pt1 ) { ...
in LineSegment.java. The abbreaviated details are as follows:
/* * =========================================================================================== * LineSegment.java: A line segment is defined by the (x,y) coordinates of its two end points. * * Written By: Mark Austin November, 2005 * =========================================================================================== */ import java.lang.Math; public class LineSegment { protected Node n1, n2; // nodal points defining the LineSegment // .... details removed ..... public LineSegment() { } // Compute min distance from line segment to point ... public double distanceToPoint( Node pt1 ) { // .... fill in details here .... } // --------------------------------------- // Exercise methods in line segment class. // --------------------------------------- public static void main( String args[] ) { double dX, dY; System.out.println("LineSegment test program"); System.out.println("==============================="); // Create two new line segments. LineSegment s1 = new LineSegment(); s1.setLineSegment( 1.0, 1.0, 4.0, 4.0 ); // Print details of line segments. s1.printSegment(); // Compute distance of a point from a length segment.... Node pt1 = new Node ( "pt1", 0.0, 0.0 ); System.out.println( pt1.toString() + ": Distance to line = " + s1.distanceToPoint( pt1 ) ); Node pt2 = new Node ( "pt2", 1.0, 0.0 ); System.out.println( pt2.toString() + ": Distance to line = " + s1.distanceToPoint( pt2 ) ); Node pt3 = new Node ( "pt3", 5.0, 1.0 ); System.out.println( pt3.toString() + ": Distance to line = " + s1.distanceToPoint( pt3 ) ); Node pt4 = new Node ( "pt4", 6.0, -1.0 ); System.out.println( pt4.toString() + ": Distance to line = " + s1.distanceToPoint( pt4 ) ); // End of exercise. System.out.println("==============================="); System.out.println("End of LineSegment test program"); } }
Due Date. November 18.
Week 13: November 21 and 23, 2005
Week 14: November 28 and 30, December 1, 2005
Part 1.
Download, compile and run the Triangle application code from the "java examples" web page.
Notice that the code can compute whether or not a point is inside the triangle.
Extend the functionality of this program so that you can compute the distance from the triangle to a point. The point may or may not be inside the polygon.
Hint. This problem boils down to computing the distance of a point from three line segments defined by the edges along the perimeter of the triangle. Hence, my solution adds the method:
public double distanceToPoint( Node pt ) { ....
to Edge.java. You should test that this works before moving on. Then simply add a second method,
public double distanceToPoint( Node pt ) { ....
to Triangle.java. This second version simply calls the distanteToPoint() ... method associatged with the edges, e.g.,
edge1.distanceToPoint( Node pt ) .....
etc ....
For the graphical user interface, I started with DemoGUI.java on the java examples web page. I made one small change to the class definitions .... i.e., change
class DemoGraphicsScreen extends Canvas { ....
to
class DemoGraphicsScreen extends JPanel { ....
and then adjust the drawText() and gsDraw() methods. You should be able to click on the canvas and compute the distance from a specific triangle (just go ahead and make one up). I defined my triangle at the top of the constructor for DemoGraphicsScreen. e.g.,
class DemoGraphicsScreen extends JPanel { .... Triangle t; // Here is the constructor ..... public DemoGraphicsScreen () { t = new Triangle(); t.node1 = new Node(); t.node2 = new Node(); ....etc...
Part 2.
Download the source code to the polygon analysis program, compile it, and then
fill in the missing details of source code.
Most of the missing details are to do with the
computation of engineering properties (e.g., area, moments of inertia).
A few details require drawing of strings/labels on the canvas.
You can download the source code: (1) as individual java, xml and dtd files, or (2) as a tar file, which will be unpacked. Here are the details:
Download Individual Files
The "abbreviated" source code is contained in the following files:
The java source code files should be easy to download. Some web browsers will try to display the xml files ... the result might be an empty screen or perhaps a row of numbers. You can grab the original "xml" file by looking a "view source" in the edit (or view) pulldown menu and then cutting/pasteing the file contents.
You will need to put the files grid.gif, line.gif
and move.gif in a folder/directory called icons.
Download and unpack a tar file
Click here to download the tar file "demo-polygon1.tar" to your UNIX account. To unpack the tar file, type:
tar xvf demo-polygon1.tar
The command will create a folder/directory called demo-polygon1.d containing all of the java, xml and dtd code.
Compiling and running the application
To compile the program type:
javac PolygonGUI.java
If you click on the "load" button at the bottom of the window, then the file "polygon.xml" will be loaded into the system. To load specific files (e.g., polygon-bridge.xml) into the analysis package, click on the "File" pulldown menu, then "Open..." A FileChooser window should pop up on your screen with xml files highlighted. I have only tested this in the Mac OS X, so please let me know if this doesn't work on your system!!!!!
All of the missing blocks of code are in PolygonGUI.java and PolygonAnalysis.java and are labeled:
// INSERT MISSING DETAILS HERE .....
You will need to write code for:
Screendumps (or screen shots) on Linux/Unix Systems
On systems running the X Window System, the standard utility to dump an image of an X Window is xwd(1), The program xwd produces XWD X Window Dump image data. It can be invoked in the following way:
xwd -root -out root.xwd
xwd can also be used to dump a single window if provided with the -id option followed by the corresponding window id, for further info see man 1 xwd [1] (http://www.hmug.org/man/1/xwd.html). When run remotely, xwd is useful for taking screen shots of modal menus in action.
For more info, see: Answers.com: Screenshot .
What to Hand In ...
For each question, hand in a copy of your source code and a screendump of each application. To simplify the grading, please highlight your source code with the sections of code you have actually written ....
Due Date. Monday 12th December. 9 am. No extensions. I will hand out my solutions on Monday and bring the graded papers to the final exam.
Week 16: December 12, 2005
Last class -- Monday!!! Hopefully it will not snow .... I will go over the assignments and give you my thoughts on the final exam and how to study for it.
Week 17: December 19, 2005
The final exam will be open book and open notes. There are three questions. Question 1 is on basic java concepts (30 pts). Question 2 is on java program development (30 pts). Question 3 is on java program development with graphical user interfaces (30 pts). Make sure that you bring Austin/Chancogne to the exam.
Developed in August 2005 by Mark Austin
Copyright © 2005, Department of Civil and Environmental Engineering,
University of Maryland