Results 1 to 9 of 9
  1. #1
    caramelxxx is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Blue J programming mutator help

    I've tried to write this mutator so a the delievry time can be set but i think what i have written after the equals sign is wrong, please help

    public Time setDeliveredTime(int hour, int minute)
    {
    deliveredTime = (hour, minute);
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Blue J programming mutator help

    No, the problem is not inside the method, it's how you've declared the method. What should you declare that a mutator method should return? Or put another way, when you look at most examples of mutator methods, what do you see them declared as returning?

  3. #3
    caramelxxx is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Blue J programming mutator help

    im sorry but i dont understand what you are saying and i dont really understand programming in general :/

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Blue J programming mutator help

    When you declare a method, you declare it's return type. Above you've declared that your method will return a Time object:

    public Time setDeliveredTime(int hour, int minute)

    In your code examples, what do most mutator or setter methods declare returning. Look at your book or tutorial and please get back to me, and let's discuss this.

  5. #5
    caramelxxx is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Blue J programming mutator help

    public class Order
    {
    private int orderRef;
    private String customerName;
    private String description;
    private double totalCost;
    private Time callinTime;
    private Time deliveredTime;

    i thought Time was the return type?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Blue J programming mutator help

    Mutator methods aren't supposed to return anything. That's my point. What do you put in the return type for a method that's not supposed to return anything? Hint: it starts with a "v".

  7. #7
    caramelxxx is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Blue J programming mutator help

    oh void, so does this look correct now
    public void setDeliveredTime(Time hour, Time minute)
    {
    deliveredTime = hour;
    deliveredTime = minute;
    }

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Blue J programming mutator help

    There are exceptions, in that I have seen some mutator methods return the object that is being set, and I've seen others return a boolean to indicate that the mutation was successful, but in my experience these are the exceptions rather than the rule.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default Re: Blue J programming mutator help

    Quote Originally Posted by caramelxxx View Post
    oh void, so does this look correct now
    public void setDeliveredTime(Time hour, Time minute)
    {
    deliveredTime = hour;
    deliveredTime = minute;
    }
    'deleiveredTime' is a Time object, so you'll need to create one and assign that.
    Not knowing what constructors it has can't really say whether you would pass the hour and minute into the constructor or whether you would need to use setters.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Mutator Method help
    By Dex in forum New To Java
    Replies: 2
    Last Post: 07-29-2012, 07:59 AM
  2. Mutator methods
    By toterpunkt in forum New To Java
    Replies: 8
    Last Post: 02-24-2011, 08:17 AM
  3. Please help with mutator
    By ethemartian in forum New To Java
    Replies: 21
    Last Post: 02-06-2011, 01:57 AM
  4. Accessor/Mutator Question
    By noble in forum New To Java
    Replies: 4
    Last Post: 02-02-2010, 04:21 AM
  5. mutator method
    By dirtycash in forum New To Java
    Replies: 7
    Last Post: 11-22-2007, 10:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •