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.

Page 2 of 2 FirstFirst 12
Results 26 to 34 of 34

Thread: Setters and getters

  1. #26
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Setters and getters

    dddddddddddddddddddddddddddddd

  2. #27
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Setters and getters

    geteggPrawn is undefined for pizza
    The compiler is usually correct. Check why.

    Without definitions and code, I can't see what is wrong.

    eggPrawn.eggPrawn.seteggPrawn
    That is unusual looking and confusing code.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #28
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Setters and getters

    Quote Originally Posted by Norm View Post
    The compiler is usually correct. Check why.

    Without definitions and code, I can't see the what is wrong.

    eggPrawn.eggPrawn.seteggPrawn
    That is unusual looking and confusing code.
    Yeah but the compiler is telling me that "The method geteggPrawn() is undefined for the type Pizza" yet it works for the other without an error, even though i don't have get method in pizza, it's in another class. Why would it work for one but not the other?

  4. #29
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Setters and getters

    Why would it work for one but not the other?
    Only answer without seeing the code is that it is coded correctly in one and incorrectly in the other.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #30
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Setters and getters

    Quote Originally Posted by Norm View Post
    Only answer without seeing the code is that it is coded correctly in one and incorrectly in the other.
    Well i showed the code in a previous post, i've went over and over and they're definitely the same

  6. #31
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Setters and getters

    they're definitely the same
    Why does the compiler find an error?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #32
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Setters and getters

    Quote Originally Posted by Norm View Post
    Why does the compiler find an error?
    Do you know why

    	boolean vegetarian = true;
    				if (bacon.getType().equals("bacon")||(prawn.getType().equals("prawn"))) {
     
    				 vegetarian = false;
    				  System.out.println("This pizza is not Vegetarian");
    			}
     
    				else {
     
    			     System.out.println("This pizza is Vegetarian");
    				}
    will work when bacon and prawn are selected, it will say this is not vegetarian, however if i say no to bacon and prawn and choose e.g. cheese it'll crash and won't appear with "this is a vegetarian pizza"

  8. #33
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Setters and getters

    it'll crash
    You should post the full text of the error message
    AND the code that causes the error.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #34
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Setters and getters

    Quote Originally Posted by Norm View Post
    You should post the full text of the error message
    AND the code that causes the error.
    Exception in thread "main" java.lang.NullPointerException
    at PizzaChoice.main(PizzaChoice.java:150)

    and if (bacon.getType().equals("bacon")||(prawn.getType() .equals("prawn"))) {

    sorry about that

    --- Update ---

    resolved the issue

    --- Update ---

    Quote Originally Posted by Norm View Post
    You should post the full text of the error message
    AND the code that causes the error.
    Do you know of anyway to say if the user selects an option then they can't select any others?
    for example
    do you want coke
    do you want fanta
    if they choose coke then fanta becomes unavailable, creating an illegal argument exception

Page 2 of 2 FirstFirst 12

Similar Threads

  1. help with setters and getters
    By takira in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 28th, 2013, 12:34 PM
  2. help with setters and getters
    By takira in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 26th, 2013, 04:10 PM
  3. Can anyone explain the Getters and setters in Java
    By sivasubramaniam in forum Java Theory & Questions
    Replies: 4
    Last Post: July 30th, 2013, 06:47 AM
  4. Encapsulation (getters and setters) Tips?
    By Robertgif in forum Java Theory & Questions
    Replies: 4
    Last Post: March 2nd, 2013, 06:36 AM
  5. Problems with input/output and getters/setters
    By robbiep551 in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: January 5th, 2012, 11:44 PM