Guest User

Untitled

a guest
Jan 17th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. package assignment1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class DrivingCostCalculator {
  6.  
  7. public static double calculateGasTripCost(double milesToDrive, double milesPerGallon, double dollarsPerGallon) {
  8. return (milesToDrive / milesPerGallon) * dollarsPerGallon;
  9. }
  10.  
  11. public static void main(String[] args) {
  12. double milesToDriveInput = 0.0;
  13. double milesPerGallonInput = 0.0;
  14. double dollarsPerGallonInput = 0.0;
  15. double gasTripCostOutput = 0.0;
  16.  
  17. Scanner input = new Scanner(System.in);
  18.  
  19. System.out.print("Miles To Drive: ");
  20. milesToDriveInput = input.nextDouble();
  21. System.out.println();
  22.  
  23. System.out.print("Miles Per Gallon: ");
  24. milesPerGallonInput = input.nextDouble();
  25. System.out.println();
  26.  
  27. System.out.print("Dollars Per Gallon: ");
  28. dollarsPerGallonInput = input.nextDouble();
  29. System.out.println();
  30.  
  31. gasTripCostOutput = calculateGasTripCost(milesToDriveInput, milesPerGallonInput, dollarsPerGallonInput);
  32. System.out.println("Calculate Gas Trip Cost: " + gasTripCostOutput);
  33. }
  34.  
  35. }
Add Comment
Please, Sign In to add comment