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 17 of 17

Thread: Bluej issue

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Bluej issue

    Hi there, i am trying to declare 4 types of fish food types in the constructor but keep getting compiling problems so was wondering how to do it?

    :foodType = "fish food pellets" || "spirulina tablets";

    The code above is situated in the constructor.

    Need help urgent thanks.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Bluej issue

    getting compiling problems
    Please post the full text of the compiler error messages and the code that is causing the errors.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bluej issue

    Hi there, it said : " bad operand types for binary operator '||'

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Bluej issue

    Please post the full text of the compiler error messages and the code that is causing the errors, not just part of the message, the full text.

    The || operator has boolean operands, not Strings.
    (a > 2) || (c < 1)
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bluej issue

    This is the code and the line which is causing problems is within ##
     
    /*
     * This is the class in which the fish will be feed when i am out and not home
     */
     
    public class FishFeeder
    {
        private int amountFood;
        private int flareAmount;
        public String foodType;
     
        public FishFeeder ()
        {
            amountFood = 100;
            flareAmount = 5;
            ##foodType = "fish food pellets" OR "spirulina tablets";##
        }
     
        public int getFlareAmount ()
        {
            return flareAmount;
        }
     
       public void changeFoodType (String newFishFood )
       {
           foodType = newFishFood;
        }

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Bluej issue

    foodType = "fish food pellets" OR "spirulina tablets";
    A variable can be assigned one value with an assignment statement.
    I have no idea what that statement is trying to do. You can't make up new syntax that the compiler does not understand. You have to use syntax it understands.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bluej issue

    Thanks for the reply, but that doesnt work either as its saying i need ";" after the: "fish food pellets"(..

    what is the problem here?

    Thanks alot

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Bluej issue

    Please copy full text of error message and paste it here. Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    And the source statements that caused it.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bluej issue

    Sorry i am unable to get an error message to that extend as i am using bluej sorry but all that is said is: ";" is expected.

    Thanks

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Bluej issue

    ";" is expected.
    That seems like a very clear error message. What is the problem you are having with it?
    The compiler wants a ; so add a ; where the compiler is telling you to put it.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bluej issue

    If i am to put the ";" after :foodType = "fish food pellets". Then the rest of that code will be dismissed and it says that the line of code is not a statement.

    Cheers

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Bluej issue

    Add // after the ; and the compiler should be happy.

    You never explained what you are trying to do
    nor have you posted the code with the error.
    I can't see over your shoulder to know what is causing the problem.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bluej issue

    Im trying to store different types of food in this class called fishfeeder, and when declaring these values as such i am having the specified issued.

    What you just recently told me creates a comment which is defying the purpose of the code.

    Thanks

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Bluej issue

    store different types of food in this class
    Define a variable for each type
    or put the different types into an array or arraylist.

    Done for tonight. Back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bluej issue

    Im trying to store different types of food in this class called fishfeeder, and when declaring these values as such i am having the specified issued.

    What you just recently told me creates a comment which is defying the purpose of the code.

    Thanks

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Bluej issue

    Would a container like an ArrayList solve your problem?
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Bluej issue

    So are you trying to have the food type say "fish food pellets or spirulina tablets", or are you trying to get the food type to say either "fish food pellets" or "spirulina tablets"?

Similar Threads

  1. [SOLVED] Bluej problem with adding an object from one class to another.
    By BeardedAxeWound in forum Object Oriented Programming
    Replies: 1
    Last Post: August 13th, 2012, 07:48 PM
  2. bluej some questions about a simple car details class
    By infernocy in forum Object Oriented Programming
    Replies: 5
    Last Post: April 9th, 2012, 05:32 AM
  3. Make brick wall using BlueJ
    By boumasmoud in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 3rd, 2011, 04:32 PM
  4. Help in programming question. Bluej complier
    By Rads23 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: August 3rd, 2011, 09:12 PM
  5. Replies: 7
    Last Post: July 21st, 2011, 02:29 PM