This call after scanner.next()
causes a blank line in the command-line session:
System.out.println();
Just leave it out. Then the interaction looks like this:
How many gallons of Petrol would you like to add: 2.3
Adding 2.3 gallons of fuel to the tank
As @shmosel said you may also want to use print()
rather than println()
in your two catch
blocks just like you do at the top of your method.