The only thing I would suggest for your interface would be to add some sort of visibility (public, private, protected)
to your method declarations. You have that in the implementation but not in the interface. The code in the implementation looks fine, just the two variables seem to be doing the same thing. I do not know if I fully understand why you called it Category but having upper case Interface names is fine convention in java.
In set methods you can do exactly what you did this.amount = amount
, calling that method from the constructor is fine practice.
In regards to your first question if you add a class variable for each of your set methods and just set that variable to the value passed in then you can add up the total in the getTotal()
method and return that value.
private int personalLoan;
private int donationGifts;
private int recreation;
private int houseHoldItems;
...
@Override
public void setPersonalLoan(int budget) {
this.personalLoan = budget;
}
@Override
public void setDonationsGifts(int budget) {
this.donationGifts = budget;
}
@Override
public void setRecreation(int budget) {
this.recreation = budget;
}
@Override
public void setHouseHoldItems(int budget) {
this.houseHoldItems = budget;
}
...
public double getTotal() {
double total = personalLoan + donationGifts + recreation + houseHoldItems + utilities + savings + groceries....
return total;
}
You can also have all of those variables as parameters in your constructor and set them using those methods instead of taking in one value for your total.
Note I did catch that you have your budgets as int's
as such you cannot have decimal values for your budget. You may want to change that in your interface and then returning a double for the getTotal()
makes more sense.