ICS 111, Introduction to Computer Science
Lab 17 - Files / Methods
Note: Only one lab for this week.
It will be due on Sunday at 12:00pm noon.
Make sure that you logout from the computers when you leave
the lab or other persons may see your stuff or use your account to do "bad"
things.
Instructions:
To receive credit for this lab assignment, you must be finished by
Sunday, November 7, at 12:00 p.m. noon. After this time you will not receive any credit. Future lab assignments will be due by 11:59 p.m. on the day of the lab assignment.1. Log in to UH UNIX (Secure Shell in Windows)
- If you are in the lab, go to the Start Menu, then Programs,
and look for 'SSH Secure Shell Client'. If you're at home, a good program to use to connect to
UH UNIX
is Putty (click here to download).
The putty program is an executable and doesn't need to be installed.
- Host name is: uhunix.its.hawaii.edu
- Your user name is the first part of your UH e-mail address.
If your UH email address is 'frank@hawaii.edu', your user name would be 'frank'.
Your password is the same as your e-mail password.
2. Create and edit a file in Pico (Getting Started with Pico), named LabX.java (substitute the X for the lab number- e.g. Lab5.java)
Do the following:
First, create an input file in pico. You may call it whatever you want. In that file, put the following:
hello 54.239 12 Joe Frank
63.123113 90098.23 Blanca 23 23432432
blah this is
23423 a sdafs 999.123 test
book 1 56.1254 next car 7563
testing
102.36 house
Have your program ask the user for a file to open.
If the file doesn't exist, the program should print a user friendly message
and exit the program.
If the file exists (we'll specify the input file above
that you made), do the following steps:
Read a line of the file at a time, until there are no
more lines in the file.
For each line of the file, split up the line based on a
space. For instance, in the file above- the last line of the
file contains two tokens: "102.36" and "house".
For each token do the following:
Analyze each token of the file, and if it is a number,
then write the number to an output file. If the token is not a number,
then write the token to the screen.
In between each line of input you read from the input
file, output a line of dashes to your output file and to the screen (such as
System.out.println("-----------------------------"); for the screen part),
so that you can visually see in your output where each line of the input
file starts and ends.
When you output tokens to either the screen or the
file, print the number of tokens remaining on the line, as well as the line
number of the input file that you are on. (Something like: 3 tokens
remaining on line 2)
Finally, print the total number of tokens that were
numbers, and the total number of tokens that were not numbers.
Note: When you test your program you should
try it without the input file so that you make sure that your program will
not crash. In other words, you try it with and without the file and
make sure that your program works without crashing.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
You must also follow all of the commenting guidelines. Be sure to visit the link and check that your code follows all of the guidelines. Failure to do so will result in a deduction of points.
* Your program must compile without any errors, and must run properly to receive credit for this lab.
3. Get into Pine (Getting Started with Pine, PDF) and attach the Java (.java) file to an e-mail (See pages 11-12 in Getting Started with Pine, PDF).
- Send the file to ics111-lab@hawaii.edu account.
- control <J>, then control <T> allows you to browse and pick the file that you wish to attach. Only submit the .java file. Do not submit the .class file.
- Your e-mail should have the following subject: lab X / lastname (lab X should be substituted with the lab number, and lastname should be substituted for your lastname... e.g. Lab 5 / Sharritt). Not following this standard will result in a deduction of points.
4. Check the webpage to make sure that the e-mail arrived. Note that this will be sent to the ICS 111 lab address (ics111-lab@hawaii.edu). This one is different from the ics111-homework@hawaii.edu. There are two different ones so we can have homework assignments and lab assignments separate.
Here are the URLs:
http://www2.hawaii.edu/~tp_200/bmf/ics111-homework.html
http://www2.hawaii.edu/~tp_200/bmf/ics111-lab.html
5. Once we (TAs) get the e-mail in our account AND we can verify it on the web, we will grade your lab. For grading policies on your lab, click here...
Link to the Java API - to look up any methods of any class you would like to use.
Link to the Java Coding Standard - to look up Java code formatting rules.