ICS 111, Introduction to Computer Science
Lab 16 - Files / Methods
Note: Only one lab for this week.
It will be due on Thursday at 11:59pm.
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
Thursday, October 28, at 11:59 p.m. 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:
Program will display a menu to work with files
Menu options:
1. Find if a given file exists
2. Write information to a file
0. Exit
Option 1 specifications:
Create a boolean method fileExists, no parameters). Here is the process and requirement for menu option 1:
Need to ask for a filename to name the file. filename must be at least 3 (non blank) characters long. you will need to do this in a separate method. The method should return a String filename. This method will take no parameters. The method will consist of a loop that will not end until the user enters a valid filename.
Once you get the filename use it to find out if it exists. Hint: Use try/catch and the FileNotFoundException.
This should be done in a boolean method that will take no parameters and it will return true if the file exists and false otherwise.
Option 2 specifications:
Create a void method writeToFile, no parameters) Here is the process and requirements
- Need to ask for a filename to name the file. filename must be at least 3 (non blank) characters long. you will need to do this in a separate method. The method should return a String filename. This method will take no parameters. The method will consist of a loop that will not end until the user enters a valid filename.
- Create the file (no need for an extra method)
- Read information from the user and write it to the file (no need for an extra method)
Notice
that for both option 1 and 2 you will need to read a filename from the user.
This is the perfect opportunity to create a method that you can reuse for
two different purposes. The common method should be called:
readFilename it will take no parameters and it will return a String
containing the filename of the file to be found.
Your program should loop around until the user chooses
to exit the program.
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.