Primitives Student Lesson
Primitives
Primitives
- 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
public double purchasePrice() {
return getListPrice() * (1+taxRate);
}
public int compareCustomer(Customer other)
{
int compare = getName().compareTo(other.getName());
if (compare == 0) {
return getID() - other.getID();
}
else {
return compare;
}
}