I am trying to write an elevator test program in java.
It is suppose to execute the following steps using the methods in the class:

1: Starting from the first-floor.
2: Go to 2nd (update bool GoingUp)
3: Go to 3rd
4: Back to second floor

This is what I have!

public class method {
public static void main(String[] args) {
direction currentfloor = new direction();
currentfloor.down();}

It's calling the class direction:

public class direction {
public void goDown()
{
System.out.println("Elevator is going down");
}

Now this part works good, but I am stuck with the second step where the new method GoingDown() is suppose to be a bool which i am not sure how to update or set it up, at least not in java :-/?

Edited 5 Years Ago by eny321: n/a

Let me make sure I understand you. You want to create a boolean variable who's value tells what floor you are on or whether or not you are going up or down.

here is how you create a boolean var:

Boolean [B]down[/B] = [B]true[/B];

can change the items in bold to the values you want.

To change its value simply call its var name in this case down.

For what you are doing I suggest using a integer var to keep track of the floor number.

int floor = 1;

then to change the floor call your method

currentfloor.GoUp();
//or
currentfloor.GoDown();

and all the method will do is increase or decrease the floor number.

public void GoUp(){
floor++;
}

Edited 5 Years Ago by DarkLightning7: n/a

Thanks, that's what I have been trying to figure out.
The IsGoingUp() method should print and display where the elevator is, like "elevator is going to second" third floor etc..
So calling from the main method GoingUp.IsGoingUp()
Should check what floor I am and simply output "The elevator is going to the second floor" the GoingDown.IsGoinDown() should do the same just reversed. My problem is with the actual set up I suppose!

Edited 5 Years Ago by eny321: n/a

Ok This works but does not update the floors. No meter hor often i call the GoingUp method.

Output: The Elevator is going to the 1 floor
public class control_panel {
    int floor = 1;

    public void GoingUp() {
        
        floor++;

    }
        public void IsGoingUp() {
            
            System.out.printf("The Elevator is going to the %d floor", floor);

        }
    }

Main Method

control_panel GoingUp = new control_panel();
        GoingUp.IsGoingUp();

Edited 5 Years Ago by eny321: n/a

here is a basic layout for code you fill it in. The problem with having methods that take time, like having the elevator go between floors, is that you need sleep actions so that it takes time for the elevator to travel. I highly doubt that you need that level of complexity. Just make it go to the floor.

public class method {
    public static void main(String[] args) {
        elevator one = new elevator;
        System.out.println("Current floor is: " + one.getFloor());
        System.out.println("Going up two floors.")
        one.goUp;
        one.goUp;
        System.out.println("New floor is: " + one.getFloor);
    }

    public class elevator {
        public void goDown(){
        }
        public void goUp(){
        }
        public void getFloor(){
        }
}

If you want it so say which floor it is going to from which floor simply put a print statement inside of the up and down events.

if anything that I posted does not make sense please tell me. ( ;

Edited 5 Years Ago by DarkLightning7: n/a

I am sorry. the word void should not be inside the elevator class simply remove them. leave everything else though. just delete the words.

Edited 5 Years Ago by DarkLightning7: n/a

Nice job DarkLightning7
but allow me to make a little adjustments to your code:

public class method {
    public static void main(String[] args) {
        elevator one = new elevator();
        System.out.println("Current floor is: " + one.getFloor());
        System.out.println("Going up two floors.")
        one.goUp;
        one.goUp;
        System.out.println("New floor is: " + one.getFloor);
    }
[U]}[/U]
    public class elevator {

        [U]int floor;
        boolean down;[/U]

        public void goDown(){
        }
        public void goUp(){
        }
        public [U]int[/U] getFloor(){
        }
}

I checked the code and here is what it should be

public class elevator {
   public static void main(String[] args) {
        move one = new move();
        System.out.println("Current floor is: " + one.getFloor());
        System.out.println("Going up two floors.");
        one.goUp();
        one.goUp();
        System.out.println("New floor is: " + one.getFloor());
    }
}

class move {
        int floor;

        public void goDown(){
            floor--;
        }
        public void goUp(){
            floor++;
        }
        public int getFloor(){
            return floor;
        }
}

Edited 5 Years Ago by DarkLightning7: n/a

how we can come down or up on some event occur for eg:I am on second floor instantly i want to go first floor and again up on third floor how i will invoke the methods bcoz there is no condition is given there

prateek: this thread is four years old.
You should try to write your own code, and when come into something you can't solve, start a new thread, showing your code and what you expect it to do and what it is actually doing (wrong).

Don't revive dead threads.

This article has been dead for over six months. Start a new discussion instead.