• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

create a method

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"pegleg", please check your private messages for an important administrative matter.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 176
Mac Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic