Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Homework Assignment 5 - Elevator
- ---------------------------------
- import java.util.Scanner;
- public class Elevator {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- // Data to be retrieved by the user
- int startFloor, destFloor, elevInFloor;
- // Constants that will be used by the program
- final int timeBetweenFloors = 3;
- final int timeInFloor = 5;
- // Getting data from the user
- System.out.println("Please enter your floor: ");
- startFloor = s.nextInt();
- System.out.println("Please enter the destination floor: ");
- destFloor = s.nextInt();
- System.out.println("Please enter the elevator position (floor number): ");
- elevInFloor = s.nextInt();
- // Calculating the total time and printing the result to the console
- System.out.println("The amount of time for reaching your floor destination is: " +
- ((Math.abs(startFloor-elevInFloor)*timeBetweenFloors) + timeInFloor +
- Math.abs(startFloor-destFloor)*timeBetweenFloors));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement