ICS 211 Homework H00: Printing a file’s contents.

Purpose

A quick refresher on creating a Java program that prints out the contents of a file in different ways.

This assignment will give you practice using Eclipse to create a Java program that takes a parameter from the command line.

Tasks

1. Create a Java project in Eclipse called ICS211-workspace

This project is where we will be doing all our homework assignments for ICS 211. Here’s a screen shot of my Eclipse with my ICS211-workspace project. eclipse

2. Create a package named edu.ics211.h00

This is where we will put all our classes for homework 00.

3. Create a program FileDump that will print out the contents of any file.

FileDump should read in the name of a file from the command line.

I recommend you create a method for each of the different outputs. Use the FileReader to read the contents of the file a byte at a time. Then you can convert the byte to the correct representation you want to display.

  1. Hint you can use Integer.toBinaryString(val) to create a String with the binary representation of val.
  2. Hint you can use Integer.toHexString(val) to create a String with the hexadecimal representation of val.
  3. Hint you can use the String constructor new String(byte[], “UTF-8”) to create the string representation.

Here is an example of the output for the file Hello.txt. I put spaces between the binary and hexadecimal byes, but didn’t in the string representation. The output of the program should look like:

Binary contents of Hello.txt:
01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 
01100100 00100000 01100110 01110010 01101111 01101101 00100000 01001001 01000011 01010011 
00100000 00110010 00110001 00110001 00101110 00001010 01010100 01101000 01101001 01110011 
00100000 01101001 01110011 00100000 01110100 01101000 01100101 00100000 01110011 01100101 
01100011 01101111 01101110 01100100 00100000 01101100 01101001 01101110 01100101 00101110 

Hexadecimal contents Hello.txt:
48 65 6c 6c 6f 20 57 6f 72 6c 
64 20 66 72 6f 6d 20 49 43 53 
20 32 31 31 2e 0a 54 68 69 73 
20 69 73 20 74 68 65 20 73 65 
63 6f 6e 64 20 6c 69 6e 65 2e 
 
UTF-8 contents Hello.txt:
Hello World from ICS 211.
This is the second line.

What is the output when you use elipsis.png as the file?

Getting Eclipse to ask for a command line argument.

You can configure Eclipse to ask the user for any number of command line arguments. From the Menu choose “Run -> Run Configurations”. You will see a dialog similar to:

Run Configurations Dialog

Select the (x)= Arguments tab.

Arguments tab

Then click in the Program Arguments: field and choose the “Variables..” button. Scroll down till you see the string_prompt choice.

String prompt variable

Choose ok.

When you run your program you will see a dialog box like

Args

This is where you can supply the file name.

Grading Rubric

CriterionExcellent (100%)Satisfactory (75%)Borderline (50%)Unsatisfactory (25%)Poor (0)
Adherence to standards - 2 points
Does it conform to standards in every detail?
No errors. Minor details of the assignment are violated, or poor choices are made where the assignment is unclear. Significant details of the assignment or the underlying program intent are violated, but the program still fulfills essential functions. Significant details of the assignment or the underlying program intent are violated, but the program still fulfills some essential functions. Misses the point of the assignment.
Breakdown (modular design) - 1 point
Does it demonstrate good modular design?
No errors. 1-3 minor errors. > 3 minor errors OR 1 major error. 2 major errors > 2 major error.
Correctness of code - 4 points
Does it work? Does it pass JUnit?
Passes all tests. Works for typical input, may fail for minor special cases. Fails for typical input, for a minor reason. Fails for typical input, for a major reason. No.
Documentation, and style - 2 points
Is it clear and maintainable? Does it pass CheckStyle?
No errors. 1-3 minor errors. > 3 minor errors OR 1 major error. 2 major errors > 2 major error.
Efficiency of code - 1 point
Does it use the Java features well?
No errors. 1-3 minor errors. > 3 minor errors OR 1 major error. 2 major errors > 2 major error.

Turning in the Assignment

The assignment is due on Thursday at 11:55pm. You may turn it in early.