Computer Science 2
Section 1: 8:30 - 9:20 TTh @ 110 MLH
Section 4: 12:30 - 1:20 TTh @ 114 MLH
Code from 10/14
Multiply.java
Sentence.java
Collections code
LinkedListTest.java
UniqueWords.java
Net code
DayClient.java
HTTPClient.java
PortTest.java
SMTPClient.java
Thread code
HerkyThread.java
TenThreads.java
Project Requirements
UPDATED
- Hand in a paper copy of your source code, i.e. all files with a ".java"
extension, along with any other files necessary to run the program.
Make sure that you submit an electronic copy of your source code as well.
- Your source code should have your name, section number, ID, and project
number listed in a comments block at the beginning of the code.
- Your code is graded on both correctnes and clarity.
- Correctness: make sure that your program rigorously tests all code that
you have written - every method, every class.
- Clarity: NEW -
your programs must include comments which clarify the code for the reader.
Comments should be short and informative - one line explaining how a variable
will be used, what a method will do, how the function is being called, etc.
Examples:
//This class defines a Square object.
class Square extends Shape
{
//side represents the length one side of the Square object
private int side;
//This is my default constructor. It sets side equal to 5
Square()
{
side = 5;
}
//This constructor takes an int parameter, and sets side equal to it
Square(int n)
{
side = n;
}
//This method returns the area of a Square object.
//It takes a Square object as a parameter, and returns an int
int Area(Square s)
{
//Get the length of the Square's side
int x = s.side;
//Return the area
return x*x;
}
..........
..........
}
- NEW - You must include a "readme" file with your program,
indicating what the name of the program is, all files associated with the
program, how to compile it, and how to run it.
The readme must also include a short description of what the program does,
a listing of all classes defined in the program along with a short description
of what each class does, and a listing of the methods in each class with a
short description of what they do.
Example:
Readme for Square.java
This program simply defines a Square object. It includes only the file
Square.java. It is compiled by typing:
javac Square.java
and can be run by typing:
java Square
Class Square: This class defines a Square object. The Square object contains
one instance variable, side.
- int side: side represents the length one side of the Square object
Methods
Square(): This is my default constructor. It sets side equal to 5.
Square(int n): This constructor takes an int parameter, and sets side equal to it.
int Area(Square s): This method returns the area of a Square object. It takes a Square object as a parameter, and returns an int.
Submitting Projects
- Go to the folder where you've written your source code using the "cd" command.
For example, if you've created a folder named "CS2" in your home directory, and this
directory is where your source code is, go there.
- Make a new directory for submitting using the "mkdir" command.
- Copy your source code into the directory using the "cp" command.
- cp Project1.java project1/
- Submit the folder using the "submit" command.
- Enter the course number (in this case, c020).
- Enter the submit directory.
That's all!
Dr. Slonneger's Very Tiny Java Graphics Program
public class VTiny
{
public static void main(String [] args)
{
javax.swing.JFrame jf = new javax.swing.JFrame();
//Notice the anonymous class!
jf.getContentPane().add(new javax.swing.JPanel()
{
public void paintComponent(java.awt.Graphics g)
{
super.paintComponent(g);
setBackground(java.awt.Color.cyan);
g.setColor(java.awt.Color.blue);
g.setFont(new java.awt.Font("Serif", java.awt.Font.BOLD, 250));
g.drawString("J", 50, 200);
}
});
jf.setSize(250,300);
jf.setVisible(true);
}
A Short Guide to UNIX
Useful commands:
cntl-d -- quit
cntl-c -- break
cat -- list a file on the screen at full speed
more -- list a file on the screen, one page at a time
rm f -- remove file f from a directory
cp f1 f2 -- make copy of a file
cp path/f . -- make copy of a file from somewhere else with same name
ls -- list the current directory on the screen
ls -l -- list the current our directory with dates and permissions
mv f1 f2 -- rename a file or directory
cd subd -- change to subdirectory
cd .. -- change to parent directory
cd -- return to home directory
mkdir dir -- create a new directory
rmdir dir -- remove an empty directory
chmod 644 f -- change permissions on a file or directory
ps -- show processes running in current shell
kill pn -- kill process with number pn
man cmd -- display documentation from the manual on the screen
For help on the use of any command, use the "man" (short for manual)
command. For example, "man man" will tell how to use "man". Some
"man pages" (output from the man command) are longer than a screenfull;
for these use "man man | more", which sends the result of man to the
more command.
Permissions are describe by 9 bits rwxrwxrwx. The first three are
you, the middle three are your group, and the last three are the world.
To make a file readable, use "chmod 644 filename", to make a directory
passable, use "chmod 711 dirname". and to make a directory passable
and readable, use "chmod 755 dirname".
For printing in 301 MLH, use the command: lp -dp301 filename.