0

hi norm,

but the whole codes has been posted few days ago. i remembered you asked for the whole codes :).

the for loop is just the addition of the codes.

0

check all the buttons pressed and when it finds it, go to that floor.

How does the code you posted change the movement to "go to that floor"?

There are no comments in the code so I have no idea what this statement is supposed to do:
if(app.control.bp == false) {

What is the Timer (tm) for?

0

hi norm,

sry bout that. this is the codes with explanation. thanks. sry keep trouble you.

//this is to find the current floor pressed
        curFloor = currentFloor(current);
        //loop if the elevator needs to be stopped for a while
        if ((app.control.bp[curFloor] == true) && (yco % height == 0)) {

            //i become current floor
            int i = curFloor;
           
                //for loop to check all the floors below the current floor
                for(i = curFloor; i >= 0; i--) {
                    
                    //if all the floors below not being pressed
                    if(app.control.bp[i] == false) {
                       //move up (this is part i am not sure)
                }
            }
          

            //display pick passenger at which floor currently
            String line0 = ("Elevator is picking up passenger at floor " +
                    app.control.b[curFloor].getActionCommand().substring(1));
            app.state.setText(line0);
            
            //stop the timer
            stop();
            
            //start new timer to give time to load passengers
            tm = new Timer(this.drag, this);
            tm.setInitialDelay(this.delay);
            tm.setDelay(this.drag);
            
            //start the timer
            start();
            
            //clear all the state
            app.control.bp[curFloor] = false;
            app.control.b[curFloor].setBackground(Color.cyan);

        }
0

Another thing, where are the stop and start methods defined?

Nothing can be done without the whole program with definitions for all the stuff you use in the short code you've posted.

Can you explain what problem the code you posted is supposed to solve?
Have you designed what the code is supposed to do
Or are you writing code without any design?

0

hi norm,

Another thing, where are the stop and start methods defined?
- timer is not the issue here. but if you think it leads to the problemm, it defined under the elevator class

Nothing can be done without the whole program with definitions for all the stuff you use in the short code you've posted.

-do you want me to post all the codes here?

Can you explain what problem the code you posted is supposed to solve?
-
#

//if all the floors below not being pressed
#
if(app.control.bp[i] == false) {
#
//move up (this is part i am not sure) <----- This one
#
}

the problem is i tried to make it go up instead go down because after i press floor 5, it will check that i never press 1, 2, 3, 4 and its supposed to go up.instead..its still go down.

Have you designed what the code is supposed to do
Or are you writing code without any design?

- Yes. Absolutely. Without design. the codes wont even start.

Thanks.

0

hi norm,

the method performed event:

public void actionPerformed(ActionEvent e) {

        //register listener for slider
        app.getSlider().addChangeListener(this); 
        
        //change moving direction when hits the top and bottom
        if (yco == topy) {
            up = false;
            String line1 = "Elevator is going down";
            app.state.setText(line1);
        }
        if (yco == bottomy) {
            up = true;
            String line2 = "Elevator is going up";
            app.state.setText(line2);
        }

        //adjust Y coordinate to simulate elevator movement (up/down)
        if (up) {
            up();
        } else {
            down();
        }

        //this is to find the current floor pressed
        curFloor = currentFloor(current);
        //loop if the elevator needs to be stopped for a while
        if ((app.control.bp[curFloor] == true) && (yco % height == 0)) {

            //i become current floor
            int i = curFloor;

                //for loop to check all the floors below the current floor
                for(i = curFloor; i >= 0; i--) {

                    //if all the floors below not being pressed
                    if(app.control.bp[i] == false) {
                       yco -= dy0;
                       //move up (this is part i am not sure)
                }
                    else {
                        yco += dy0;
                        
                    }
            }
          

            //display pick passenger at which floor currently
            String line0 = ("Elevator is picking up passenger at floor " +
                    app.control.b[curFloor].getActionCommand().substring(1));
            app.state.setText(line0);

            //stop the timer
            stop();

            //start new timer to give time to load passengers
            tm = new Timer(this.drag, this);
            tm.setInitialDelay(this.delay);
            tm.setDelay(this.drag);

            //start the timer
            start();

            //clear all the state
            app.control.bp[curFloor] = false;
            app.control.b[curFloor].setBackground(Color.cyan);

        }

        //repaint the panel
        repaint();

        //update the state of elevator
    }

thanks.the codes with explanation is done with "//".

i am able to give further explanation about the codes and design if necessary.thanks.

0

hi norm,

compile no problem.

its just i could not get elevator detect that someone pressed another button. its supposed to go to that button instead going to lowest floor first and then go to that floor.

keep thinking of the logic but still cant get it right.

0

my logic is using for loop to check all the check all floors that is not being pressed and then move up the elevator to the button that is pressed only.

0

my logic is using for loop to
1)check all the check all floors that is not being pressed
2)then move up the elevator to the button that is pressed only.

Why do you only move up? What if you are at floor 5 and button 3 is pressed?

0

currently i just want to take it step by step. because now even i cant move the elevator up. :)

0

I'm not sure if I understand.
If the elevator is moving up and stops and someone presses a button on a higher floor the elevator is to move up to that floor. Your old program works that way. No change would be necessary.

Your statement of the logic did NOT say if the direction that the elevator was moving was to be tested or not.

0

yeah.my old program works that way. it will go all the way up and all the way down and stop when can find pressed button.

so the improvement here is to make the elevator not moving up or down all the way but move according to the button pressed. if no buttons pressed, just move up and down.

meaning i must test the moving elevator?thanks.

0

You need to test which direction the elevator is moving and change it if the button press is in the other direction.

0

hi,

i managed to make the elevator notice that there is another button being pressed and it will go up to go that floor.

but there is some issues here. i think its because of my for loop..its only checked for all non press buttons, but floors checked is pressed, it will not make the elevator move to that floor.

0

Again what is your logic to "make the elevator move to that floor"
There are four cases:
The elevator is above the floor and moving up
The elevator is above the floor and moving down
The elevator is below the floor and moving down
The elevator is below the floor and moving up

How do you detect each of these situations and
what do you change to make the elevator move where you want it to go?

0

Don't forget that you are allowed to press more than 1 button. And that an elevator with no buttons pressed either waits where it is, or returns to the ground floor and waits - it doesn't just "move up and down".

0

hi all,

i think i solved that already..

now the issue that i have is to convert the codes to run as applications and applet.

the problem is the applet can run. but it does not seem to accept the codes..and now cant even see the println to test for any variables.

and i followed the standard of creating applicationa and applet.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.