Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- This program demonstrates the use of escape sequence and the system-out-println system outputs.
- @author John Rozsa
- @version 2/6/12
- CIS 1500
- */
- import java.util.Scanner;
- public class testgas
- {
- public static void main (String [] args)
- {
- double milesdriven, gallons, milespergallon, milesperweek, milespergallonofauto, currentcostofgas, milesperyear;
- //get information from the user
- // declares milespergallon = milesdriven divided by gallons
- System.out.println("WELCOME TO THE GAS CALCULATION PROGRAM.");
- System.out.println("How many miles you drive per week?");
- Scanner keyboard = new Scanner(System.in);
- milesperweek = keyboard.nextDouble();
- System.out.println("How many miles per gallon does your auto get?");
- milespergallonofauto = keyboard.nextDouble();
- System.out.println("What is the current cost of gas?");
- currentcostofgas = keyboard.nextDouble();
- milesperyear = 52.18 * milesperweek;
- //display information back to the user
- //calculate miles per year
- System.out.println ("At " + milesperweek + " miles per week you will travel " + milesperyear + " miles per year.\n");
- System.out.println ("Gallons per week " + (milesperweek/milespergallonofauto) + "\n");
- System.out.println ("Gallons per year " + (milesperweek/milespergallonofauto * 365) + "\n");
- System.out.println ("With gas at " + (currentcostofgas) + " per gallon, you will spend:\n");
- System.out.println ("Gas expence per week: " + (currentcostofgas) * milesperweek/milespergallonofauto + "\n");
- System.out.println ("Gas expense per year: " + (currentcostofgas) * milesperyear/milespergallonofauto + "\n");
- System.out.println ("If gas goes up by one dollar per gallon to " + (currentcostofgas + 1) + " per gallon, you will spend:\n");
- System.out.println ("Gas expense per week: " + (currentcostofgas + 1) * milesperweek/milespergallonofauto + "\n");
- System.out.println ("Gas expense per year: " + (currentcostofgas + 1) * milesperyear/milespergallonofauto + "\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement