/** * TravelCost computes the cost of travel using a vehicle. * * @author (Andrew Samuels) * @version (02-04-2010) */ //importing Scanner from library import java.util.Scanner; public class TravelCost { public static void main(String[] args) { //create variables int travelDistance; //travel distance in miles int gasolineUsage; //gasoline usage in miles per gallon double gasolinePrice; //gasoline price in dollars per gallon double totalTravelCost; //The total cost of traveling //Create Scanner Scanner keyboard = new Scanner(System.in); //capture travel distance from user System.out.print("Please enter travel distance (miles): "); travelDistance = keyboard.nextInt(); //capture gas usage from user System.out.print("Please enter gas usage of vehicle (miles per gallon): "); gasolineUsage = keyboard.nextInt(); //capture gas price from user System.out.print("Please enter gas price (dollars per gallon): "); gasolinePrice = keyboard.nextDouble(); //Calculate totalTravelCost = (travelDistance/gasolineUsage)*gasolinePrice; //print total travel cost System.out.println("The total travel cost (dollars): " + totalTravelCost); } }
I am a software engineer with a computational physics focus. The purpose of this blog is to showcase my ideas and works. I can create value and reduce costs for your company.