Re: Java Help Needed
[ QUOTE ]
[ QUOTE ]
Little off topic but here goes. This is how I would do it.
private AirConditioner officeAC;
.
.
.
officeAC = new AirConditioner();
officeAC.turnOn();
officeAC.setTemp(69);
.
.
.
[/ QUOTE ]
One slight difference in how I read the question
[ QUOTE ]
There is a reference variable officeAC of type AirConditioner . Create a new object of type AirConditioner using the officeAC reference variable.
[/ QUOTE ]
//Assumed officeAC has already been defined and initialized
//Not sure this is valid Java syntax, but they do ask for a "new" object
AirConditioner myAC = new AirConditioner(officeAC);
//If this isn't valid, use AirConditioner myAC = officeAC;
//The rest is the same
officeAC.turnOn();
officeAC.setTemp(69);
Edit: P.S. I hate Java. Learn C++ or C#
[/ QUOTE ]
If we are entertaining toughts that AirConditioner class has contructors other than the default one.
officeAC = new AirConditioner(true); // constructor determines if the airconditioner is on or off at creation time.
officeAC.setTemp(69);
OR
officeAC = new AirConditioner(69); // creates the air conditioner with the temperature already set @ 69
|