Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java Contrstuctor

Moses76
Moses76 


Complete the partial implementation of the class ExpenseTracker below. An Expense- Tracker is used to store Expenses. i) Add the type of the elements of the array expenses. ii) Complete the constructor. iii) Complete the implementation of the method double getTotal(). The method double getTotal() returns the total amount for all the expenses that are currently stored in the ExpenseTracker. public class ExpenseTracker { private __________[] expenses; private int size; // keeps track of the number of elements public ExpenseTracker( int capacity ) { __________________________________; size = 0; } // a method has been defined for adding expenses to the tracker public boolean add( Expense e ) { ... } public double getTotal() { } public class Run { public static void main( String[] args ) { ExpenseTracker epro = new ExpenseTracker( 10 ); epro.add( new PrivateCar( "ACFAS 2004", "Montreal (QC)", 430 ) ); epro.add( new Airfare( "IWBRA 2005", "Atlanta (GA)", 204.0 ) ); epro.add( new Breakfast( "IWBRA 2005", 2 ) ); epro.add( new Lunch( "IWBRA 2005", 3 ) ); epro.add( new Dinner( "IWBRA 2005", 2 ) ); System.out.println( "total = " + epro.getTotal() ); } } Attachments
Tags
Clarifications

Answers

ExpenseTracker in java

SW_wizard
SW_wizard 



Solution provided for the question. Attachments
ExpenseTracker.java (1 K) Download Preview
// a method has been defined for adding expenses to the tracker public boolean add( Expense e ) { expenses[size++] = e; return true; } public double getTotal() { double total =0.0; for(int i=0; i<size ; i++){ total = total +

Screenshots
Purchase Answer