write a program that implements computerized maintenance of your
monthly expenditure record keeping. You have to build two classes ExpenseItem, ExpenseLedger
The class ExpenseLedger will record all expenses you make. You record an expense by giving it a serial number, a description (that tells what it is about) and money you spent on this item. So you need to create a class ExpenseItem with serial, description and amount. Provide constructors,
getters & setters & toString for this class. Now in ExpenseLedger class you need to build a collection that will hold instance of ExpenseItem. Provide following methods in ExpenseLedger
1. int removeSmallExpenses(double amt):This method will find expense items that are smaller or equal to amount amt and then remove these items from list. Note that multiple items can be smaller than this value and thus each of these should be removed. Also this method should return number of items removed.
2. Override toString method to print ledger in well formatted form
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(){
}
public ExpenseItem(int serialnum, String description, double amount) {
this.serialnum = serialnum;
this.description = description;
this.amount = amount;
}
public int getSerialnum() {
return serialnum;
}
public void setSerialnum(int serialnum) {
this.serialnum = serialnum;
}
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 "ExpenseItem{" + "serialnum=" + serialnum + ", description=" + description + ", amount=" + amount + '}';
}
}
class ExpenseLedger{
ArrayList<ExpenseItem> l=new ArrayList<ExpenseItem>();
public ExpenseLedger(){
}
int removeSmallExpenses(double amt){
//
}
@Override
public String toString() {
return "ExpenseItem{" + "serialnum=" + l.serialnum + ", description=" + l.description + ", amount=" + l.amount + '}';
}
}
Comments
Leave a comment