These programs are not necessarily very object oriented—they will mostly be small programs consisting of a class with a public static void main
method, and perhaps one or two other public static
methods. The purpose is to get you used to programming in Java, and to get you up to speed on some of the basics such as:
If you want to work together in teams of up to three people (you pick the teams) you may—or you may work individually.
A few rules for working together on this assignment:
Even if you work together, for this assignment, each person must still script and submit separately.
Each person on the team should "take the lead" on at least one of the three programs. Indicate who took the lead on each one in the comments. You might write something like this:
// H02a.java for CISC370, 06/13/07
// Programmers: Ella Fitzgerald (Lead), Cassius Clay, Keith Richards // Calculate height of a tree // ...
// H02b.java for CISC370, 06/13/07
// Programmers: Keith Richards (Lead), Cassius Clay, Ella Fitzgerald // Count words in a file // ...
// H02c.java for CISC370, 06/13/07
// Programmers: Cassius Clay (lead), Ella Fitzgerald, Keith Richards // Sort a list of integers // ...
For this assignment, your best bet is to use an internet search engine, along with the many Java resources on the web.
In a directory on strauss called ~/cisc370/h02, create and test source code for each of three programs indicated below.
Create a single script in which, for each of the three programs, you cat the source code for the program, show that the program compiles, and then show that the program works properly.
Note that for some programs, running it once may not be enough to show that it works properly. You may also need to
You are responsible for using your intelligence and judgment to determine what is needed.
In a 300-level class, it is not the responsibility of the Instructor or TA to spell that out for you in detail. We are available to help you brainstorm, and if you submit a detailed clear test plan sufficiently in advance, we might be willing to sign off that it is enough testing, but this is not guaranteed.
Write a program that helps a surveyor estimate the height of a tree (the green line) as shown in the picture below.
Inputs are the height of the leveling instrument, the angle theta (between level, and a sight-line to the top of the tree, in degrees), and the distance to the base of the tree.
Make simplifying assumptions as needed (i.e. level ground, the inaccuracy introduced by the thickness of the tree is insignificant to the measurement.) You may ask for measurements in feet or meters, as you see fit, but be sure to label your inputs and your outputs consistently with whatever unit you choose.
Use type double to represent all numeric values.
Things you will need to find out:
Write a program that takes the name of a file on the command line as the first input parameter. Open that file, and read each line. Count the total number of words in the file, and print the total on the "standard output" stream.
Produce an error message if there is not exactly one input parameter, or if the file cannot be opened. Write that message to the "standard error" output stream, not the standard output stream.
Consider "words" to be any sequence of one or characters "non-white-space" characters, where "white space" is defined (for purposes of this exercise) as sequence of 1 or more of space, tab (\t), newline/line feed (\n), carriage return (\r), or form feed (\f) characters.
Things you need to find out:
Write a program that takes the name of two files on the command line as the first and second input parameters:
The input file should consist of a sequence of integers, one per line. Your program should read every line in that file.
Your program should write an output file with the name given, consisting of the same integers, sorted, one per line.
Produce an error message if any of the following occur:
Things you need to determine:
Consider "words" to be any sequence of one or characters "non-white-space" characters, where "white space" is defined (for purposes of this exercise) as sequence of 1 or more of space, tab (\t), newline/line feed (\n), carriage return (\r), or form feed (\f) characters.
Submit your work on WebCT for the assignment marked H02. Upload and submit BOTH
If you do not know how to create a tar consult the following lab from CISC181 for an overview.
A reminder: even though your H02.tar (or tar.gz, or .tgz. or .zip file) contains your Java source, you are still required to "cat" this source code in your .txt file, and submit it in both forms. If you do not, you will lose points.
Here's why: Submitting both allows your TA the ability to
Of course, the two should agree—if they don't, that's also a potential grading deduction. So if you make changes to your code, be sure that you redo both your script, and your tar/zip file.
Now read Chapters 5-6 for Thursday. As you read, you may want to apply the typo corrections from the errata to your book.
Part | Item | Description | Points |
---|---|---|---|
H02a | Functionality | The program actual works—it does what it is supposed to do when you run it | 20 |
Style | The program is well commented. Someone reading the program can follow your logic and understand how the program works. | 20 | |
Scripting | Your script clearly demonstrates the functions of the program, and includes a reasonable amount of testing. | 10 | |
H02b | Functionality | The program actual works—it does what it is supposed to do when you run it | 20 |
Style | The program is well commented. Someone reading the program can follow your logic and understand how the program works. | 20 | |
Scripting | Your script clearly demonstrates the functions of the program, and includes a reasonable amount of testing. | 10 | |
H02c | Functionality | The program actual works—it does what it is supposed to do when you run it | 20 |
Style | The program is well commented. Someone reading the program can follow your logic and understand how the program works. | 20 | |
Scripting | Your script clearly demonstrates the functions of the program, and includes a reasonable amount of testing. | 10 | |
All | Following Directions | All submitted files (e.g. script, tar, gzipped tar, or zip file) are submitted according to directions. | 30 |
TOTAL POINTS |