If you haven't finished your previous Unix tutorials do them now.
Use the gedit editor to type the following program. The name of the file must be AddTwoNumbers.java. Specify the name of the file in the command.
Use gedit to add the following lines to the start of the program:
// Name: AddTwoNumbers.java // Purpose: Input two numbers and display their sum // Author: Tim Whitfort
Use gedit to change the line to display the sum, from:
System.out.println(sum);
to:
System.out.println("The sum is = " + sum);
To compile the program type the following command in a terminal window:
javac AddTwoNumbers.java
If you have any syntax errors they will be displayed on the screen.
Use gedit to edit the program. Look at the listing above and try and fix the errors.
If you can't fix the problem see your tutor for help. You are not expected to know Java, so don't spend too much time before you get help.
To run the program type the following command:
java AddTwoNumbers
You are required to demonstrate your understanding of some commonly used Unix commands.
Create a text file called q8Commands.txt. Each line of the file is to contain a command number and the UNIX command required to do the commands described below:
The start of the file q8Commands.txt should contain:
1. cd ~
2. pwd
3. ls
etc (you complete the rest)
| Command Number |
Command Description |
|---|---|
| 1 | Ensure your current directory is your home directory |
| 2 | Display the name of your present working directory |
| 3 | List the files in your home directory |
| 4 | Change directory to your Programming Environment directory (this should already have been created) |
| 5 | Change directory to your tutorials directory (this should already have been created. If it doesn't exist create it)) |
| 6 | Display the name of the present working directory |
| 7 | List the names of all the files in the current directory |
| 8 | Create a new directory called 'tut20' in the tutorials directory |
| 9 | Change directory to your new tut20 directory |
| 10 | Display the name of your present working directory |
| 11 | Copy the AddTwoNumbers.java file created earlier into the current directory |
| 12 | Print the above file to itlab3 (this won't work. write down what the command would be anyway) |
| 13 | Compile AddTwoNumbers.java |
| 14 | Run AddTwoNumbers |
| 15 | Copy all files from the /Users/cjcope/Public to your current directory using a relative reference to cjcope's public directory |
| 16 | Rename lecture2.txt to lecture3.txt |
| 17 | Display the permissions on the files in the current directory |
| 18 | Delete the other read permissions (mode) from all of the txt files in your current directory |
| 19 | Delete lecture3.txt |
| 20 | Display the permissions on the files in the current directory |
| 21 | Change directory to the parent directory (tutorials) |
| 22 | Move Hello.java from the tut20 directory to the current directory |
| 23 | Display the names of the files in the current directory |
| 24 | Display the name of the present working directory |
| 25 | Delete your tut20 directory (This may require a few of commands - be careful). Make sure the your q8Commands.txt file isn't in the directory before deleting it |
| 26 | Display the names of the files in the current directory |
Print the file q8Commands.txt and hand it in stapled to a title page for assessable tutorial D. Alternatively you can show your tutor your commands in the Lab session in week 11.
Use grep to:
If you have time investigate Unix further.
Due Date: Computer Lab Week 11
Marks: 2%
Section 8 (Unix Commands) above is Assessable Tutorial D. Hand in a title page as specified in Assessable Tutorial A, and a printout of the file q8Commands.txt. Alternatively you can show your tutor your commands in Computer Lab week 11.
Written by Tim Whitfort.