Advertisement
eranseg

Elevator

Jul 21st, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. Homework Assignment 5 - Elevator
  2. ---------------------------------
  3. import java.util.Scanner;
  4.  
  5. public class Elevator {
  6.     public static void main(String[] args) {
  7.         Scanner s = new Scanner(System.in);
  8.         // Data to be retrieved by the user
  9.         int startFloor, destFloor, elevInFloor;
  10.         // Constants that will be used by the program
  11.         final int timeBetweenFloors = 3;
  12.         final int timeInFloor = 5;
  13.         // Getting data from the user
  14.         System.out.println("Please enter your floor: ");
  15.         startFloor = s.nextInt();
  16.         System.out.println("Please enter the destination floor: ");
  17.         destFloor = s.nextInt();
  18.         System.out.println("Please enter the elevator position (floor number): ");
  19.         elevInFloor = s.nextInt();
  20.         // Calculating the total time and printing the result to the console
  21.         System.out.println("The amount of time for reaching your floor destination is: " +
  22.                          ((Math.abs(startFloor-elevInFloor)*timeBetweenFloors) + timeInFloor +
  23.                            Math.abs(startFloor-destFloor)*timeBetweenFloors));
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement