LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 703 users online 225046 members 1599 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
ComfortableSilence
I haven't filled out my profile...
Days Active: 9
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
6 online / 28 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

Return Statements (Java)
Replies: 5Last Post Oct. 29, 2008 6:22pm by matto
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( Majo )


Soothsayer
Reply
Code:
public boolean validateScore(int score)
{
if((score >= 0) && (score <= 100))
{
return true;
}
return false;
}

What exactly is going on here? If the condition is met, "return true". If it's not, "return false"....which means?...

What do the return statements, in this case, do?

-------
"Under the hardness of her facade a woman's heart is still beating."


12:55 pm on Oct. 29, 2008 | Joined: May 2005 | Days Active: 301
Join to learn more about Majo Pennsylvania, United States | Straight Female | Posts: 6,733 | Points: 10,531
LiveWire Humor
UltimaTaz

Swami

Patron
Reply
Looks like it's a fail-fail test.

-------
There's an elephant in my birdbath

12:57 pm on Oct. 29, 2008 | Joined: Aug. 2007 | Days Active: 540
Join to learn more about UltimaTaz Maryland, United States | Straight Male | Posts: 20,345 | Points: 25,502
Ethryx


Enlightened One

Patron
Tech Support Leader
Reply
The function will return true if the score is between 0 and 100, including 0 and 100. If its lower then 0 or higher then 100 then it will return false.

-------
"It is hard to fail, but it is worse never to have tried to succeed."
- Theodore Roosevelt

12:57 pm on Oct. 29, 2008 | Joined: Jan. 2007 | Days Active: 633
Join to learn more about Ethryx New York, United States | Straight Male | Posts: 5,268 | Points: 15,290
( Majo )


Soothsayer
Reply
Quote: from Ethryx at 3:57 pm on Oct. 29, 2008

The function will return true if the score is between 0 and 100, including 0 and 100. If its lower then 0 or higher then 100 then it will return false.

But how does that validate the value? I mean...what does that do? True/False doesn't get printed out so what happens? You call the method and then...it checks...but then what happens with/to the true/false?

-------
"Under the hardness of her facade a woman's heart is still beating."


1:03 pm on Oct. 29, 2008 | Joined: May 2005 | Days Active: 301
Join to learn more about Majo Pennsylvania, United States | Straight Female | Posts: 6,733 | Points: 10,531
Ethryx


Enlightened One

Patron
Tech Support Leader
Reply
Quote: from Majo at 4:03 pm on Oct. 29, 2008

Quote: from Ethryx at 3:57 pm on Oct. 29, 2008

The function will return true if the score is between 0 and 100, including 0 and 100. If its lower then 0 or higher then 100 then it will return false.
 

But how does that validate the value? I mean...what does that do? True/False doesn't get printed out so what happens? You call the method and then...it checks...but then what happens with/to the true/false?



Let me put this into a real example for you:

int Score = 85;
boolean ScoreValid;

ScoreValid = validateScore(Score);
if(ScoreValid == true)
{
// put coding here when the user entered a valid score between 0 and 100
}
else
{
// this would be an error since the score is either lower then 0 or higher then 100. tell the user to re-enter the score
}

** As you can see, the function validateScore (which you wrote the coding to above) is going to return a true/false value to, in this case, the variable ScoreValid based on the integer that is passed too it (Score). If the variable Score contains a number between 0 and 100, ScoreValid will be true because validateScore will set it to true. If it is below 0 or above 100, ScoreValid will be false because validateScore will set it to false. The user of this java program does not see this true/false value. This is just a way of checking that a valid 'score' was submitted and not something else.

Hope that helps, let me know if you still don't understand.

Post edited at 1:29 pm on Oct. 29, 2008 by Ethryx

-------
"It is hard to fail, but it is worse never to have tried to succeed."
- Theodore Roosevelt


1:28 pm on Oct. 29, 2008 | Joined: Jan. 2007 | Days Active: 633
Join to learn more about Ethryx New York, United States | Straight Male | Posts: 5,268 | Points: 15,290
matto

Enlightened One

Patron
Reply
'boolean' is a data type that holds two possible values: true or false.  Just like 'int' and 'char' are kinds of data types.

This means that any boolean value, once computed, will have a value of true or false.

Some examples of boolean values:
true
false
(x > 7) (true if x is > 7, false if x<=7)
validateScore(100) (true)
validateScore(30) (true)
validateScore(-5) (false)

The method 'validateScore' returns a boolean value to wherever it is called.  These boolean values can be used in if() statements and while() statements, and places like that. Within the () there must be a boolean value.

Post edited at 6:26 pm on Oct. 29, 2008 by matto

-------
"Say what you like about the tenets of National Socialism, Dude,
at least it's an ethos."
--Walter Sobchak


6:22 pm on Oct. 29, 2008 | Joined: Aug. 2007 | Days Active: 496
Join to learn more about matto California, United States | Male | Posts: 9,856 | Points: 15,601
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic