To disallow other students from reading your homework programs, you must save your file in a directory inside your cs170 directory.
To do this, execute this command in a terminal window:
mkdir ~/cs170/hw4 |
To change your current directory to ~/cs170/hw4, use this command:
cd ~/cs170/hw4 |
gedit yourProgramName.java |
The name yourProgramName is the name of the Java program (and also the name of the class.
Remember:
|
|
This is what you should see when you run the program and enters 7 as the first number and 5 as the second number:
UNIX>> java Operators Enter the first number: 7 Enter the second number: 5 7 + 5 = 12 7 - 5 = 2 7 * 5 = 35 7 / 5 = 1 7 % 5 = 2 |
Notes:
|
UNIX>> java -cp /home/cs170002/share/hw4 Operators |
|
This is what you should see when you run the program and enters atlanta
UNIX>> java FirstEqLast Enter a word: atlanta Yes |
This is what you should see when you run the program and enters boston
UNIX>> java FirstEqLast Enter a word: boston No |
Relevant materials:
UNIX>> java -cp /home/cs170002/share/hw4 FirstEqLast |
public class ShowCurrentTime { public static void main(String[] args) { long nMillis; // We need long for accuracy !!! long n, hours, minutes, seconds; nMillis = System.currentTimeMillis(); n = nMillis/1000; // Total # Second; seconds = n % 60; // Seconds n = n / 60; // Total # minutes; minutes = n % 60; // Minutes n = n / 60; // Total # hours; hours = n % 24; // Hours System.out.print(hours); System.out.print(":"); System.out.print(minutes); System.out.print(":"); System.out.print(seconds); System.out.println(" GMT"); } } |
The usual output of the time is as follows:
hh:mm:ss |
In other words, we always use 2 digits for to display the hours, minutes and seconds,
When the hour, minute or second is less than 10, the output of the program deviates from the usual format, e.g.:
7:8:9 (Standard: 07:08:09) |
Edit your own ShowCurrentTime.java program and cut and paste the above ShowCurrentTime.java into your ShowCurrentTime.java program.
Then add some statement into the program to make the program print the time in the standard format.
Hint:
|
UNIX>> java -cp /home/cs170002/share/hw4 ShowCurrentTime |
|
cd ~/cs170/hw4 (omit this if your current directory is hw4) /home/cs170002/turnin-hw Operators.java hw4 /home/cs170002/turnin-hw FirstEqLast.java hw4a /home/cs170002/turnin-hw ShowCurrentTime.java hw4b |
Your homework is not turned unless the above commands are successful (you will get a "success" message when turn in was successful).
(It works just like turn in command of labs).
|