public class BankAccount
{
private int dollars;
private int cents;
public BankAccount( int initialDollars, int initialCents ) {
dollars = initialDollars;
cents = initialCents;
}
public int getDollars() {
return dollars;
}
public int getCents() {
return cents;
}
public double getBalance() {
return dollars + cents/100.0;
}
public void setDollars( int updatedDollars ) {
dollars = updatedDollars;
}
public void setCents( int updatedCents ) {
cents = updatedCents;
}
public static void main( String[] args ) {
new BankAccount( 10000, 8 );
BankAccount checkingAccount = new BankAccount( 1837, 21 );
System.out.println(checkingAccount.getBalance() );
checkingAccount.setDollars( checkingAccount.getDollars() * 10 );
}
}
public class Flower {
private int numPetals;
private boolean wilted;
public Flower( int petals ) {
this.numPetals = petals;
this.wilted = false;
}
public int getNumPetals() {
return numPetals;
}
public boolean isWilted() {
return wilted;
}
public void dropPetal() {
if (getNumPetals() > 0) {
numPetals -= 1;
}
}
public void wilt() {
wilted = true;
}
public String toString() {
String baseRep = "A flower with " + Integer.toString(getNumPetals())
+ " petals that is ";
if (isWilted())
return baseRep + "wilted :(";
else
return baseRep + "not wilted!";
}
public static void main( String[] args ) {
new Flower( 10 );
Flower buttercup = new Flower( 5 );
Flower iris = new Flower( 3 );
System.out.println( buttercup );
System.out.println( iris );
for (int i = 0; i < 4; i++ ) {
buttercup.dropPetal();
iris.dropPetal();
}
System.out.println( buttercup );
System.out.println( iris );
iris.wilt();
System.out.println( iris );
}
}