Answer to Question #269632 in Java | JSP | JSF for beerr

Question #269632

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.      void addExpense(description, amount): You should be able to figure out the serial of the expense yourself. This method will create an expense item and add it to the ledger. 


1
Expert's answer
2021-11-21T17:33:41-0500


package expenseledger;


import java.util.ArrayList;


class ExpenseItem{
    private String serial, description;
    private double amount;
     ExpenseItem(String des, double am){
        
        description  = des;
        amount = am;
        
    }
    ExpenseItem(String s, String des, double am){
        serial  =s;
        description  = des;
        amount = am;
        
    }
    String getSerial(){
        return serial;
    }
    
    String getDescription(){
        return description;
    }
    
    double getAmount(){
        return amount;
    }
    
   public String toString(){
        return serial +" "+description+"  "+amount;
    }
}
public class ExpenseLedger {


    static ArrayList list = new ArrayList <>();
    
   void addExpense(String description,double amount){
       ExpenseItem item = new ExpenseItem(description, amount);
       list.add(item);
   }
    public static void main(String[] args) {
        
    }
    
}

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