Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A class for managing money.
- *
- * Travis Smith
- * 10/21/11 CS221 S1 Lab6
- */
- public class Money
- {
- //declare variables
- private final int CENTS_PER_DOLLAR = 100;
- private int cents;
- //constructors
- public Money ()
- { cents = 0;
- }//end default constructor
- public Money (int totalCents)
- { cents = totalCents;
- }//end 1 int constructor
- public Money (int dollars, int cents)
- { this.cents = cents + dollars * CENTS_PER_DOLLAR;
- }//end 2 int constructor
- //getters
- public int getDollars()
- { int dollars = (cents - (cents % CENTS_PER_DOLLAR)) / CENTS_PER_DOLLAR;
- return dollars
- }//end get dollars
- public int getCents()
- { int answer = cents % CENTS_PER_DOLLAR;
- return answer;
- }//end get cents
- public String toString()
- { return ("$" + this.getDollars + "." + this.getCents);
- }//end to string
- //setters
- public void setDollars(int dollars)
- { this.dollars = dollars;
- }//end set dollars
- public void setCents (int cents)
- { this.cents = cents;
- }//end set cents
- }//end class
Add Comment
Please, Sign In to add comment