import java.util.*;
//=================================================================================================
public class UseFruit {
//-------------------------------------------------------------------------------------------------
    private static final Scanner keyboard = new Scanner(System.in);
//-------------------------------------------------------------------------------------------------
    public static void main(String[] args) {

        ArrayList<ProvidesValue> fruitBasket = new ArrayList<>();
        char fruitOption;
        double fruitValue;
        int fruitInHand;
        double totalWeightBefore,totalWeightAfter;
        ProvidesValue fruitWithValue;

        do {
            System.out.print("(A)pple & weight, (O)range & juice, e(X)it : ");
            fruitOption = Character.toUpperCase(keyboard.next().charAt(0));
            switch (fruitOption) {
                case 'A':
                    fruitValue = keyboard.nextDouble();
                    fruitBasket.add(new Apple(fruitValue));
                    break;
                case 'O':
                    fruitValue = keyboard.nextDouble();
                    fruitBasket.add(new Orange(fruitValue));
                    break;
                case 'X':
                    break;
                default:
                    System.out.println("Invalid option");
                    break;
            }
            keyboard.nextLine();
        } while (fruitOption != 'X');

        totalWeightBefore = 0.0;
        totalWeightAfter = 0.0;
        for (fruitInHand = 0; fruitInHand < fruitBasket.size(); fruitInHand++) {
            fruitWithValue = fruitBasket.get(fruitInHand);
            System.out.println("Before: " + fruitWithValue);
            totalWeightBefore += fruitWithValue.getValue();
            fruitWithValue.eatSome();
            totalWeightAfter += fruitWithValue.getValue();
            System.out.println("After : " + fruitWithValue);
        }
        System.out.println("Total weight before is " + totalWeightBefore);
        System.out.println("Total weight after is  " + totalWeightAfter);
    }
//-------------------------------------------------------------------------------------------------
}
//=================================================================================================
