Android : How to calculate total in model array-list?

by Muhammad Faisal Ramadhani   Last Updated October 10, 2019 02:26 AM

i want to create totalHaveMoney ,i was try to looping data income - expense but this is failed. there only getting incomefrom one data , and calculating not working

Model :

public class MoneyManager {
    String name, category;
    String date, description, key;
    Long income, expense, totalMoney;

    public MoneyManager(String name, String category, String date, Long income,Long expense , String description) {
        this.name = name;
        this.category = category;
        this.date = date;
        this.income = income;
        this.expense = expense;
        this.description = description;
    }

    public MoneyManager() {
    }
    public Long totalMoney(){
        Long haveMoney = getIncome();

        for (int i = 0; i < this.getIncome(); i++){
            haveMoney -= getExpense();
        }
        return haveMoney;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public Long getExpense() {
        return expense;
    }

    public void setExpense(Long expense) {
        this.expense = expense;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public Long getIncome() {
        return income;
    }

    public void setIncome(Long income) {
        this.income = income;
    }

    public Long getTotalMoney() {
        return totalMoney;
    }

    public void setTotalMoney(Long totalMoney) {
        this.totalMoney = totalMoney;
    }
}

any help will be appreciate



Related Questions


Updated January 02, 2019 12:26 PM

Updated June 26, 2017 15:26 PM

Updated April 16, 2017 03:26 AM

Updated April 25, 2018 04:26 AM

Updated July 04, 2019 08:26 AM