teaching machines

CS 145 Lecture 21 – Our own objects

November 28, 2011 by . Filed under cs145, fall 2011, lectures.

Agenda

Code

CommandLineArguments.java

package lecture;

public class CommandLineArguments {
  public static void main(String[] args) {
//    for (int i = 0; i < args.length; ++i) {
//      System.out.println(args[i]);
//    }
    
    System.out.println(args.length);
    for (String arg : args) {
      System.out.println(arg);
    }
  }
}

NDeckerBurger.java

package lecture;

public class NDeckerBurger {
  // Instance variables
  private int nDecks;
  
  // Constructor
  public NDeckerBurger(int givenDeckCount) {
    nDecks = givenDeckCount;
  }
  
  // Methods
  public int getCheeseCount() {
    return nDecks;
  }
  
  public int getBaconCount() {
    return 4 * nDecks;
  }
  
  public int getDeckCount() {
    return nDecks;
  }
  
  public int getBunCount() {
    return nDecks + 1;
  }
  
  public double getKetchupOunces() {
    return 2.4 * nDecks;
  }
  
  public double getCalorieCount() {
    return 41 * getBaconCount() + 31 * getCheeseCount() + 211 * getDeckCount() + 27 * getBunCount() + 10 * getKetchupOunces() / 0.4;
  }
  
  public void fuse(NDeckerBurger other) {
    nDecks = nDecks + other.nDecks;
  }
  
  public static void printBoo() {
    System.out.println("boo");
  }
  
  public static void main(String[] args) {
    NDeckerBurger breakfast = new NDeckerBurger(32 + 10);
    NDeckerBurger wifesBreakfast = new NDeckerBurger(14);
    breakfast.fuse(wifesBreakfast);
    System.out.println(breakfast.getDeckCount());
    System.out.println(breakfast.getCalorieCount());
    
    NDeckerBurger.printBoo();
  }
}

TODO

Haiku

Monogamy
Args see the world
But the ladies want stable
So now I’m instance