Answer to Question #268874 in Java | JSP | JSF for beeju

Question #268874

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


1
Expert's answer
2021-11-20T06:45:03-0500
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
public class ExpenseItem{
    int serial=input.nextInt();
    String descrip=input.next(); 
    int amout=input.next();
    static void addExpense(){
        System.out.println("Enter the name of item and amount: ");
        String item=input.next();
        int amount=input.nextInt();
    }
    static void removeSmallExpenses(){
         System.out.println("Enter the name of item to be removed: ");
         double amt=input.nextDouble();
    }
    void totalExpenditure(){
        System.out.println("Enter the total number of items recorded in the ledger: ");
         double total=input.nextDouble();
         System.out.println("Total number of items recorded are: "+total);
    }
	public static void main(String[] args) {
	    class classObj = ledger.class();
        Constructor[] cons = classObj.getConstructors();
  
        
        String str = cons[0].toString();
  
        
        System.out.println("Constructor : " + str);
        totalExpenditure();
        removeSmallExpenses();
         addExpense();
    }
  public class ledger{
  
        public ledger(Object... objects)
        {
            int arr[5]={"bread","sugar","jam","rice","fruits"}
            for(int i=0;i<5;i++){
                arr[i];
            }
        }
    }
}

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