I know this is gonna be an easy fix, but I can't see it! Why won't this work?

import java.util.Scanner;
public class Elevator 

    {
public boolean doorOpen=false;
public int currentFloor = 1;
public final int TOP_FLOOR = 5;
public final int BOTTOM_FLOOR = 1;

public static void main(String args[])

    {
int op=0;
Scanner SO=new Scanner(System.in);
System.out.println("1-DOor Open \n 2-Door Close");
System.out.println("3-Go Up \n 4-Go Down");
System.out.println("5-To Select Desired Floor");
System.out.println("0-To Quit Program");
System.out.println("Your Option");
op=SO.nextInt();

    }
public void openDoor() 

    {
System.out.println("Opening door.");
doorOpen = true;
System.out.println("Door is open.");

    }

public void closeDoor() 

    {
System.out.println("Closing door.");
doorOpen = false;
System.out.println("Door is closed.");

    }
public void goUp() 

    {
System.out.println("Going up one floor.");
currentFloor++;
System.out.println("Floor: " + currentFloor);

    }
public void goDown() 

    {
System.out.println("Going down one floor.");
currentFloor--;
System.out.println("Floor: " + currentFloor);

    }
public void setFloor(int desiredFloor) 

    {
while (currentFloor != desiredFloor)

    {
if (currentFloor < desiredFloor)

    {
goUp();

    }
else 

    { 
goDown();

    }
    } 
    }
public int getFloor() 

    {
return currentFloor;

    }
public boolean checkDoorStatus()

    {
return doorOpen;

    }
    }

thanks for any help!

public static void main(String[] args) {
    // your menu
    switch(op) {
        //your decision logic
    }
}

ty cool zephyr. I took out what I had and I added what u suggested. I am still getting an error code that it can't find the symbol (op). Maybe I need to sleep on it and try again tomorrow.

op is your variable on line 13

I have modidifed your code a little, see if this helps....

import java.util.Scanner;

public class Elevator 



    {

public static boolean doorOpen=false;

public static int currentFloor = 1;

public final int TOP_FLOOR = 5;

public final int BOTTOM_FLOOR = 1;

static int op=0;

public static void main(String args[])



    {



Scanner SO=new Scanner(System.in);

System.out.println("1-DOor Open \n 2-Door Close");

System.out.println("3-Go Up \n 4-Go Down");

System.out.println("5-To Select Desired Floor");

System.out.println("0-To Quit Program");

System.out.println("Your Option");

op=SO.nextInt();


if(op==1){

    openDoor();
}else if(op==2){
    closeDoor();
}else if(op==3){
    goUp();
}else if(op==4){
    goDown();
}else if(op==4){
    setFloor(op);
}else{
    System.exit(0);

}


    }

public static void openDoor() 



    {

System.out.println("Opening door.");

doorOpen = true;

System.out.println("Door is open.");



    }



public  static void closeDoor() 



    {

System.out.println("Closing door.");

doorOpen = false;

System.out.println("Door is closed.");



    }

public static void goUp() 



    {

System.out.println("Going up one floor.");

currentFloor++;

System.out.println("Floor: " + currentFloor);



    }

public static void goDown() 



    {

System.out.println("Going down one floor.");

currentFloor--;

System.out.println("Floor: " + currentFloor);



    }

public static void setFloor(int desiredFloor) 



    {



while (currentFloor != desiredFloor)



    {

if (currentFloor < desiredFloor)



    {

goUp();



    }

else 



    { 

goDown();



    }

    } 

    }

public int getFloor() 



    {

return currentFloor;



    }

public boolean checkDoorStatus()



    {

return doorOpen;



    }

    }

The last "else if" statement i posted above should be op==5 not op==4, typo error

murali:

Here at DaniWeb we try to help people learn Java and develop their Java skills. We do NOT do people's homework for them. Your post explains and teaches nothing, it just gives the OP a chance to cheat. In future please help by pointing people in the right direction - eg tell them which classes and methods they should read about, or give them some sample code that they will have to understand and adapt to thier needs. If you feel you should correct someone's code then that's useless if you don't explain what you changed and why you changed it as you did. If you need to explain with actual code then explain why you coded it the way you did. Don't just spoon-feed them a solution to copy and paste.

Hi James,
I thought by seeing that he will understand... I wont post the entire code , will just suggest idea from now on...

Dennis_1 , you have defined your methods but you have not called them , so i just made a condition as per user input inside a nested If else and called each method accordingly. Hope this helps you to understand.

That's OK, thanks for understanding. Some people will take the time to study the before/after versions, see what's changed, and work out why... but many others wll just copy/paste. see it works, breath a sigh of relief and move on, with no gain of understanding. You never know at first which type the OP is :)

ps Your second para would have been a perfect initial answer to the question like this...

"Dennis_1 , you have defined your methods but you have not called them , so just make a condition as per user input inside a nested If else and call each method accordingly."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.