Advertisement
deww1

BPA Contest 2006

Nov 16th, 2011
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. //package bpa;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  *
  7.  * @author Devin Mitchell
  8.  */
  9. public class SpeedingHighway {
  10.  
  11.     private static int l; //speed limit
  12.     private static int s; //speed driving
  13.     private static int d; //distance
  14.  
  15.     public static void main(String args[]) {
  16.         Scanner sc = new Scanner(System.in);
  17.  
  18.         l = sc.nextInt(); //initiating speed limit
  19.         s = sc.nextInt(); //initiating driving speed
  20.         d = sc.nextInt(); //initiating distance
  21.         int time = 0;
  22.  
  23.         if ( l < 0 || s < 0 || d < 0) { // checks if 3 positive integers were entered
  24.             System.out.println("You must enter 3 positive numbers!");
  25.             return;
  26.         }
  27.  
  28.         if (s >= l) {
  29.             time = (int)(60 * ((double) d / l)) - (int)(60 * ((double) d / s)); // calculates the time saved
  30.            
  31.             System.out.println();
  32.             System.out.println(time + " minutes saved.");
  33.         }
  34.     }
  35. }
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement