Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Range Calculator

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Range Calculator

    I am attempting to create a range calculator that will calculate the amount of fuel needed to reach a destination. I have done what I know so far and just need help finishing up a few sections so that it is in working order. Specifically, I am having the most trouble with calculating the number of gallons and liters and the run-time error.

     
    /********************************************************
     * This class will calculate the number miles a car
     * can travel given the number of gallons of fuel,
     * and the MPG of the car can achieve. 
     *
     * @author
     * @version 
     ********************************************************/
     /*******************************************************
     *  References and Acknowledgements: 
     *  
     *
     ********************************************************/
    import java.util.Scanner; // needed for keyboard input
     
    public class RangeCalculator
    {  // START class RangeCalculator
     
    	/*****************************************************
    	 * main method
    	 *
    	 * @param 
    	 * @return
    	 *****************************************************/
     
    	public static void main(String args[])
    	{  // START main method
    		System.out.print("Welcome to the CSCI200 Range Calculator.\n");			// Welcome Message
    		System.out.println();
    		Scanner user_input = new Scanner(System.in);
    		String destination;
    		System.out.print("Type the name of your destination:");
    		destination = user_input.next();
    		String number_of_miles;
    		System.out.print( destination + " is how many miles away?");
    		number_of_miles = user_input.next();
     
     
    		System.out.print(  + "is not valid.  I will use 100 for the number of miles.");
    		System.out.println();
     
     
    		// Declarations
     
    		Scanner input = new Scanner(System.in);		                // keyboard input
    		int finalDestination;								// Your final destination
    		int numberOfMiles;							        // # of miles needed to travel (int)
    		final int MPG = 23; 								// # of miles per gallon
    		final double LITERS_CONVERSION = 3.78541178;	                // conversion factor for liters
    		double fuelGallons;								// # of gallons (double)
    		double fuelLiters;									// # of liters (double)
     
    		// Instantation
    		finalDestination = destination;
    		numberOfMiles = number_of_miles;
     
     
     
    		// Prompts and Input
     
     
    		// Action code
     
    																	// Calculate number of gallons
    																	// Calculate number of liters
     
    		// Output
    		String distance;
    		System.out.print("\n%s is %d miles away.  You will need %.2f gallons, or %.4f liters of fuel.");
     
    	} // END main method
     
    } // END class RangeCalculator

    Any help with finishing this code is appreciated! Thank you.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,722
    Thanks
    45
    Thanked 1,974 Times in 1,948 Posts

    Default Re: Range Calculator

    the run-time error.
    If you want help with the error, you need to copy the full text of the error message and pasted it here.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. String Index Out of range
    By Shikha Jain in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 24th, 2012, 09:14 PM
  2. String index out of range?
    By oksmartypants in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 19th, 2012, 01:10 PM
  3. Help with my Range Finder programme
    By kidza12 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 3rd, 2011, 12:53 PM
  4. String Index out of range
    By petemyster in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 8th, 2010, 02:59 PM
  5. [SOLVED] Help; algorithm to determine 'range'
    By b_jones10634 in forum Algorithms & Recursion
    Replies: 13
    Last Post: August 24th, 2010, 04:57 PM