hi everyone, i need help with an assignment that i'm having trouble with.
I need to create a class called Money whose objects represent amounts of money, with two instance variables of type int for the dollars and cents in the amount of money
i got the constructors down but am having trouble with the static methods.
i need to make two static methods, one that adds two objects of type Money and the other that subtracts two objects of type Money.
I also need to add a second version of the methods for addition and subtraction which should have the same names as the static version but should use a calling object and a single argument(i am still thinking about this part but any suggestions would be very helpful)
I'll put my code below and thanks for any help
public class Money
{
private int dollars;
private int cents;
public Money(int d, int c)
{
dollars = d;
cents = c;
}
public Money(int da)
{
dollars = da;
cents = 0;
}
public Money()
{
dollars = 0;
cents = 0;
}
public static int add(int m3, int m4)
{
return (m3+m4);
}
public static int minus(int m1, int m2)
{
return (m1-m2);
}
public int getDollars()
{
return dollars;
}
public int getCents()
{
return cents;
}
public void setDollars(int dol)
{
dollars = dol;
}
public void setCents(int cen)
{
cents = cen;
}
public String toString()
{
return ("Dollar amount: " + dollars + "Cents amount: " + cents + dollars + "." + cents);
}
public boolean equals(Money yourMoney)
{
return ((this.dollars==yourMoney.dollars)&&(this.cents==yourMoney.cents));
}
}