Posted: Sat Sep 18, 2010 5:23 pm Post subject: Help with java
I need help with my java assignment or give me a example to complete this
1. Declare two variables of type double, one called avgConsumption, the other called distance.
2. Create a Scanner object as demonstrated in class to read-in all user input.
3. Have the user input the car's fuel effciency rating in litres per 100 km (L/100km) and assign this to the avgConsumption variable.
4. Have the user input the trip distance in kilometres (km) and assign this to the distance variable.
5. Declare another variable called fuelUsed to store the estimated number of litres of fuel used during the trip. (What type should this be?)
6. Calculate the litres of fuel used and assign this to the fuelUsed variable. Fuel used equals avgConsumption multiplied by the distance and then divided by 100.
7. Now display to the user the estmated amount of fuel that will be used. Display a message like "A trip of 250 km in this vehicle should consume about 28.275 litres of fuel".
code:
public class projectJ {
public static void main(String[] args) {
Scanner input = new Scanner(System.in); // 2
System.out.println("Car's fuel "); // Car's fuel effciency rating in litres per 100 km (L/100km) // 3
double avgConsumption = input.nextDouble();
// Estamted amount of fuel that will be used
System.out.println(" A trip of" + "km in this vehicle should consume about " fuelUsed + "litres of fuel");
} // end main
} // end class
Sponsor Sponsor
Tony
Posted: Sat Sep 18, 2010 6:10 pm Post subject: RE:Help with java
You already have step-by-step instructions for what to do. What part do you need help with?
// Calculate the litres of Fuel used // 6
double fuelUsed = avgConsumtion * distance / 100;
// Estamted amount of fuel that will be used
System.out.println(" A trip of" avgConsumption + "km in this vehicle should consume about " fuelUsed + "litres of fuel");
} // end main
} // end class
This is the part l'm getting errors from.
code:
// Estamted amount of fuel that will be used
System.out.println(" A trip of" avgConsumption + "km in this vehicle should consume about " fuelUsed + "litres of fuel");
Tony
Posted: Sun Sep 19, 2010 2:09 pm Post subject: Re: Help with java
Quote:
projectJ.java:15: ')' expected
System.out.println(" A trip of" avgConsumption + "km in this vehicle should consume about " fuelUsed + "litres of fuel");
.........................................^
The parser is expecting for you to close the parenthesis after " A trip of".