Hello, ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Err or: Hotel.java:4: Undefined variable: running running = false; ^ Error: Hotel.java:21: No variable running defined in class Elevator. if (!(NorthElevator.running)) ^ Error: Hotel.java:25: No variable running defined in class Elevator. if (!(SouthElevator.running)) ^ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++WHEN I TRIED TO COMPILE THE TEXT BELOW I GOT THE ERRORS ABOVE CAN YOU SUGGEST WHAT TO DO ? +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++clas s Elevator { boolean runnig = true; void shutDown() { running = false; }
}
class FrontDesk { private final int EVENING = 8; Elevator NorthElevator, SouthElevator;
FrontDesk() { //the class sonstructor NorthElevator = new Elevator(); SouthElevator = new Elevator(); } void maintenance(int time) { if (time == EVENING) NorthElevator.shutDown(); } void displayStatus() { // code is very inefficient, but serves a purpose System.out.print("North Elevator is "); if (!(NorthElevator.running)) System.out.print("not "); System.out.println("running."); System.out.print("South Elator is "); if (!(SouthElevator.running)) System.out.print( " not "); System.out.println("running."); } } public class Hotel { public static void main(String args[]) { FrontDesk lobby; lobby = new FrontDesk();
System.out.println("It's &:00. Time to check the elevators."); lobby.maintenance(7); lobby.displayStatus();
System.out.println(); System.out.println("It's 8:00. Time to check the elavators."); lobby.maintenance(8); lobby.displayStatus(); }
: CAN YOU SUGGEST WHAT TO DO ? : class Elevator { : boolean runnig = true;
Try a) changing "runnig" to "running" (forgot an n) b) making the variable public, i.e. change the line into "public boolean running = true" (I don't know the scoping reules by heart, but it could be that the standard visibility is: not visible for other classes -- but I may be wrong...)
ma...@patrol.i-way.co.uk wrote: > Error: Hotel.java:4: Undefined variable: running > running = false; > ^ > Error: Hotel.java:21: No variable running defined in class Elevator. > if (!(NorthElevator.running)) > ^
[snip!]
>class Elevator { > boolean runnig = true;
^^^^^^ This is mispelled, should be running...
--Joe
___________________________________________________________________ Joseph A. Millar FTP Software, Inc. Software Engineer Ph: (508) 684-6461 100 Brickstone Square jmil...@ftp.com Fax:(508) 684-6992 Andover, MA 01810 http://www.ftp.com USA
In <31D5A43F.2...@patrol.i-way.co.uk>, ma...@patrol.i-way.co.uk writes: >CAN YOU SUGGEST WHAT TO DO ? >+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++cla ss Elevator { > boolean runnig = true; > void shutDown() { > running = false;
If this is just a simple cut and paste, then you should note that initially you've decleared a boolean variable called "runnig" and then later referred to it as "running".