Class Money Part A: Define a class named Money whose objects represents amount o
ID: 3906028 • Letter: C
Question
Class Money Part A: Define a class named Money whose objects represents amount of Canadian money. The class should have 2 instance variables of type int for the dollars and cents and a static variable to keep track of the number of objects of type Money created a The class should have the following constructors. o a constructor with 2 parameters of type int one for the dollars and cents a a constructor with 1 parameter for an amount of dollars with zero cents a a constructor with no arguments (default constructor) a copy constructor s Include accessor methods a Include mutator methodsExplanation / Answer
import java.util.Objects; public class Money { private int dollars, cents; private static int count = 0; public Money(int dollars, int cents) { this.dollars = dollars; this.cents = cents; count++; } public Money(int dollars) { this.dollars = dollars; this.cents = 0; count++; } public Money() { this.dollars = 0; this.cents = 0; count++; } public int getDollars() { return dollars; } public void setDollars(int dollars) { this.dollars = dollars; } public int getCents() { return cents; } public void setCents(int cents) { this.cents = cents; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Money money = (Money) o; return dollars == money.dollars && cents == money.cents; } @Override public String toString() { return "Money{" + "dollars=" + dollars + ", cents=" + cents + '}'; } }