Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with java
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
asianrandy




PostPosted: 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();
       

        // 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
       
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
asianrandy




PostPosted: Sat Sep 18, 2010 9:45 pm   Post subject: 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




PostPosted: Sun Sep 19, 2010 3:30 am   Post subject: RE:Help with java

What kind of errors are there?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
asianrandy




PostPosted: Sun Sep 19, 2010 12:02 pm   Post subject: 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



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




PostPosted: 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".
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Insectoid




PostPosted: Sun Sep 19, 2010 3:08 pm   Post subject: RE:Help with java

The ........^ is telling you exactly where the error is.
asianrandy




PostPosted: Mon Sep 20, 2010 11:43 am   Post subject: Re: Help with java

nvm guys i fix it 8)
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: