Assignment # 8 | Due Monday, 4/27

Go over the Unit testing video and answer these questions:

Assignment # 7 | Due Monday, 4/20

Write a GUI program that uses the Model-View-Controller paradigm similar to the program we did in class. The program will be used to convert a given temperature value from Fahrenheit to Celsius. Organize your classes according to

Make sure your MVC classes serve their individual purposes, neither more nor less.

Assignment # 6 | Due Wednesday, 4/1st

  1. Display a chessboard inside a window frame. Obviously, the window will have 8 x 8 rows and columns of alternating black and white squares. Choose any size for your window.

Assignment # 5 | Due Monday, 3/16th

We have already looked at the simple Item class:

class Item {    
    int data;  
    Item nextItem;    

    public String toString() {
        return "Item with data: " + data;
    }
}

and its use in the main method:

public static void main(String[] args) {
    Item item = createList();
    printList(item);

}

public static void printList(Item firstItem) {
    Item currentItem = firstItem;

    while (currentItem != null) {
        System.out.println(currentItem);
        currentItem = currentItem.nextItem;
    }
}

public static Item createList() {
    Item a = new Item();
    a.data = 23;

    Item b = new Item();
    b.data = 29;
    a.nextItem = b;

    Item c = new Item();
    c.data = 35;
    b.nextItem = c;

    Item d = new Item();
    d.data = 43;

    return a;
}

Now create the LinkedList class so that you can do these things in a main method:

LinkedList list = new LinkedList(); // creates an empty list
list.addItem(23);   // adds a new item to the list with data 23
list.addItem(42);   // ...
System.out.println(list);

Assignment # 4

Due March 3rd, 5p.m.

Write a class Vehicle that represents, of course, a vehicle. Give it all the properties (for e.g., weight, maximum speed)—modeled as variables—and behavior (drives, brakes, etc,)—modeled as methods—that you think are relevant. Subclass Vehicle with classes representing cars, airplanes, and ships (I am taking a lot of liberty here with the regular definition of a ‘vehicle’). For each of these subclasses add two more subclasses each; for e.g., Car may be subclassed by SUV and Sedan. While making subclasses, extend the properties and behavior of superclasses in ways that will seem pertinent. Also implement the toString() method in each of them. Make extensive use of this and super in your classes.

Then in your test class create an array of 10 Vehicles and in the array store one object of each class that you have implemented. Then, in a loop, print out the description of each object in the array (using the toString() method appropriately) and also call a method that’s defined in the Vehicle class on it.

Assignment # 3

Due Feb. 23rd (before lecture)

Write a program that will do the following:

  1. reads from a text file and prints out the number of occurences of the String “blip” in it
  2. read the contents of a directory (just like the commands ls in Unix and dir in Windows do) and find out if there is a file or directory with "bak" in its name.

    // count "blip" occurences 
    // a big assumption: every line contains no more than one "blip"
    // for more sophisticated solution need to use StringTokenizer
    try {
        FileReader fr = new FileReader("input.txt");
        BufferedReader reader = new BufferedReader(fr);
    
        int blipCount = 0;
        String singleLine;
        while ((singleLine = reader.readLine()) != null) {
            if (singleLine.indexOf("blip") != -1)
                blipCount++;
        }
    
        System.out.println("Blip count is: " + blipCount);
        reader.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    
    
    
    // read the contents of current directory to find something with "bak" in it
    try {
        File dir = new File(".");
        if (dir.exists() && dir.isDirectory()) {
            String listing[] = dir.list();
            int bakCount = 0;
            for (int i = 0; i < listing.length; i++) {
                if (listing[i].indexOf("bak") != -1)
                    bakCount++;
            }
            System.out.println("Number of files/directories with \"bak\" in them: " + bakCount);
        }
    
    } catch (Exception e) {
        e.printStackTrace();
    }