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();
}
}
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...)
Geert.
NEC SPE Geert.V...@rug.ac.be NEC METU
ge...@einstein.rug.ac.be
http://studwww.rug.ac.be/~gvernaev
>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
jmi...@ftp.com Fax:(508) 684-6992 Andover, MA 01810
http://www.ftp.com USA
>CAN YOU SUGGEST WHAT TO DO ?
>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++class 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".
boolean runnig = true;
And it should read:
boolean running = true;
- jb
ma...@patrol.i-way.co.uk wrote:
Error: Hotel.java:4: Undefined variable: running
running = false;
^
WHEN I TRIED TO COMPILE THE TEXT BELOW I GOT THE ERRORS ABOVE
CAN YOU SUGGEST WHAT TO DO ?
class Elevator {