You have to build 2 classes ExpenseItem, ExpenseLedger Class ExpenseLedger record expenses you make. You record expense by serial number,description,amount. Create a class ExpenseItem with serialnum, description,amount. Provide constructors, toString for this class. Now in ExpenseLedger class create arraylist of ExpenseItem. Provide following methods
void addExpense(description, amount). This method create an expense item and add it to ledger. Int removeSmallExpenses(double amt):This method will find expense items that are smaller or equal to amount amt and remove items from list. Note that multiple items can be smaller than this value and thus each of these should removed. Also this method should return number of items removed. Double totalExpenditure(): This method calculate total expenditure recorded in ledger so far. You can do this by iterating through expenses list and adding all the amounts to find the total expenditure so far. Override toString method so ledger is printed in well formatted way
import java.util.*;
public class Main
{
public static void main(String[] args) {
}
}
class ExpenseItem{
private int serialnum;
private String description;
private double amount;
public ExpenseItem(){
}
}
class ExpenseLedger{
private int serial_number;
private String description;
private double amount;
ArrayList<ExpenseItem> l=new ArrayList<ExpenseItem>();
public ExpenseLedger(){
}
void addExpense(String description, double amount){
//
}
int removeSmallExpenses(double amt){
//
}
double totalExpenditure(){
//
}
}
Comments
Leave a comment