Lift Operation – Program Development in Java Interesting !!!

import java.awt.geom.*;

public class elevator
{

    static int floor;

    public static void main(String args[])
    {

        floor = (int) (Math.random() * 10 + 1);

        System.out.println("The elevator is now on floor " +floor);
        System.out.print("Which floor are you at now (0-10) where 0 = basement: ");
        int current_floor = Keyboard.readInt();

        if(floor == current_floor)
        {
            System.out.println("Enter the elevator");
        }
        else
        {
            MoveElevator(current_floor);
        }


        System.out.println("To which floor would you want to go (0-10) where 0 = basement");
        int target_floor = Keyboard.readInt();

        MoveElevator(target_floor);
    }

    public static void MoveElevator(int target_floor)
    {
        int direction;
        if( target_floor > floor )
        {
            System.out.println("The elevator is on it's way up...");
            direction = 1;
        }else{
            System.out.println("The elevator is on it's way down...");
            direction = -1;
        }

        while(target_floor != floor)
        {
            floor += direction;
            System.out.println(floor);
        }

        System.out.println("The elevator has arrived");
    }
Advertisements

About ashokabhat

I am a C,C ,JAVA,Adobe Flex,.NET Programmer Currently working as a Software Developer
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s