Thursday, July 15, 2010

package mylinkedlist;

public class LLNode<T>
{
    public T value;
    public LLNode next;
   
    public LLNode(T n)
    {
        value = n;
        next = null;
    }
}
package mylinkedlist;

public class LinkedList<T>
{
    LLNode<T> head;
    LLNode tail;
    int count;
   
    LinkedList()
    {
        head = tail = null;
        count = 0;
    }
   
    void addAtBeginning(T n)
    {
        count++;
        LLNode<T> ln = new LLNode<T>(n);
       
        if (isEmpty())
        {
            head = ln;
            tail = ln;
        }
        else
        {
            ln.next = head;
            head = ln;
        }
       
    }
   
    boolean isEmpty()
    {
        return head == null;
    }
   
    void printAllItems()
    {
        for (LLNode<T> i = head; i != null; i = i.next)
            System.out.println(i.value);
    }
   
    T front()
    {
        if (head == null)
            return null;
        else
            return head.value;
    }
   
    T rear()
    {
        LLNode<T> prev = null;
        for (LLNode<T> i = head; i != null; i = i.next)
            prev = i;
       
        if (prev == null)
            return null;
        else
            return prev.value;   
    }
   
    int size()
    {
//        int count = 0;
//        for (LLNode i = head; i != null; i = i.next)
//            count++;
       
        return count;   
    }
   
    void addAtEnd(T n)
    {
//        LLNode prev = null;
//        for (LLNode i = head; i != null; i = i.next)
//            prev = i;
//       
//        if (prev == null)
//            ;
//        else
//        {
//            prev.next = new LLNode(n);
//            count++;
//        }
        count++;
        LLNode ln = new LLNode<T>(n);
        if (isEmpty())
        {
            head = ln;
            tail = ln;
        }
        else
        {
            tail.next = ln;
            tail = ln;
        }
    }
   
}
Material:

Java syntax:
primatives vs. reference types
strings, string comparison, assignment
Integer vs. integer
pass by reference vs. by value
classes, objects
arrays vs. arraylists
arraylists vs arraylists
static vs. non-static data members and methods
public, private, protected, package
inheritance via extends
implements for interfaces

semantics:
Person, Book, MyLibrary class and how they interact
Linked list
Maybe to make a similar class, extend the class by adding functionality

Monday, July 12, 2010

Project

Write a computer game: Poker Dice

http://en.wikipedia.org/wiki/Poker_Dice

Thursday, July 8, 2010

Plan:
1) arrays, how to use, limitations
2) ArrayLists (both of Object and generics)
3) Inheritance

class Person
{
    static String firstname;
    String lastname;
    String ssn;
    int age;
    static void takeAWalk() { ... }
}

class Customer extends Person
{

}

class Employee extends Person
{
    takeAWalk() { ... }
}


main()
{
    Person x;
    Person.firstName;
    x.firstName;
    x.takeAWalk();
}



4) if there is time, some more Applet material

Wednesday, June 30, 2010

package org.cs212.hello;

public class Hello {

    public static void main(String[] args) {
        int a = 5;
        int b = 5;
        if (a==b)
            System.out.println("a equals b");

        Integer A = new Integer(5);
        Integer B = new Integer(5);
       
        if (A.equals(b))
            System.out.println("A equals B");
       
        /*
        String s = "Goodbye";
        System.out.println(s);
       
        String t = "Good";
        t = t + "bye";
        System.out.println(t);
        System.out.println(s == t);
        if (s.equals(t))
        {
            System.out.println("They are equal!");
       
        }
       
        System.out.println("hello");
        Person p = new Person();
        p.setName("Fred");
        System.out.println(p.getName());
       
        Person q; // = new Person();
        //q.setName("Fred");
        q = p;
       
        if(p==q)
        {
            System.out.println("same");
        }
        else
        {
            System.out.println("different");
        }*/
    }

}
public class Person
{
    // fields
    private String name; // the person's name
    private int maximumBooks;
   
    // constructor
    public Person()
    {
        name = "unknown name";
        maximumBooks = 3;
    }
    qccs212.blogspot.com
    // getters and setters
    public String getName()
    {
        return name;
    }
   
    public void setName(String n)
    {
        name = n;
    }

    public int getMaximumBooks() {
        return maximumBooks;
    }

    public void setMaximumBooks(int maxBooks) {
        maximumBooks = maxBooks;
    }
   
}