Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-11-2008, 11:34 AM
Member
 
Join Date: Nov 2008
Posts: 14
Rep Power: 0
SKYLINEGTR is on a distinguished road
Default [SOLVED] Please help with java
shasduybhkvk yuvk yu

Last edited by SKYLINEGTR; 11-21-2008 at 02:45 PM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-11-2008, 11:43 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,431
Rep Power: 8
Fubarable is on a distinguished road
Default
You need to look up and use enums. Check the Sun tutorials for info on this.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-11-2008, 11:46 AM
Member
 
Join Date: Nov 2008
Posts: 14
Rep Power: 0
SKYLINEGTR is on a distinguished road
Default
enums?? never even heard of these but ok ill take a look

thx
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-11-2008, 11:52 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,504
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
There is a nice tutorial on Suns tutorial about enum in Java.

Java enum
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-12-2008, 11:35 AM
Member
 
Join Date: Nov 2008
Posts: 14
Rep Power: 0
SKYLINEGTR is on a distinguished road
Default
ok iv been reading some of them tutorials but im still stuck
I need to create an integer field to hold the directions and with enums where can i state its an int? And where do i stick the constants 1,2,3,4?? Well apparently i 'can' use these...but i guess i dont need to if i dont?

It cant just be this can it

private enum Direction { UP, DOWN, LEFT, RIGHT }
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-12-2008, 01:52 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,431
Rep Power: 8
Fubarable is on a distinguished road
Default
Enums can hold and return ints or Strings or anything else just like a regular class. Look at the tutorial and it will show you how to do this.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 11-12-2008, 05:09 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,504
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Yes enums can holds and return any primitive data type. Seems to me you don't have clearly read about enums.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 11-12-2008, 08:01 PM
Member
 
Join Date: Nov 2008
Posts: 14
Rep Power: 0
SKYLINEGTR is on a distinguished road
Default
indeed actually its only my 2nd month leanring java and iv never heard or read about enums before

If I write a possible solution can someone atleast say if its right or wrong please..im going to work on it now..
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 11-13-2008, 04:52 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,504
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Now you have create an enum Direction, and it's hold all directions you want.

Define an object of Direction and in simple way, in a switch-case block refer the direction you want.

Code:
public class DirectionUse {
     Direction direction;

     public DirectionUse(Direction direction) {
         this.direction = direction;
     }

     public void EnumUsingHere() {
         switch(direction) {
              case UP:
                    System.out.println("Up");
                    break;
              // all other cases as you need
         }
     }

     public static void main(String[] args) {
         DirectionUse use = new DirectionUse(Direction.UP);
         use.EnumUsingHere()
     }
}
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 11-13-2008, 11:48 AM
Member
 
Join Date: Nov 2008
Posts: 1
Rep Power: 0
laxminarayana is on a distinguished road
Default
hello hai i want help to develop java coding
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 11-13-2008, 07:32 PM
Member
 
Join Date: Nov 2008
Posts: 14
Rep Power: 0
SKYLINEGTR is on a distinguished road
Default
Thx for your help guys, i managed to complete that class now but i just need a question answering on the next part now

OK, say. I had a class called Cars and now another called Person.
Im going to create a field which contains an array of car objects, but initially it wont contain any cars

So for this do i just have something like the following field and declare later in the constructor about the CAR Objects?:

private double[] cars;


Thanks
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 11-13-2008, 08:41 PM
Member
 
Join Date: Nov 2008
Posts: 14
Rep Power: 0
SKYLINEGTR is on a distinguished road
Default
actually forget that...that isnt the problem tbh
iv declared the following field (array)

private double[] cars;

now in the constructor im trying to initialise the array so it can hold 6 objects from the 'Cars' class itself....im not sure what else to enter in the code..this is what i have...

Cars = new double[6];

but this doesnt refer to the cars class so how do i do that?? :S
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 11-14-2008, 05:26 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,504
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
An array is a collection of same data type.

Code:
private double[] cars;
This is an array of double values, data type is double. If you want to hold an object, array must holds relevant object types. You have to do something like this.

Code:
Cars[] car_array = new Cars[6];
Until you added any object, null objects are contain.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 11-14-2008, 02:19 PM
Member
 
Join Date: Nov 2008
Posts: 14
Rep Power: 0
SKYLINEGTR is on a distinguished road
Default
ah so thats how you link it...thx!
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 11-14-2008, 05:52 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,504
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Did you solve the question? What you mean by link?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 11-14-2008, 06:59 PM
Member
 
Join Date: Nov 2008
Posts: 14
Rep Power: 0
SKYLINEGTR is on a distinguished road
Default
dont worry that part is solved
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 11-15-2008, 04:20 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,504
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
So it' better if you can mark the thread solved.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 11-15-2008, 02:10 PM
Member
 
Join Date: Nov 2008
Posts: 14
Rep Power: 0
SKYLINEGTR is on a distinguished road
Default
ok calm down
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 11-17-2008, 05:28 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,504
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Originally Posted by SKYLINEGTR View Post
ok calm down
I'm always. Want to make our community is the best place.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #20 (permalink)  
Old 11-18-2008, 01:09 AM
Member
 
Join Date: Nov 2008
Posts: 14
Rep Power: 0
SKYLINEGTR is on a distinguished road
Default
jhujbvyeddc tf tf ju

Last edited by SKYLINEGTR; 11-21-2008 at 02:46 PM.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +2. The time now is 11:00 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org