Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Boolean variable problem

  1. #1
    Member
    Join Date
    Aug 2013
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs down Boolean variable problem

    This, once again, is my school assignment that I need help on.

    problem:

    When you go on a date, you rate your date's fashion sense on a scale from 0 to 10. As a general rule, if the rating is 8 or more, then you will consider going out again with the same person. However, if your date's parents are wealthy, you will consider going out again with him or her if the rating is 7 or more.

    If the int r contains your date's rating from 0 to 10 and the boolean w contains true if and only if your date's parents are wealthy, write code that will set d to true if and only if you will consider going on another date with the same person.

    Here's what I've gotten to so far:

     
    d = r > 8; 
    if (w = true);
        d = r > 7;

    Thanks.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Boolean variable problem

    I know the variable names were given to you, but when you have the flexibility, give your variables decent names. Single letter variable names are only acceptable as loop control variables, and that's more by convention than anything else. Give even loop control variables longer names if it helps you understand your program better.

    It also helps to comment your code. In this case, just follow the instructions given in the assignment:
    // if the date's fashion sense, r, is greater than or equal to 8, consider going out again:
    if ( r >= 8 )
    {
        // d is true if another date is possible
        d = true;
    }
     
    // or if the parents are wealthy, w is true, then the date is acceptable with a fashion sense of 7 or more
    if ( w && r >= 7 )
    {
        d = true;
    }
    That's not the answer, because the OR that begins the second comment has to be included in the code somewhere, and the value of d for the case when the date is not acceptable has to be set. You should be able to figure those details out.

Similar Threads

  1. Boolean problem
    By RepersGhost in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 8th, 2013, 07:05 AM
  2. boolean problem.
    By Leonardo1143 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 13th, 2013, 05:32 PM
  3. Boolean Method Test Problem
    By Khadafi in forum Java Theory & Questions
    Replies: 4
    Last Post: January 13th, 2012, 11:07 PM
  4. Problem printing a two dimensional boolean array
    By sallyB in forum What's Wrong With My Code?
    Replies: 10
    Last Post: June 23rd, 2011, 03:56 PM
  5. Boolean method returning a boolean value
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 10:56 AM

Tags for this Thread