Answer to Question #270195 in Java | JSP | JSF for User 12345

Question #270195

You are required to write a program that implements the computerized maintenance of your 

monthly expenditure record keeping. You will have to build two classes ExpenseItem, 

ExpenseLedger 

 The class ExpenseLedger will record all the expenses you make. You record an expense by giving 

it a serial number, a description (that tells what it is about) and the money you spent on this item. So 

you need to create a class ExpenseItem with serial, description and amount. Provide constructors, 

getters and setters. Also provide toString for this class. Now in the ExpenseLedger class you need to 

build a collection that will hold the instance of ExpenseItem. Provide the following methods in the 

ExpenseLedger

1. int removeSmallExpenses(double amt):This method will find expense items that are smaller or equal to amount amt & then remove these items from list. Note that multiple items can be smaller than this value & thus each of these should be removed & return number of items removed.


1
Expert's answer
2021-11-23T11:23:38-0500
import java.util.LinkedList;

public class ExpenseLedger {
    private LinkedList<ExpenseItem> expensesLedger;

    public ExpenseLedger() {
        expensesLedger = new LinkedList<>();
    }

    int removeSmallExpenses(double amt) {
        LinkedList<ExpenseItem> expenseItems = new LinkedList<>();
        for (ExpenseItem expenseItem : expensesLedger) {
            if (expenseItem.getAmount() <= amt) {
                expenseItems.add(expenseItem);
            }
        }
        for (ExpenseItem expenseItem : expenseItems) {
            expensesLedger.remove(expenseItem);
        }
        return expenseItems.size();
    }

}


public class ExpenseItem {
    private int serial;
    private String description;
    private double amount;

    public ExpenseItem() {
        serial = -1;
        description = "?";
        amount = -1;
    }

    public ExpenseItem(int serial, String description, double amount) {
        this.serial = serial;
        this.description = description;
        this.amount = amount;
    }

    public int getSerial() {
        return serial;
    }

    public void setSerial(int serial) {
        this.serial = serial;
    }

    public String getDescription() {
        return description;
    }

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

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    @Override
    public String toString() {
        return serial + " " + description + " " + amount;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS