-
Java code problem?
Hi all! My assignment question is this:
Write a program that asks the user to input
• The number of gallons of gas in the tank
• The fuel efficiency in miles per gallon
• The price of gas per gallon
Then print the cost per 100 miles and how far the car can go with the gas in the tank.
Thus far, I've written the code:
public class assignmenti
{
public static void main ( String args[] )
{
Scanner keyboard = new Scanner(System.in);
double gallons, milesPerGallon, pricePerGallon;
//Get input
System.out.println("Gallons in the tank?");
gallons = keyboard.nextdouble();
System.out.println("Fuel efficiency?");
milesPerGallon = keyboard.nextdouble();
System.out.println("Price of gas per gallon?");
pricePerGallon = keyboard.nextdouble();
// Print output
System.out.println("Cost per 100 miles:" + ((100/milesPerGallon) * pricePerGallon) + "Dollars");
System.out.println("How far the car can go:" + (gallons * milesPerGallon) + "miles");
}
}
But it won't compile inside my terminal. Anyone see any detrimental errors here as to why my program isn't working?
-
Re: Java code problem?
Please copy the full text of the error messages and paste it here.
Please edit your post and wrap your code with
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
-
Re: Java code problem?
hi
just making sure you imoported the needed class for your scanner.
import java.util.*;
this must be at the very top of your code.
also keyboard.nextdouble();
you must use capitals on the doubles
keyboard.nextDouble();
i fixed those 4 things and it now compiles
hope this helps
-
Re: Java code problem?
Oh, didn't realize I wasn't capitalizing the doubles. I fixed that and it compiled for me too. Thanks a load!
-Scorks