Two Plus Two Older Archives  

Go Back   Two Plus Two Older Archives > Internet Gambling > Internet Gambling
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-08-2005, 11:54 PM
Shilly Shilly is offline
Senior Member
 
Join Date: Aug 2004
Location: Madison, WI
Posts: 128
Default Java Help Needed

This is not applicable to poker, but I figured that a lot of people here would be able to help me out with this.

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:00 AM
Prod1gy Prod1gy is offline
Junior Member
 
Join Date: Oct 2003
Posts: 4
Default Re: Java Help Needed

Little off topic but here goes. This is how I would do it.

private AirConditioner officeAC;
.
.
.
officeAC = new AirConditioner();
officeAC.turnOn();
officeAC.setTemp(69);
.
.
.

or you could do it like this. both do the same thing. Just the first example assumes that officeAC might be not be a local variable to a method.

AirConditioner officeAC = new AirConditioner();
officeAC.turnOn();
officeAC.setTemp(69);
.
.
.
Reply With Quote
  #3  
Old 02-09-2005, 12:06 AM
moondogg moondogg is offline
Senior Member
 
Join Date: Oct 2003
Posts: 145
Default Re: Java Help Needed

[ 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#
Reply With Quote
  #4  
Old 02-09-2005, 12:19 AM
RED_RAIN RED_RAIN is offline
Junior Member
 
Join Date: Nov 2003
Location: Plymouth, MN
Posts: 11
Default Re: Java Help Needed

Not to be a dick.

Just getting the answer won't help you in future java courses.

Especially if you are Csci major.

The stuff you are asking is extremely basic, if your book truely sucks that much, find a different one. I would suggest feeling comfortable with this stuff as it doesn't get easier than this.
Reply With Quote
  #5  
Old 02-09-2005, 12:36 AM
Bytestream Bytestream is offline
Senior Member
 
Join Date: Jul 2004
Posts: 116
Default Re: Java Help Needed

[ QUOTE ]
AirConditioner myAC = new AirConditioner(officeAC);

[/ QUOTE ]

I doubt his AirConditioner constructor is overloaded to take objects of type AirConditioner...
Reply With Quote
  #6  
Old 02-09-2005, 02:55 AM
NoTalent NoTalent is offline
Senior Member
 
Join Date: Sep 2003
Posts: 119
Default Re: Java Help Needed

There is no way your textbook is this bad. Please post the title and author.

This is the first thing you learn in OO programming. Search for "java object tutorial" or something on google and you can figure this out in 3 seconds...
Reply With Quote
  #7  
Old 02-09-2005, 03:04 AM
Al P Al P is offline
Senior Member
 
Join Date: Jan 2005
Location: Micro Short-Handed
Posts: 239
Default Re: Java Help Needed

I forget java but in VB.NET

OfficeAC is a type of AirConditioner.

Dim OfficeAC as new AirConditioner()

Turn on Air

OfficeAC.turnOn()

Set Temp

OfficeAC.setTemp(69)

Turn Off

OfficeAC.turnOff()

Destroy it ala Office Space Style

OfficeAC = Nothing

It should look similar in java. It's not that hard really.
Reply With Quote
  #8  
Old 02-09-2005, 03:35 PM
SamJack SamJack is offline
Senior Member
 
Join Date: Sep 2003
Posts: 436
Default 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
Reply With Quote
  #9  
Old 02-09-2005, 03:54 PM
moondogg moondogg is offline
Senior Member
 
Join Date: Oct 2003
Posts: 145
Default Re: Java Help Needed

Yeah, I thought Java may have that built-in as a copy constructor syntax. Apparently they don't, in which case I the alternate constructor code I put their should be used (IMHO)
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 01:01 AM.


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