Two Plus Two Older Archives  

Go Back   Two Plus Two Older Archives > 2+2 Communities > Other Other Topics
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-08-2005, 11:26 PM
Shilly Shilly is offline
Senior Member
 
Join Date: Aug 2004
Location: Madison, WI
Posts: 128
Default 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.
Reply With Quote
  #2  
Old 02-09-2005, 12:44 AM
akaLogic akaLogic is offline
Junior Member
 
Join Date: Sep 2002
Posts: 12
Default 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.
Reply With Quote
  #3  
Old 02-09-2005, 01:28 AM
natedogg natedogg is offline
Junior Member
 
Join Date: Dec 2003
Posts: 0
Default 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
Reply With Quote
  #4  
Old 02-09-2005, 02:39 AM
Shilly Shilly is offline
Senior Member
 
Join Date: Aug 2004
Location: Madison, WI
Posts: 128
Default 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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:02 AM.


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