Advertisement
a1ananth

Untitled

Feb 12th, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. /**
  2. This program demonstrates the use of escape sequence and the system-out-println system outputs.
  3.  
  4. @author John Rozsa
  5. @version 2/6/12
  6. CIS 1500
  7.  
  8. */
  9. import java.util.Scanner;
  10.  
  11. public class testgas
  12. {
  13.     public static void main (String [] args)
  14.     {
  15.         double milesdriven, gallons, milespergallon, milesperweek, milespergallonofauto, currentcostofgas, milesperyear;
  16.        
  17.         //get information from the user
  18.         // declares milespergallon = milesdriven divided by gallons
  19.  
  20.         System.out.println("WELCOME TO THE GAS CALCULATION PROGRAM.");
  21.         System.out.println("How many miles you drive per week?");
  22.         Scanner keyboard = new Scanner(System.in);
  23.         milesperweek = keyboard.nextDouble();
  24.  
  25.         System.out.println("How many miles per gallon does your auto get?");
  26.         milespergallonofauto = keyboard.nextDouble();
  27.  
  28.         System.out.println("What is the current cost of gas?");
  29.         currentcostofgas = keyboard.nextDouble();
  30.  
  31.         milesperyear = 52.18 * milesperweek;
  32.  
  33.         //display information back to the user
  34.  
  35.         //calculate miles per year
  36.  
  37.         System.out.println ("At " + milesperweek + " miles per week you will travel " + milesperyear + " miles per year.\n");
  38.  
  39.         System.out.println ("Gallons per week " + (milesperweek/milespergallonofauto) + "\n");
  40.  
  41.         System.out.println ("Gallons per year " + (milesperweek/milespergallonofauto * 365) + "\n");
  42.  
  43.         System.out.println ("With gas at " + (currentcostofgas) + " per gallon, you will spend:\n");
  44.  
  45.         System.out.println ("Gas expence per week: " + (currentcostofgas) * milesperweek/milespergallonofauto + "\n");
  46.  
  47.         System.out.println ("Gas expense per year: " + (currentcostofgas) * milesperyear/milespergallonofauto + "\n");
  48.  
  49.         System.out.println ("If gas goes up by one dollar per gallon to " + (currentcostofgas + 1) + " per gallon, you will spend:\n");
  50.  
  51.         System.out.println ("Gas expense per week: " + (currentcostofgas + 1) * milesperweek/milespergallonofauto + "\n");
  52.  
  53.         System.out.println ("Gas expense per year: " + (currentcostofgas + 1) * milesperyear/milespergallonofauto + "\n");
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement