Week 1: January 26 and 28, 2005
Week 2: January 31. February 2 and 4, 2005
Week 3: February 7, 9 and 11, 2005
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: February 14, 16 and 18, 2005
Week 5: February 21, 23 and 25, 2005
Week 7: March 7, 9 and 11, 2005
Week 8: March 14, 16 and 18, 2005
Hints. In problems 3.2 and 3.3 you will need to prompt a user for input from the keyboard -- you should use the 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. 134 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.
For each problem, hand in a copy of your program source code and a script file showing the I/O of typical program runs.
Due date: March 18, 9am.
Week 9: March 21, 23 and 25, 2005
Week 10: March 28 and 30. April 1, 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.
Due date: April 6, 9am.
Week 11: April 4, 6 and 8, 2005
prompt >> prompt >> java TidyTable number left right ========= ============ ============ 0/7: 0.0000 0.0000 1/7: 0.1429 0.1429 11/7: 1.5714 1.5714 111/7: 15.8571 15.8571 1111/7: 158.7143 158.7143 -11111/7: -1587.2856 -1587.2856 0: 0 0 10: 10 10 1000: 1000 1000 -1000000: -1000000 -1000000 ========= ============ ============ prompt >>The source code is: TidyTable.java We will use the doubleToString() and integerToString() methods in homework 4.
Weeks 12 and 13: April 11 through 22, 2005
prompt >> java Circle Wheel 1: Center is at (1.0,2.0): Radius = 2.0 Wheel 2: Center is at (5.0,3.0): Radius = 3.0 Wheel 2: Perimeter = 18.84955592153876 Wheel 2: Area = 28.274333882308138 prompt >>
Read pg's 511-515 of Austin/Chancogne.
Question 4.1. The two files that you will need are Complex.java and Quadratic.java .
After you have downloaded these files to your account, you can compile the program by simply typing:
javac Quadratic.java
Then start to fill in the missing details. As with the previous assignments, please hand in a copy of the program source code (i.e., Quadratic.java) and a script file showing I/O for a couple of typical program runs.
Question 4.2. Download the file DataMatrix.java and fill in the missing details in method print(). When you run the completed program, the output should look something like:
prompt >> java DataMatrix Matrix: A 1.0E-4 2.0 0.0 0.0 0.0 2.0 -23.0 -3000.0 0.0 0.0 13.0 -140.0 Matrix: B row/col 1 2 1 -2785.02 126.44 2 -3680.37 -2016.06 Matrix: C row/col 1 2 3 4 5 6 1 0.000 4.000 8.000 12.000 16.000 20.000 2 -9.999 -5.999 -1.999 2.000 6.000 10.000 3 -19.999 -15.999 -11.999 -7.999 -3.999 0.000 4 -29.999 -25.999 -21.999 -17.999 -13.999 -9.999 5 -39.999 -35.999 -31.999 -27.999 -23.999 -19.999 Matrix: C row/col 7 8 9 10 1 24.000 28.000 32.000 36.000 2 14.000 18.000 22.000 26.000 3 4.000 8.000 12.000 16.000 4 -5.999 -1.999 2.000 6.000 5 -15.999 -11.999 -7.999 -3.999 prompt >>
Question 4.3. The adjacent figure shows how triangles can be modeled using Vector, Node, Edge and Triangle classes.
The class Vector models two dimensional vectors characterised by (x,y) coordinate pairs. The class Node extends Vector. It adds a name. An edge line segment is characterised by its two "node" end points (i.e., The class Edge uses instances of class Node). Finally, the class Triangle uses three instances of class Node and three instances of class Edge.
To get started, download and compile the files Vector.java , Node.java , Edge.java and Triangle.java . These four files are the solution to homework 4, Fall Semester 2004, plus a code outline for testing whether a point lies inside/outside a triangle. Output from the complete program should look something like:
Test output with toString() method Triangle: "null" ================================= Edge("e1") connects nodes (n3, n1) Edge("e2") connects nodes (n1, n2) Edge("e3") connects nodes (n2, n3) Node("n3") is at (3.0,0.0) Node("n1") is at (3.0,4.0) Node("n2") is at (0.0,0.0) ================================= Perimeter = 12.0 Area = 6.0 Test pointInsideTriangle() method ... *** Point (1,1) is INSIDE triangle *** Point (3,1) is INSIDE triangle *** Point ( 3.5, 1) is OUTSIDE triangle *** Point (-3,1) is OUTSIDE triangle
Fill in the missing details in the pointInsideTriangle() method.
Related Hint. Paul Burke has prepared a nice discussion of this problem together with three solution approaches.
Week 14: April 25, 27 and 29, 2005
Week 15: May 2, 4 and 6, 2005
The ArrayList class in Java provides facilities for building lists of generic objects. To see how the class Arraylist works in practice, please download, compile, and run the files ArrayTest1.java , ArrayTest2.java , Triangle.java , Edge.java , and Node.java .
Program ArrayTest1 builds/prints a list of strings and then incrementally assembles a list of polygon edges and vertices. Finally, we use the java Iterator to walk along the polygon edges and compute the perimeter. The output is as follows:
Walk along list and print strings ================================= Name = node 1 Name = node 2 Name = node 3 Name = node 4 Name = node 5 Polygon node list ==================================== Node("p1") is at (0.0,0.0) Node("p2") is at (5.0,0.0) Node("p3") is at (5.0,5.0) Node("p4") is at (2.5,7.0) Node("p5") is at (0.0,5.0) Node("p6") is at (0.0,0.0) ==================================== Polygon edge list ==================================== Edge("e1") connects nodes (p1, p2) Edge("e2") connects nodes (p2, p3) Edge("e3") connects nodes (p3, p4) Edge("e4") connects nodes (p4, p5) Edge("e5") connects nodes (p5, p6) Edge("e6") connects nodes (p6, p1) ==================================== Polygon perimeter = 21.40312423743285 ====================================
Program ArrayTest2 builds a list of three triangles, adds them to a list, and then walks along the list printing contents of each object in a string format. The output is as follows:
Print triangles ================================= Triangle: "A" ================================= Edge("e1") connects nodes (n3, n1) Edge("e2") connects nodes (n1, n2) Edge("e3") connects nodes (n2, n3) Node("n3") is at (3.0,0.0) Node("n1") is at (3.0,4.0) Node("n2") is at (0.0,0.0) ================================= Triangle: "C" ================================= Edge("e1") connects nodes (n3, n1) Edge("e2") connects nodes (n1, n2) Edge("e3") connects nodes (n2, n3) Node("n3") is at (2.0,0.0) Node("n1") is at (-1.0,-4.0) Node("n2") is at (2.0,-1.0) ================================= Triangle: "B" ================================= Edge("e1") connects nodes (n3, n1) Edge("e2") connects nodes (n1, n2) Edge("e3") connects nodes (n2, n3) Node("n3") is at (1.0,0.0) Node("n1") is at (1.0,4.0) Node("n2") is at (1.0,1.0) =================================
Download the java source code and data files for the "blue pole" layout program. The contents of each file are as follows:
To compile the program simply type:
javac TriangleGUI.java
The java compiler is pretty smart!. It will automatically identify the dependecies among files and compile all of the java source code. To run the program in the appletviewer, type:
appletviewer TriangleGUI.html
Question 5.1.
In the prototype implementation,
blue poles are defined by their name and (x,y) position.
Extend the capabilities of Pole.java and the graphical user interface code
so that poles are also defined by whether or not they
contain a camera, and whether or not they are in service.
To help you get started, the revised version of Pole.java might look like:
public class Pole extends Node { protected Color color; protected boolean bHasCamera; protected boolean bInService; ... details of Pole.java go here ...
Variables "bHasCamera" and "bInService" will be either true or false. The extended pole.txt file might look like:
6 A 0.5 0.5 true true B 4.5 2.8 true true C 9.0 0.0 true false D 9.3 2.5 false true E 10.0 7.0 true true F 15.0 7.0 true true
Here, the fourth column of data indicates whether or not the pole contains a camera. The fifth columns of data indicates whether or not the pole is in service (notice that the pole beside A.V. Williams is, in fact, currently out of service!).
Extend Pole.java to account for the additional functionality. You will need new methods for setCamera() and setService(), and will need to extend the constructors and toString(). Unless otherwise indicated, assume that "bHasCamera" and "bInService" are false. Extend main() to exercise all of the new parts of Pole.java.
Then modify/extend PoleNetwork.java to read and process nodes in the extended file format shown above.
Note. To help you out, my solution uses ideas from "GettinStarted.java" and the "Demo Strings" programs that are in class reader. The output to my solution for the Pole program is:
Pole("A") is at (1.0,2.0) "Has camera" is false "In service" is false Pole("B") is at (3.0,8.0) "Has camera" is true "In service" is false
The output to my solution for the PoleNetwork program is:
List of Poles ================================= Pole("A") is at (0.5,0.5) "Has camera" is true "In service" is true Pole("B") is at (4.5,2.8) "Has camera" is true "In service" is true Pole("C") is at (9.0,0.0) "Has camera" is true "In service" is false Pole("D") is at (9.3,2.5) "Has camera" is false "In service" is true Pole("E") is at (10.0,7.0) "Has camera" is true "In service" is false Pole("F") is at (15.0,7.0) "Has camera" is true "In service" is true
What to Hand In.
You should be able to complete this part of the
assignment without using graphics at all.
Hand in a copy of your program source code indicating all places
where (just mark this up with a pen) where you have modified the code.
Also, hand in a script file demonstrating the new functionality of
Pole.java and PoleNetwork.java.
Question 5.2.
The prototype implementation allows a user
to click on a point that lies inside a building,
and the program will report the closest pole.
Modify the program functionality so that:
Hand in a screendump of the "blue pole" application program that shows the modified program functionality.
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 .
Week 16: May 9 and 11, 2005
Final Exam: May 19 (Thursday), 8.00am-10.00am. 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 January 2005 by Mark Austin
Copyright © 2005, Department of Civil and Environmental Engineering,
University of Maryland