Why Java?

  • more simple language
  • automatic garbage collection
  • flexible and effecient because it is object oriented
  • multi threaded allows java to run multiple programs at once

Primities

  • primitives are lowercase
  • nonprimitives are uppercase
  • Collegeboard need-to-know primitives: Boolean, Int, Double

Casting

  • changing a variable from one data type to another
  • widening: happens automatically, going from smaller to larger data type
  • narrowing: need to declare to address overflow error, going from larger to smaller data type

Operators

  • (+) is addition
  • (-) is subtraction
  • (/) is division
  • (*) is multiplication
  • (%) finds the remainder
  • example: x += 7 increases the varaible by 7

Homework

2006 FRQ 2a, 3a (due monday)

2 a)

// returns the price of the item including the tax
 public double purchasePrice()
 {
   return getListPrice() * (1.0 + taxRate);
 }

3 a)

// returns 0 when this customer is equal to other;
  //   a positive integer when this customer is greater than other;
  //   a negative integer when this customer is less than other
  public int compareCustomer(Customer other)
  {
    int diff = getName().compareTo(other.getName());
    if (diff == 0)
      diff = getID() - other.getID();
    return diff;
  }