Friday, July 29, 2005

ugh, i cant believe another two weeks have past since i last wrote any entries. anyway...

for the last two weeks, my students have shown steady improvement in their ability to create object oriented programs. i mean, i could really see the difference. at first they were clueless as to what attributes to use, how to stucture their class, stuff like that. at the end of this period, things were going quite well..

me 13 was class taxi. i asked them to implement this with the following methods:

* Taxi(int initialmoney, double initialgas)
* void flagdown() - taxi becomes occupied, meter set to 30, error if method is called while taxi is occupied
* void travel(int km) - taxi tries to travel a certain distance. for every kilometer, gas level decreases by .1 liter. if the taxi is occupied, meter increases by 10. outputs an error if taxi has run out of gas
* void getoff() - passenger gets off. meter value is added to taxi's current money and gross income.
* void getgas(int liter) - gas costs 30 per liter, taken from taxi's current money, of course outputs an error if the taxi does not have any current money.
* int getGrossIncome() - returns gross income
* int getExpenses() - returns total expenses spent on gas
* int getNetIncome() - gross income - expenses
* int getCurrentMoney() - returns current money
* int totalKm() - total kilometers travelled

only 1/4 of my class was able to submit this on time

ME 14 is a Vector-type class. I asked them to implement a class SuperArray with the following methods:

* void set(int index, String data)
* String get(int index)
* void changeSize(int newSize) - changes the size of the SuperArray. values beyond the new size are discarded.
* public String toString() - returns a String with SuperArray's elements in the form {a,b,c...}

change size was tricky for them, but a good majority was able to finish the ME on time

ME15 is a free-for-all mp. I asked them to create an OOP class of their own.

Today is the end of another 2 week cycle. ME 16-17 may have been quite hard, as only 2 people (in both my classes) were able to submit it on time.

An extension of the SuperArray class, class SongList has the following methods:

* void addSong(String title, String band, String genre, int lengthinseconds)
* boolean contains(String title)
* boolean delete(String title)
* int numberOfSongs()
* public String toString() - prints out all the information per song, and total playlist time

and the tricky methods
* SongList createListBand(String band)
* SongList createListGenre(String genre)
which basically create new SongLists whose songs match the band/genre

It was heartbreaking to watch my students stare at computer screens. Some of them couldnt even get addMethod right, having problems with array declaration and use.

I dont know what to do next. i have to move on with the lesson, yet i cant as im still not that confident with my students ability. all that progress in the last two weeks seem to disappear when they're doing something by themselves. *sigh*

Tuesday, July 19, 2005

The individual me



after two weeks of the pilot-copilot scheme, my students seem to have gotten a little better (no more late submissions). it was time for an individual exam (part of the schedule too).

i've had the problem of worrying that my afternoon students would just simply look at the submissions of the morning class so i decided to give different machine exercises for the first class.

ME 10-11 morning

create a class ATM that has the following methods


  • void deposit(int money) - deposits money into your ATM account
  • void withdraw(int money) - withdraws money from your ATM account. Money must not be greater than 10000, in the hundreds, and you cannot withdraw more than what you have in your account, including the 10 php service charge.
  • int checkBalance() - returns balance. this however costs 1 php


ME 10-11 afternoon

create a class Cellphone that has the following methods


  • void load(int money) - load Cellphone with money
  • void text() - text message, costs 1 php
  • void call(int minutes) - calls another phone. this method attempts to call for as long as it can, subtracting 8 php per minute until call is completed, or no more credit is available. in that case, this method outputs an error message showing how many minutes were actually used.
  • int checkBalance() - returns how much credit the phone has. costs 1php.
  • void transferLoad(Cellphone c, int money) - transfers money from this cellphone to c. 1 php service charge. errors on lack of money.


The individual ME is recorded as double the regular ME score. So that at least this single individual ME could have bigger weight than the group ME's.

Anyway, the results. The morning class performed well, everyone got this ME, and quite a few finished the bonus problem i gave them. Afternoon class was appalling. Only four people managed to finish the exercise. Despite my initial misgivings, i asked them to finish the problem over the break so that they'd get to see how classes are created.

The next meeting (back to the regular P-C scheme, different pairs) i switched the exercises and the morning class did the Cellphone exercise as easy as pie. The afternoon class finished the late Cellphone and the ATM exercise (but then again, they had help).

I cant move on with the lesson (Stacks and Queues next) until im sure that both classes have a good grasp on object creation.

Tuesday, July 05, 2005

Day 5, first OOP day and Day 6



Well... Last friday i started with the first OOP lesson.

Started out from C, a structure describing a Point


typedef struct Point {
  double x;
  double y;
};


and its use is as follows:


Point p;
p.x = 3; p.y = 4;
printf("(%lf,%lf)",p.x,p.y);


Then i convert both to Java


public class Point {
  double x;
  double y;
}


and in the main class:

Point p = new Point();
p.x = 3; p.y = 4;
System.out.println("(" + p.x + "," + p.y + ")");


Then i introduce them to the concept of methods by making the printing method built-in.


public class Point {
  double x;
  double y;

  void printPoint() {
    System.out.println("(" + x + "," + y + ")");
  }
}


And the corresponding modification to main:

Point p = new Point();
p.x = 3; p.y = 4;
p.printPoint();


I then show them the advantage of this... By having a lot of points declared, then have them have to change the ()'s into {}'s.

I try to teach them that calling a variable's method you are actually inside variable. I introduce them to concepts of class and object, attributes and methods at this point in time.

Since they are C programmers and are already familiar with functions, i get them to implement a double distanceToOrigin() method that returns how far the current point is to the origin.

The next concept i have to teach myself is the ability of a method to return a Point object via method Point midPoint(double otherX, double otherY). Then a short lesson on method overloading through a second method Point midPoint(Point anotherPoint).

Exercise for this is a Complex number implementation, something that represents Complex number a+bi were i is the sqrt of -1. Methods to be implemented are Complex add(Complex anotherC) and Complex times(Complex anotherC). Also an implementation of public String toString() (didnt tell them its special use yet) just so that they get used to using toString().

Common problems that i found with my students working on this is the problem of still using the variable used to reference this object inside the object.

i.e.

Complex c,d,e;
...
e = c.add(d);


and then inside the add method:

Complex add(Complex otherC) {
e.a = c.a + otherC.a //something like this
}


Another problem, which was kindof unexpected, was...

public String toString() {
  Complex result = new Complex();
  return result.a + " + " + result.b + "i";
}


Not sure how that happened, but around 4 pairs had this problem.

Anyway, i was too tired for Day 6 so i just gave them the period for their free-for-all ME.

Day 5 and 6



Well... Last friday i started with the first OOP lesson.

Started out from C, a structure describing a Point


typedef struct Point {
  double x;
  double y;
};


and its use is as follows:


Point p;
p.x = 3; p.y = 4;
printf("(%lf,%lf)",p.x,p.y);


Then i convert both to Java


public class Point {
d