CISC370, Homework H02, Summer 2007
Basic Java Skills

Due: Tuesday 06/19, 11:55pm

Better: Do half tonight, half Wednesday night

Introduction

In this assignment, you'll create three small Java Programs.

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:

You may collaborate—provided you document your collaboration

If you want to work together in teams of up to three people (you pick the teams) you may—or you may work individually.

If you work together...

A few rules for working together on this assignment:

Required Reading

For this assignment, your best bet is to use an internet search engine, along with the many Java resources on the web.

Overview

What you need to do

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.

Think carefully about your scripting strategy.

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.

 

H02a.java: A program to calculate the height of a tree

Write a program that helps a surveyor estimate the height of a tree (the green line) as shown in the picture below.

Picture of surveying instrument measuring height of a tree

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:

H02b: Write a program to calculate the number of words in a file

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:

H02c: Write a program to sort a list of integers

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.

 

Finishing and Submitting: Create a tar or zip file, and turn it in on WebCT

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.

Reminder: Submit your code both in your .txt file and in your .tar file

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.

Next Steps: Read Chapters 5-6 in HFJ

Now read Chapters 5-6 for Thursday. As you read, you may want to apply the typo corrections from the errata to your book.

Grading Rubric (180 pts total)

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    

Due Date: (see top of file)


Valid XHTML 1.0 Valid CSS!