• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

create a method

 
Sue Nair
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I am new to java and am having a little bit of trouble with some code. How do I create a method named isFull() that returns a boolean value? Thanks,
pegleg
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"pegleg", please check your private messages for an important administrative matter.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's your best attempt so far?
[ January 31, 2008: Message edited by: Bear Bibeault ]
 
Sue Nair
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
What's your best attempt so far?

[ January 31, 2008: Message edited by: Bear Bibeault ]


I tried to put

isFull=boolean();
but I don't think it is right
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right. It's not right.

What you showed there is a method reference, not a declaration. You do not specify the return type on a method reference.

Before referencing the method, you need to declare it. So what's the proper syntax for declaring a method?

Or, do already have the method declared elsewhere and are having trouble calling (referencing) it?
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pegleg:
Hi! I am new to java and am having a little bit of trouble with some code. How do I create a method named isFull() that returns a boolean value? Thanks,
pegleg


As Bear told, the creation of method has to deal with two aspects. One is having it (declaring as well defining it). Second is using it (referencing) from some other place.

Are you clear with these basics of methods? If not, please have a look at the tutorial on defining methods.
 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't quite see what your method is meant to do but if it just the boolean return part then I might be able to help.



Based on our program you may choose not to write "public" or "static"
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Olivier Legat:





Here, the compiler will definitely complain as the local variable 'x' is not initialized

Initializing the local variables before their first usage is NOT optional and its a must!

We were trying to help him to first get the basics and let him come up with his own code instead we give him the full code. Of course, that is the motto of NOT being a codemill.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49796
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oliver Legat is right in what he posted; You may not need to initialise the boolean variable because the next line will readI think it is reasonable for him to drop that sort of hint. The only thing I would disagree with is the bit about static. It will probably be the object which is "full," not the class, so the method almost certainly ought not to be static.
 
Sue Nair
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! That worked for me.

Originally posted by Olivier Legat:
I don't quite see what your method is meant to do but if it just the boolean return part then I might be able to help.



Based on our program you may choose not to write "public" or "static"
 
Campbell Ritchie
Sheriff
Pie
Posts: 49796
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by S Nair:
Thanks! That worked for me. . . .

Well done. Please post what you wrote, so other "greenhorns" can learn from it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic