package day01;

import common.BaseSolution;
import common.InputReader;

public class Solution extends BaseSolution implements common.Solution {

    public static void main(String[] args) {
        new Solution().run();
    }

    class BaseFuelCalculator {
        public int calculateFuel() {
            int mass, totalFuel = 0;
            InputReader reader = getInputReader();
            String line = reader.next();
            while (line != null) {
                mass = Integer.parseInt(line);
                totalFuel += getFuel(mass);
                line = reader.next();
            }
            return totalFuel;
        }

        protected int getFuelForMass(int mass) {
            return mass / 3 - 2;
        }

        protected int getFuel(int mass) {
            return 0;
        }
    }

    class Part1FuelCalculator extends BaseFuelCalculator {
        protected int getFuel(int mass) {
            return getFuelForMass(mass);
        }
    }

    class Part2FuelCalculator extends BaseFuelCalculator {
        protected int getFuel(int mass) {
            int fuel = 0;
            int fuelPiece = mass;
            do {
                fuelPiece = getFuelForMass(fuelPiece);
                if (fuelPiece > 0) {
                    fuel += fuelPiece;
                }
            } while (fuelPiece > 0);
            return fuel;
        }
    }

    public String part1() {
        return String.valueOf(new Part1FuelCalculator().calculateFuel());
    }

    public String part2() {
        return String.valueOf(new Part2FuelCalculator().calculateFuel());
    }
}

@@ -1127,59 +1127,8 @@
 ce =
- mass;%0A            do %7B%0A                fuelPiece =
  get
@@ -1139,25 +1139,20 @@
 ForMass(
-fuelPiece
+mass
 );%0A     
@@ -1162,14 +1162,13 @@
     
-    if
+while
  (fu
@@ -1178,28 +1178,24 @@
 iece %3E 0) %7B%0A
-    
             
@@ -1237,46 +1237,60 @@
     
-%7D%0A            %7D while (fuelPiece %3E 0);
+fuelPiece = getFuelForMass(fuelPiece);%0A            %7D
 %0A   

Simplify existing day 1 loop