title: Driving cost - methods
body: <p><strong>This is a problem for school</strong></p>
  <p>Write a method <code>drivingCost()</code> with input parameters <code>drivenMiles</code>, <code>milesPerGallon</code>, and <code>dollarsPerGallon</code>, that returns the dollar cost to drive those miles. All items are of type <code>double</code>. If the method is called with</p>
  <pre><code>50 20.0 3.1599
  </code></pre>
  <p>the method returns <code>7.89975</code>.</p>
  <p>Define that method in a program whose inputs are the car's miles/gallon and the gas dollars/gallon (both doubles). Output the gas cost for 10 miles, 50 miles, and 400 miles, by calling your <code>drivingCost()</code> method three times.</p>
  <p>Output each floating-point value with two digits after the decimal point, which can be achieved as follows:</p>
  <pre><code>System.out.printf(&quot;%.2f&quot;, yourValue);
  </code></pre>
  <p>The output ends with a newline.</p>
  <p>Ex: If the input is:</p>
  <pre><code>20.0 3.1599
  </code></pre>
  <p>the output is:</p>
  <pre><code>1.58 7.90 63.20
  </code></pre>
  <p>Your program must define and call a method:
  <code>public static double drivingCost(double drivenMiles, double milesPerGallon, double dollarsPerGallon)</code></p>
  <p><strong>So far my code seems to make sense, but I keep getting this error, and I am not sure what it means,</strong></p>
  <pre><code>Exception in thread &quot;main&quot; java.util.NoSuchElementException
      at java.base/java.util.Scanner.throwFor(Scanner.java:937)
      at java.base/java.util.Scanner.next(Scanner.java:1594)
  </code></pre>
  <p><strong>Here is my code</strong></p>
  <pre><code>import java.util.Scanner;
  
  public class LabProgram {
     
     public static double drivingCost(double drivenMiles, double milesPerGallon, double dollarsPerGallon) {
        double totalCost = (dollarsPerGallon * drivenMiles) / milesPerGallon;
        return totalCost;
     }
     
     public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        double milesPerGallon = scnr.nextDouble();
        double dollarsPerGallon = scnr.nextDouble();
        double drivenMiles = scnr.nextDouble();
        
        System.out.printf(&quot;%.2f &quot;, drivingCost(drivenMiles, milesPerGallon, dollarsPerGallon) * 10);
        System.out.printf(&quot;%.2f &quot;, drivingCost(drivenMiles, milesPerGallon, dollarsPerGallon) * 50);
        System.out.printf(&quot;%.2f\n&quot;, drivingCost(drivenMiles, milesPerGallon, dollarsPerGallon) * 400);
     }
  }
  </code></pre>