Two Plus Two Older Archives

Two Plus Two Older Archives (http://archives2.twoplustwo.com/index.php)
-   Other Other Topics (http://archives2.twoplustwo.com/forumdisplay.php?f=32)
-   -   Java Help Needed (http://archives2.twoplustwo.com/showthread.php?t=192521)

Shilly 02-08-2005 11:26 PM

Java Help Needed
 
I'm in an Intro to Programming course that uses Java. For my Codelab assignments (little exercises online where you write a few lines of code, and they tell you if it is correct or not), I'm struggling with object creation. I'll list the instructions here:

Suppose there is a class AirConditioner . The class supports the following behaviors: turning the air conditioner on, off, and setting the desired temperature. The following methods are provided for these behaviors: turnOn and turnOff , which accept no arguments and return no value, and setTemp , which accepts an int argument and returns no value.

There is a reference variable officeAC of type AirConditioner . Create a new object of type AirConditioner using the officeAC reference variable. After that, turn the air conditioner on using the reference to the new object, and set the desired temperature to 69 degrees.


I know this will seem incredibly easy to someone with Java experience, but I'm having a mental block. I can't find anyting about it in this garbled textbook, and Codelab's suggestions are unhelpful.

Thanks in advance.

akaLogic 02-09-2005 12:44 AM

Re: Java Help Needed
 
AirConditioner pokerRoomAC = officeAC.clone();
pokerRoomAC.turnOn();
pokerRoomAC.setTemp( 69 );

Be sure AirConditioner implements cloneable.

If you haven't covered clone, the professor will certainly fail you for getting help.

natedogg 02-09-2005 01:28 AM

Re: Java Help Needed
 
"Create a new object of type AirConditioner using the officeAC reference variable."

I think all he means is this:

AirConditioner officeAC = new AirConditioner()

natedogg

Shilly 02-09-2005 02:39 AM

Re: Java Help Needed
 
Thanks for the replies. I know nothing about cloning yet, so I was basically lost looking at the first reply. I had already tried what you did in the second reply, but got a compiler error. I figured it out after tinkering around for a few minutes though. Thanks for the help.


All times are GMT -4. The time now is 07:22 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.