The answer after I run a tester in java comes up 0, why?

时间:2016-05-03 20:09:46

标签: java class

So I kept trying to run this, but for some reason, when I run my tester class, The prompt to enter gallons and mpg show up, and I enter it and my distance and cost come out as zero. Helllpp.

import java.util.Scanner; 

public class MilagePrinter {

int miles = 100;
double mpg;
double gallons;
double distance;
final double COSTPERGALLON = 3.95; 

public MilagePrinter() {

  double thegallons;
  double thempg; 

   Scanner input = new Scanner(System.in); 

   System.out.print("How many gallons are currently in the tank?   ");
   thegallons = input.nextDouble();

   System.out.print("How fuel efficient is the car?   ");
   thempg = input.nextDouble();

   thegallons = gallons;
   thempg = mpg; 

}


public double distance()
{
    distance = (mpg * gallons);
    return distance / miles; 
}

public double cost(){ 
     double cost = ((miles/mpg)/gallons)/COSTPERGALLON; 
     return cost;
}
}   

0 个答案:

没有答案