
-----------------------------------
asianrandy
Sat Sep 18, 2010 5:23 pm

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();
	

	// Trip distance in kilometres (km) // 4
	System.out.println("trip distance ")
	double distance = input.nextDouble();

	// 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"    + "km in this vehicle should consume about " fuelUsed + "litres of fuel");

		
	

 } // end main
} // end class
	[/code]

-----------------------------------
Tony
Sat Sep 18, 2010 6:10 pm

RE:Help with java
-----------------------------------
You already have step-by-step instructions for what to do. What part do you need help with?

-----------------------------------
asianrandy
Sat Sep 18, 2010 9:45 pm

Re: Help with java
-----------------------------------
I can't get it to work tho and there  are error and i don't know what to fix and l'm new to java

-----------------------------------
Tony
Sun Sep 19, 2010 3:30 am

RE:Help with java
-----------------------------------
What kind of errors are there?

-----------------------------------
asianrandy
Sun Sep 19, 2010 12:02 pm

Re: Help with java
-----------------------------------
[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(); 
        
        // Trip distance in kilometres (km) // 4 
        System.out.println("trip distance ");
        double distance = input.nextDouble(); 

        // 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 [/code]


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"); [/code]

-----------------------------------
Tony
Sun Sep 19, 2010 2:09 pm

Re: Help with java
-----------------------------------

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".

-----------------------------------
Insectoid
Sun Sep 19, 2010 3:08 pm

RE:Help with java
-----------------------------------
The ........^ is telling you exactly where the error is.

-----------------------------------
asianrandy
Mon Sep 20, 2010 11:43 am

Re: Help with java
-----------------------------------
nvm guys i fix it 8)
